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¶
Converts a float32 value into a string.
Internally, the value is converted to float64 and formatted using the float64 implementation.
float64¶
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¶
Result:
Display Implementation¶
Both floating-point types implement the Display interface.
This allows floating-point values to be used with formatting and output functions.
Example¶
Output:
Floating-Point Utilities¶
IsNan¶
Returns true if the value is NaN (Not a Number).
Example¶
IsInfinite¶
Returns true if the value is positive or negative infinity.
Example¶
Formatting Behavior¶
Fixed-Point Notation¶
Most values are formatted using fixed-point notation.
Example:
Result:
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:
Possible result:
Example:
Possible result:
Notes¶
float32uses thefloat64formatter 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.