Libraries
Float Source Code
 previous   up   next 

Types
float
Double precision floating point numbers.

float

const type: float

Double precision floating point numbers.


Constant Summary
float
Infinity
Positive infinity.
float
NaN
Not-a-Number (NaN) value.

Operator Summary
float
(attr float) . value
Default value of float (0.0).
float
+ (in float: number)
Plus sign for float numbers.
float
- (in float: number)
Minus sign, negate a float number.
float
(in float: summand1) + (in float: summand2)
Add two float numbers.
float
(in float: minuend) - (in float: subtrahend)
Compute the subtraction of two float numbers.
float
(in float: factor1) * (in float: factor2)
Multiply two float numbers.
float
(in float: dividend) / (in float: divisor)
Compute the division of two float numbers.
float
(in float: dividend) rem (in float: divisor)
Compute the floating-point remainder of a division.
float
(in float: dividend) mod (in float: divisor)
Compute the floating-point modulo of a division.
float
(in float: base) ** (in integer: exponent)
Compute the exponentiation of a float base with an integer exponent.
float
(in float: base) ** (in float: exponent)
Compute the exponentiation of a float base with a float exponent.
float
(in float: number) << (in integer: exponent)
Multiply number by 2 raised to the power of exponent.
float
(in float: number) >> (in integer: exponent)
Divide number by 2 raised to the power of exponent.
void
(inout float: number) +:= (in float: delta)
Increment a float number by a delta.
void
(inout float: number) -:= (in float: delta)
Decrement a float number by a delta.
void
(inout float: number) *:= (in float: factor)
Multiply a float number by a factor and assign the result back to number.
void
(inout float: number) /:= (in float: divisor)
Divide a float number by a divisor and assign the result back to number.
boolean
(in float: number1) = (in float: number2)
Check if two float numbers are equal.
boolean
(in float: number1) <> (in float: number2)
Check if two float numbers are not equal.
boolean
(in float: number1) < (in float: number2)
Check if number1 is less than number2.
boolean
(in float: number1) > (in float: number2)
Check if number1 is greater than number2.
boolean
(in float: number1) <= (in float: number2)
Check if number1 is less than or equal to number2.
boolean
(in float: number1) >= (in float: number2)
Check if number1 is greater than or equal to number2.
float
(attr float) parse (in string: stri)
Convert a string to a float number.
string
(in float: number) digits (in integer: precision)
Convert a float to a string in decimal fixed point notation.
string
(in float: number) sci (in integer: precision)
Convert a float to a string in scientific notation.
string
(in string: sciNumber) exp (in integer: expDigits)
Set the number of exponent digits in a scientific float notation.
float
(attr float) conv (in integer: number)
Convert an integer to a float.

Function Summary
integer
compare (in float: number1, in float: number2)
Compare two float numbers.
integer
hashCode (in float: number)
Compute the hash value of a float number.
string
str (in float: number)
Convert a float number to a string.
string
string (in float: number)
Convert a float number to a string.
float
float (in string: stri)
Convert a string to a float number.
float
flt (in integer: number)
Convert an integer to a float.
float
float (in integer: number)
Convert an integer to a float.
float
abs (in float: number)
Compute the absolute value of a float number.
integer
round (in float: number)
Round a float to the nearest integer.
integer
trunc (in float: number)
Truncate towards zero.
boolean
isNaN (in float: number)
Determine if a number has a Not-a-Number (NaN) value.
boolean
isNegativeZero (in float: number)
Determine if a number is negative zero (-0.0).
boolean
isPositiveZero (in float: number)
Determine if a number is +0.0.
string
literal (in float: number)
Convert a float number to a string.
float
rand (in float: low, in float: high)
Compute pseudo-random number in the range [low, high).
floatElements
decompose (in float: number)
Decompose float into normalized fraction and integral exponent for 2.

Constant Detail

Infinity

const float: Infinity

Positive infinity. Infinity is the result of 1.0 / 0.0 .


NaN

const float: NaN

Not-a-Number (NaN) value. Represents an undefined or unrepresentable value. NaN is the result of 0.0 / 0.0 . Checking for NaN is done with the function isNaN.


Operator Detail

. value

const float: (attr float) . value

