Square root

From Kolmafia
Jump to navigation Jump to search

Function Syntax

float square_root(float number )

  • number is the number to find the root of

Returns the square root of the specified number. Note that it is possible supply an int type number as the parameter number, in which case it will be transparently converted to a float; the value returned will still be of float type (even if the int value would be equal, such as specifying 4 as number).

Code Sample

The following code will convert raw Damage Absorption to the actual percentage of damage absorbed in a floating-point number.

int my_DA = 550;
float actual_absorbed = square_root( min( max( 10 , my_DA ) , 1000 ).to_float() / 1000 ) - 0.1;

to_float() is used to prevent fractions from being sliced. You can use raw_damage_absorption() and damage_absorption_percent() to determine your current damage absorption.