diff --git a/cli/test.yaml b/cli/test.yaml index 2ba8900d..7203655d 100644 --- a/cli/test.yaml +++ b/cli/test.yaml @@ -4075,25 +4075,40 @@ - name: isnormal function args: - - 'nan, infinite, -infinite, 9 | ., 1/. | isnormal' + - '0, 2.2250738585072011e-308, 2.2250738585072014e-308, 1, 1.7976931348623157e+308, nan, infinite, "", [], {} | isnormal' input: 'null' expected: | false false + true + true + true + false false false false false - true - true - name: normals function args: - - -c - - 'nan, infinite, -infinite, "", [], {}, 0, 9 | normals' + - '0, 2.2250738585072011e-308, 2.2250738585072014e-308, 1, 1.7976931348623157e+308, nan, infinite | ., -. | normals' input: 'null' expected: | - 9 + 2.2250738585072014e-308 + -2.2250738585072014e-308 + 1 + -1 + 1.7976931348623157e+308 + -1.7976931348623157e+308 + +- name: normals with nextafter function + args: + - '0, 2.2250738585072014e-308, 1.7976931348623157e+308, nan, infinite | nextafter(.; 0, infinite) | normals' + input: 'null' + expected: | + 2.225073858507202e-308 + 1.7976931348623155e+308 + 1.7976931348623157e+308 - name: stringify nan and infinite args: diff --git a/func.go b/func.go index a1b15767..2c2a28f9 100644 --- a/func.go +++ b/func.go @@ -1411,8 +1411,11 @@ func funcIsnan(v interface{}) interface{} { } func funcIsnormal(v interface{}) interface{} { - x, ok := toFloat(v) - return ok && !math.IsNaN(x) && !math.IsInf(x, 0) && x != 0.0 + if v, ok := toFloat(v); ok { + e := math.Float64bits(v) & 0x7ff0000000000000 >> 52 + return 0 < e && e < 0x7ff + } + return false } // An `allocator` creates new maps and slices, stores the allocated addresses.