Default value of float (0.0).


+

const func float: + (in float: number)

Plus sign for float numbers.

Returns:
its operand unchanged.

-

const func float: - (in float: number)

Minus sign, negate a float number.

Returns:
the negated value of the number.

+

const func float: (in float: summand1) + (in float: summand2)

Add two float numbers.

Returns:
the sum of the two numbers.

-

const func float: (in float: minuend) - (in float: subtrahend)

Compute the subtraction of two float numbers.

Returns:
the difference of the two numbers.

*

const func float: (in float: factor1) * (in float: factor2)

Multiply two float numbers.

Returns:
the product of the two numbers.

/

const func float: (in float: dividend) / (in float: divisor)

Compute the division of two float numbers.

A / 0.0    returns  Infinity  for A > 0.0
A / 0.0    returns -Infinity  for A &lt; 0.0
0.0 / 0.0  returns NaN
Returns:
the quotient of the division.

rem

const func float: (in float: dividend) rem (in float: divisor)

Compute the floating-point remainder of a division. The remainder has the same sign as the dividend. The remainder is dividend - flt(trunc(dividend / divisor)) * divisor The remainder is computed without a conversion to integer.

 A        rem NaN       returns NaN
 NaN      rem B         returns NaN
 A        rem 0.0       returns NaN
 Infinity rem B         returns NaN
-Infinity rem B         returns NaN
 0.0      rem B         returns 0.0  for B &lt;> 0.0
 A        rem Infinity  returns A
Returns:
the floating-point remainder of the division.

mod

const func float: (in float: dividend) mod (in float: divisor)

Compute the floating-point modulo of a division. The modulo has the same sign as the divisor. The modulo is dividend - floor(dividend / divisor) * divisor

 A        mod  NaN       returns  NaN
 NaN      mod  B         returns  NaN
 A        mod  0.0       returns  NaN
 Infinity mod  B         returns  NaN
-Infinity mod  B         returns  NaN
 0.0      mod  B         returns  0.0         for B &lt;> 0.0
 A        mod  Infinity  returns  A           for A > 0
 A        mod  Infinity  returns  Infinity    for A < 0
 A        mod -Infinity  returns  A           for A < 0
 A        mod -Infinity  returns -Infinity    for A > 0
Returns:
the floating-point modulo of the division.

**

const func float: (in float: base) ** (in integer: exponent)

Compute the exponentiation of a float base with an integer exponent.

  A    ** 0  returns 1.0
  NaN  ** 0  returns 1.0
  NaN  ** B  returns NaN              for B <> 0
  0.0  ** B  returns 0.0              for B > 0
  0.0  ** 0  returns 1.0
  0.0  ** B  returns Infinity         for B < 0
(-0.0) ** B  returns -Infinity        for B < 0 and odd(B)
  A    ** B  returns 1.0 / A ** (-B)  for B < 0
Returns:
the result of the exponentiation.

**

const func float: (in float: base) ** (in float: exponent)

Compute the exponentiation of a float base with a float exponent.

  A    ** B    returns NaN        for A < 0.0 and B is not integer
  A    ** 0.0  returns 1.0
  NaN  ** 0.0  returns 1.0
  NaN  ** B    returns NaN        for B <> 0.0
  0.0  ** B    returns 0.0        for B > 0.0
  0.0  ** 0.0  returns 1.0
  0.0  ** B    returns Infinity   for B < 0.0
(-0.0) ** B    returns -Infinity  for B < 0.0 and odd(B)
  1.0  ** B    returns 1.0
  1.0  ** NaN  returns 1.0
  A    ** NaN  returns NaN        for A <> 1.0
Returns:
the result of the exponentiation.

<<

const func float: (in float: number) << (in integer: exponent)

Multiply number by 2 raised to the power of exponent. In other words: A << B is equivalent to A * 2.0 ** B If the result underflows zero is returned. If the result overflows Infinity or -Infinity is returned, depending on the sign of number. If the argument number is a NaN, Infinity or -Infinity the unchanged argument is returned.

Returns:
number * 2.0 ** exponent

>>

const func float: (in float: number) >> (in integer: exponent)

