Seed7 - The extensible programming language
Seed7 FAQ Manual Screenshots Examples Libraries Algorithms Download Links
Libraries AES ARC4 Array ASN.1 Bigfile Bigint Bigrat Bin32 Bin64 Bitdata Bitmapfont Bitset Bitsetof Boolean Browser Bstring Bytedata Cards Category CC config Cgi Cgi dialog Char Charsets Cipher Clib_file Color CLI Commands Complex Console Crc32 Deflate DES Dialog Dir Draw Duration Echo Editline Enable_input Enable_io Enable_output Encoding Environment External_file File File system Float Font Forloop Ftp Getf Gethttp Gethttps Graph Graph_file Gzip Hash Hashsetof Hmac Html_ent Httpserv Idxarray Image Inflate Inflate file Inifile Integer Keybd Line Listener LZW Make Math Msgdigest Null_file Osfiles Picture utility Pixmap_file Pixmapfont PKCS #1 Poll Process Progs Propertyfile Rational Reference Ref_list Scanfile Scanstri Set Shell Smtp Sockbase Socket SQL base Stdio Strifile String Stritext Subrange Tar Text Time TLS/SSL Triple DES Unicode Utf16 Utf8 Vectorfont 3D Vector Window Wrinum X.509 Xmldom Xml_ent Zip
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
+ (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: 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.
float
flt (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].
float
min (in float: value1, in float: value2)
Determine the minimum of two float numbers.
float
max (in float: value1, in float: value2)
Determine the maximum of two float numbers.
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

+

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.

**

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 exponentation.

**

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 exponentation.

<<

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. When 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. When 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. When 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. When 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. When 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. When 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.

Returns:
the float result of the conversion.
Raises:
RANGE_ERROR - When 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 preceeded by a minus sign (e.g.: "-1.25"). When 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. When the precision is zero the decimal point is omitted.
Returns:
the string result of the conversion.
Raises:
RANGE_ERROR - When 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. When the precision is zero the decimal point is omitted.
Returns:
the string result of the conversion.
Raises:
RANGE_ERROR - When 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. When sciNumber contains a string in scientific float notation the exponent is changed to contain at least expDigits digits. When 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 when there is 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.

flt

const func float: flt (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(0.5)    returns  1
round(0.499)  returns  0
round(-0.48)  returns  0
round(-0.5)   returns -1
Returns:
the rounded value.
Raises:
RANGE_ERROR - When 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.

Returns:
the nearest integer not larger in absolute value than the argument.
Raises:
RANGE_ERROR - When 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).

min

const func float: min (in float: value1, in float: value2)

Determine the minimum of two float numbers.

Returns:
the minimum of the two numbers.

max

const func float: max (in float: value1, in float: value2)

Determine the maximum of two float numbers.

Returns:
the maximum of the two numbers.

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