Floats
This part of ikarus implements support for 32 bit IEEE 754 floats in Daedalus. The script was originally created to edit zFLOAT
and zREAL
variables, but can also be used to arithmetic operations on real float values (not to be confused with Daedalus floats).
Initialization
The best way to initialize all Ikarus functions is to call MEM_InitAll()
in the Init_Global()
initialization function.
Warning
If you want to use Ikarus in Gothic 1, it is best to define your own Init_Global()
function and call it from every world initialization function.
Implementation
Functions
Danger
Ikarus floats are saved as int but it doesn't mean that you can use arithmetic operators on them. All operations on floats must be done with functions listed below.
mkf
mkf
(make float) Converts the input integer x to a float value.
var int x
The input integer
Return value
The function returns the float representation of the input integer x.
truncf
truncf
(truncate float) Truncates the decimal part of the input float x.
var int x
The input float
Return value
The function returns the integer part of the input float x by discarding the decimal part.
roundf
roundf
(round float) Rounds the input float x to the nearest integer value.
var int x
The input float
Return value
The function returns the nearest integer value to the input float x. If the decimal part is exactly halfway between two integers, the function rounds to the nearest even integer.
addf
addf
(add floats) Adds two ikarus floats together.
var int x
The first floatvar int y
The second float
Return value
The function returns the sum of the input floats x
and y
. (x + y)
subf
subf
(subtract floats) Subtracts the second float from the first float.
var int x
The first floatvar int y
The second float
Return value
The function returns the difference between the first float x
and the second float y
. (x - y)
negf
negf
(negate float) Negates the input float.
var int x
The input float
Return value
The function returns the negation of the input float x
.
mulf
mulf
(multiply floats) Multiplies two ikarus floats.
var int x
The first floatvar int y
The second float
Return value
The function returns the product of multiplying the input floats x and y. (x * y)
divf
divf
(divide floats) Divides two ikarus floats.
var int x
The dividend floatvar int y
The divisor float
Return value
The function returns the quotient of dividing the input float x by y. (x / y)
invf
invf
(inverse float) Computes the inverse of the input float.
var int x
The input float
Return value
The function returns the inverse of the x
, calculated as 1/x
.
gf
gf
(greater) Checks if the first float is greater than the second float.
var int x
The first floatvar int y
The second float
Return value
The function returns TRUE
if x
is greater than y
, FALSE
is returned otherwise.
gef
gef
(greater or equal) Checks if the first float is greater than or equal to the second float.
var int x
The first floatvar int y
The second float
Return value
The function returns TRUE
if x
is greater than or equal to y
, FALSE
is returned otherwise.
lf
lf
(lower) Checks if the first float is less than the second float.
var int x
The first floatvar int y
The second float
Return value
The function returns TRUE
if x
is less than y
, FALSE
is returned otherwise.
lef
lef
(lower or equal) Checks if the first float is less than or equal to the second float.
var int x
The first floatvar int y
The second float
Return value
The function returns TRUE
if x
is less than or equal to y
, FALSE
is returned otherwise.
sqrf
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
sqrtf
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
sqrtf_approx
sqrtf_approx
Calculates the approximate square root of a float.
var int f
The input float
Return value
The function returns the approximate square root of the input float as an ikarus float.
absf
absf
(absolute value) Computes the absolute value of a float.
var int x
The input float
Return value
The function returns the absolute value of the input float x
, which is the value without the negative sign (if present).
fracf
fracf
(fraction) Computes the fraction of two integers p and q.
var int p
Numeratorvar int q
Denominator
Return value
The function returns the fraction of p
divided by q
as an ikarus float.
castFromIntf
castFromIntf
Converts an ikarus float to a Daedalus float.
var int f
Ikarus float
Return Value
The function returns the value f
as a Daedalus float.
castToIntf
castToIntf
Converts a Daedalus float to an ikarus float.
var float f
Daedalus float
Return Value
The function returns the value f
as an ikarus float.
toStringf
toStringf
Converts a float value to its string representation.
var int x
Input float value
Return value
The function returns a string representation of the input float value.
printf
printf
(print float) Prints the float on screen using Print()
.
var int x
The printed float