Divide number by 2 raised to the power of exponent. In other words: A >> B is equivalent to A / 2.0 ** B If the result underflows zero is returned. If the result overflows Infinity or -Infinity is returned, depending on the sign of number. If the argument number is a NaN, Infinity or -Infinity the unchanged argument is returned.

Returns:
number / 2.0 ** exponent

+:=

const proc: (inout float: number) +:= (in float: delta)

Increment a float number by a delta.


-:=

const proc: (inout float: number) -:= (in float: delta)

Decrement a float number by a delta.


*:=

const proc: (inout float: number) *:= (in float: factor)

Multiply a float number by a factor and assign the result back to number.


/:=

const proc: (inout float: number) /:= (in float: divisor)

Divide a float number by a divisor and assign the result back to number.


=

const func boolean: (in float: number1) = (in float: number2)

Check if two float numbers are equal. According to IEEE 754 a NaN is not equal to any float value. Therefore NaN = any_value and any_value = NaN always return FALSE. Even NaN = NaN returns FALSE.

Returns:
TRUE if both numbers are equal, FALSE otherwise.

<>

const func boolean: (in float: number1) <> (in float: number2)

Check if two float numbers are not equal. According to IEEE 754 a NaN is not equal to any float value. Therefore NaN <> any_value and any_value <> NaN always return TRUE. Even NaN <> NaN returns TRUE.

Returns:
FALSE if both numbers are equal, TRUE otherwise.

<

const func boolean: (in float: number1) < (in float: number2)

Check if number1 is less than number2. According to IEEE 754 a NaN is neither less than, equal to, nor greater than any value, including itself. If number1 or number2 is NaN, the result is FALSE;

Returns:
TRUE if number1 is less than number2, FALSE otherwise.

>

const func boolean: (in float: number1) > (in float: number2)

Check if number1 is greater than number2. According to IEEE 754 a NaN is neither less than, equal to, nor greater than any value, including itself. If number1 or number2 is NaN, the result is FALSE;

Returns:
TRUE if number1 is greater than number2, FALSE otherwise.

<=

const func boolean: (in float: number1) <= (in float: number2)

Check if number1 is less than or equal to number2. According to IEEE 754 a NaN is neither less than, equal to, nor greater than any value, including itself. If number1 or number2 is NaN, the result is FALSE;

Returns:
TRUE if number1 is less than or equal to number2, FALSE otherwise.

>=

const func boolean: (in float: number1) >= (in float: number2)

Check if number1 is greater than or equal to number2. According to IEEE 754 a NaN is neither less than, equal to, nor greater than any value, including itself. If number1 or number2 is NaN, the result is FALSE;

Returns:
TRUE if number1 is greater than or equal to number2, FALSE otherwise.

parse

const func float: (attr float) parse (in string: stri)

Convert a string to a float number.

float parse "1.2345"     returns  1.2345
float parse "1.2345e6"   returns  1234500.0
float parse "-1.0e-308"  returns -1.0e-308
float parse "1"          returns  1.0
float parse "2."         returns  2.0
float parse ".5"         returns  0.5
float parse "-.25"       returns  -0.25
float parse "Infinity"   returns  Infinity
float parse "-Infinity"  returns -Infinity
float parse "NaN"        returns  NaN
float parse "2.14PI"     raises RANGE_ERROR
Returns:
the float result of the conversion.
Raises:
RANGE_ERROR - If the string contains not a float literal.

digits

const func string: (in float: number) digits (in integer: precision)

Convert a float to a string in decimal fixed point notation. The number is rounded to the specified number of digits (precision). Halfway cases are rounded away from zero. Except for a precision of zero the representation has a decimal point and at least one digit before and after the decimal point. Negative numbers are preceded by a minus sign (e.g.: "-1.25"). If all digits in the result are 0 a possible negative sign is omitted.

0.012345 digits 4   returns "0.0123"
1.2468 digits 2     returns "1.25"
3.1415 digits 0     returns "3"
0.125 digits 2      returns "0.12"
0.375 digits 2      returns "0.38"
Infinity digits 5   returns "Infinity"
-Infinity digits 6  returns "-Infinity"
NaN digits 7        returns "NaN"
-0.004 digits 2     returns "0.00"
Parameters:
precision - Number of digits after the decimal point. If the precision is zero the decimal point is omitted.
Returns:
the string result of the conversion.
Raises:
RANGE_ERROR - If the precision is negative.
MEMORY_ERROR - Not enough memory to represent the result.

