Skip to content

Floating-Point Types

Floating-point types represent real numbers with fractional components.

Module: Std

Summary

ToString(value: float32) -> String
ToString(value: float64) -> String

float32.ToString() -> String
float64.ToString() -> String

IsNan(value: float64) -> bool
IsInfinite(value: float64) -> bool

Description

Rux provides two floating-point types:

Type Size
float32 32 bits
float64 64 bits

Both types implement the Display interface and can be converted to strings using ToString().

float32 conversions are internally performed through float64.


String Conversion

ToString

float32

ToString(value: float32) -> String

Converts a float32 value into a string.

Internally, the value is converted to float64 and formatted using the float64 implementation.


float64

ToString(value: float64) -> String

Converts a float64 value into a string representation.

Special floating-point values are handled automatically:

Value Result
NaN "NaN"
Positive Infinity "Inf"
Negative Infinity "-Inf"

Example

let text = ToString(3.141592);

Result:

3.141592

Display Implementation

Both floating-point types implement the Display interface.

extend float32 : Display
extend float64 : Display

This allows floating-point values to be used with formatting and output functions.

Example

PrintLine(3.14);

Output:

3.140000

Floating-Point Utilities

IsNan

IsNan(value: float64) -> bool

Returns true if the value is NaN (Not a Number).

Example

if IsNan(value) {

}

IsInfinite

IsInfinite(value: float64) -> bool

Returns true if the value is positive or negative infinity.

Example

if IsInfinite(value) {

}

Formatting Behavior

Fixed-Point Notation

Most values are formatted using fixed-point notation.

Example:

ToString(123.456);

Result:

123.456000

The current implementation outputs six digits after the decimal point.


Scientific Notation

Very large and very small values are automatically formatted using scientific notation.

Example:

ToString(1234567890123456.0);

Possible result:

1.2345678901234567e+15

Example:

ToString(0.00001);

Possible result:

1.0000000000000000e-05

Notes

  • float32 uses the float64 formatter internally.
  • A new string is allocated for every conversion.
  • Fixed-point formatting currently outputs six fractional digits.
  • Scientific notation is used for extremely large or small values.
  • Special values (NaN, Inf, -Inf) are supported.