From a0c4bb571fa26f49c997c6e17bbbeab2fee46640 Mon Sep 17 00:00:00 2001 From: Andy Ferris Date: Fri, 3 May 2024 19:19:19 +1000 Subject: [PATCH] Add NaN and Infinity floating-point values to Num --- crates/compiler/builtins/roc/Num.roc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/compiler/builtins/roc/Num.roc b/crates/compiler/builtins/roc/Num.roc index f1bf30bc84..a2d512fbb8 100644 --- a/crates/compiler/builtins/roc/Num.roc +++ b/crates/compiler/builtins/roc/Num.roc @@ -155,6 +155,10 @@ module [ f64ToParts, f32FromParts, f64FromParts, + nanF32, + nanF64, + infinityF32, + infinityF64, ] import Bool exposing [Bool] @@ -1433,3 +1437,19 @@ f32FromParts : { sign : Bool, exponent : U8, fraction : U32 } -> F32 ## The fraction should not be bigger than 0x000F_FFFF_FFFF_FFFF, any bigger value will be truncated. ## The exponent should not be bigger than 0x07FF, any bigger value will be truncated. f64FromParts : { sign : Bool, exponent : U16, fraction : U64 } -> F64 + +## The value for not-a-number for a [F32] according to the IEEE 754 standard. +nanF32 : F32 +nanF32 = 0.0f32 / 0.0 + +## The value for not-a-number for a [F64] according to the IEEE 754 standard. +nanF64 : F64 +nanF64 = 0.0f64 / 0.0 + +## The value for infinity for a [F32] according to the IEEE 754 standard. +infinityF32 : F32 +infinityF32 = 1.0f32 / 0.0 + +## The value for infinity for a [F64] according to the IEEE 754 standard. +infinityF64 : F64 +infinityF64 = 1.0f64 / 0.0