sci

const func string: (in float: number) sci (in integer: precision)

Convert a float to a string in scientific notation. Scientific notation uses a decimal significand and a decimal exponent. The significand has an optional sign and exactly one digit before the decimal point. The fractional part of the significand is rounded to the specified number of digits (precision). Halfway cases are rounded away from zero. The fractional part is followed by the letter e and an exponent, which is always signed. The value zero is never written with a negative sign.

0.012345 sci 4   returns "1.2345e-2"
1.2468 sci 2     returns "1.25e+0"
3.1415 sci 0     returns "3e+0"
0.125 sci 1      returns "1.2e-1"
0.375 sci 1      returns "3.8e-1"
Infinity sci 5   returns "Infinity"
-Infinity sci 6  returns "-Infinity"
NaN sci 7        returns "NaN"
-0.004 sci 2     returns "-4.00e-3"
-0.0 sci 2       returns "0.00e+0"
Parameters:
precision - Number of digits after the decimal point. If the precision is zero the decimal point is omitted.
Returns:
the string result of the conversion.
Raises:
RANGE_ERROR - If the precision is negative.
MEMORY_ERROR - Not enough memory to represent the result.

exp

const func string: (in string: sciNumber) exp (in integer: expDigits)

Set the number of exponent digits in a scientific float notation. If sciNumber contains a string in scientific float notation the exponent is changed to contain at least expDigits digits. If sciNumber contains not a string in scientific float notation it is returned unchanged. The exp operator is intended to be used together with the sci operator

0.012345 sci 4 exp 2   returns "1.2345e-02"
1.2468e15 sci 2 exp 1  returns "1.25e+15"
3.1415 sci 0 exp 3     returns "3e+000"
0.125 sci 1 exp 2      returns "1.2e-01"
0.375 sci 1 exp 2      returns "3.8e-01"
Infinity sci 5 exp 2   returns "Infinity"
-Infinity sci 6 exp 2  returns "-Infinity"
NaN sci 7 exp 2        returns "NaN"
-0.004 sci 2 exp 2     returns "-4.00e-03"
Returns:
the string result of the conversion.
Raises:
MEMORY_ERROR - Not enough memory to represent the result.

conv

const func float: (attr float) conv (in integer: number)

Convert an integer to a float.

Returns:
the float result of the conversion.

Function Detail

compare

const func integer: compare (in float: number1, in float: number2)

Compare two float numbers. Because compare is used to sort float values, a unique sort sequence of the values is needed. Therefore compare considers all NaN values as greater than Infinity. The NaN values are also considered to be equal to each other. Negative zero (-0.0) is considered by compare to be equal to positive zero (+0.0). This conforms to the behavior of all other float comparisons with zero.

Returns:
-1, 0 or 1 if the first argument is considered to be respectively less than, equal to, or greater than the second.

hashCode

const func integer: hashCode (in float: number)

Compute the hash value of a float number.

Returns:
the hash value.

str

const func string: str (in float: number)

Convert a float number to a string. The number is converted to a string with decimal representation. The result string has the style [-]ddd.ddd where there is at least one digit before and after the decimal point. The number of digits after the decimal point is determined automatically. Except for the case with only one zero digit after the decimal point the last digit is never zero. Negative zero (-0.0) and positive zero (+0.0) are both converted to "0.0".

str(16.125)    returns "16.125"
str(-0.0)      returns "0.0"
str(Infinity)  returns "Infinity"
str(-Infinity) returns "-Infinity"
str(NaN)       returns "NaN"
Returns:
the string result of the conversion.
Raises:
MEMORY_ERROR - Not enough memory to represent the result.

string

const func string: string (in float: number)

Convert a float number to a string. The number is converted to a string with decimal representation. The result string has the style [-]ddd.ddd where there is at least one digit before and after the decimal point. The number of digits after the decimal point is determined automatically. Except for the case with only one zero digit after the decimal point the last digit is never zero. Negative zero (-0.0) and positive zero (+0.0) are both converted to "0.0".

string(16.125)    returns "16.125"
string(-0.0)      returns "0.0"
string(Infinity)  returns "Infinity"
string(-Infinity) returns "-Infinity"
string(NaN)       returns "NaN"
Returns:
the string result of the conversion.
Raises:
MEMORY_ERROR - Not enough memory to represent the result.

float

const func float: float (in string: stri)

Convert a string to a float number.

float("1.2345")     returns  1.2345
float("1.2345e6")   returns  1234500.0
float("-1.0e-308")  returns -1.0e-308
float("1")          returns  1.0
float("2.")         returns  2.0
float(".5")         returns  0.5
float("-.25")       returns  -0.25
float("Infinity")   returns  Infinity
float("-Infinity")  returns -Infinity
float("NaN")        returns  NaN
float("3.14PI"      raises RANGE_ERROR
Returns:
the float result of the conversion.
Raises:
RANGE_ERROR - If the string contains not a float literal.

flt

const func float: flt (in integer: number)

Convert an integer to a float.

Returns:
the float result of the conversion.

float

const func float: float (in integer: number)

Convert an integer to a float.

Returns:
the float result of the conversion.

abs

const func float: abs (in float: number)

Compute the absolute value of a float number.

Returns:
the absolute value.

round

const func integer: round (in float: number)

Round a float to the nearest integer. Halfway cases are rounded away from zero.

round( 1.4999)  returns  1
round( 0.5)     returns  1
round( 0.4999)  returns  0
round(-0.4999)  returns  0
round(-0.5)     returns -1
round(-1.4999)  returns -1
round(1.0e+19)  raises  RANGE_ERROR
Returns:
the rounded value.
Raises:
RANGE_ERROR - If the number is NaN, -Infinity, Infinity, or does not fit into an integer.

trunc

const func integer: trunc (in float: number)

Truncate towards zero. The fractional part of a number is discarded.

trunc( 1.9999)  returns  1
trunc( 1.0)     returns  1
trunc( 0.9999)  returns  0
trunc(-0.9999)  returns  0
trunc(-1.0)     returns -1
trunc(-1.9999)  returns -1
trunc(1.0e+19)  raises  RANGE_ERROR
Returns:
the nearest integer not larger in absolute value than the argument.
Raises:
RANGE_ERROR - If the number is NaN, -Infinity, Infinity, or does not fit into an integer.

isNaN

const func boolean: isNaN (in float: number)

Determine if a number has a Not-a-Number (NaN) value. NaN represents an undefined or unrepresentable value.

Returns:
TRUE if the number has a Not-a-Number (NaN) value, FALSE otherwise.

isNegativeZero

const func boolean: isNegativeZero (in float: number)

Determine if a number is negative zero (-0.0). This function is the only possibility to determine if a number is -0.0. The comparison operators (=, <>, <, >, <=, >=) and the function compare treat 0.0 and -0.0 as equal. The operators digits and sci and the function str return the same string for -0.0 and +0.0.

Returns:
TRUE if the number is -0.0, FALSE otherwise.

isPositiveZero

const func boolean: isPositiveZero (in float: number)

Determine if a number is +0.0.

Returns:
TRUE if the number is +0.0, FALSE otherwise.

literal

const func string: literal (in float: number)

Convert a float number to a string. The number is converted to a string with decimal representation.

Returns:
the string result of the conversion.
Raises:
MEMORY_ERROR - Not enough memory to represent the result.

rand

const func float: rand (in float: low, in float: high)

Compute pseudo-random number in the range [low, high). The random values are uniform distributed.

Returns:
the computed pseudo-random number.
Raises:
RANGE_ERROR - The range is empty (low >= high holds).

decompose

const func floatElements: decompose (in float: number)

Decompose float into normalized fraction and integral exponent for 2. If the argument (number) is 0.0, -0.0, Infinity, -Infinity or NaN the fraction is set to the argument and the exponent is set to 0. For all other arguments the fraction is set to an absolute value between 0.5(included) and 1.0(excluded). For all values of number holds:

number = fraction * 2.0 ** exponent
Parameters:
number - Number to be decomposed into fraction and exponent.
Returns:
floatElements with fraction and exponent set.


 previous   up   next