Skip to content

Commit afc4c6c

Browse files
committed
fix isnormal and normals functions against subnormal numbers
1 parent c1a3ebd commit afc4c6c

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

cli/test.yaml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4075,25 +4075,40 @@
40754075
40764076
- name: isnormal function
40774077
args:
4078-
- 'nan, infinite, -infinite, 9 | ., 1/. | isnormal'
4078+
- '0, 2.2250738585072011e-308, 2.2250738585072014e-308, 1, 1.7976931348623157e+308, nan, infinite, "", [], {} | isnormal'
40794079
input: 'null'
40804080
expected: |
40814081
false
40824082
false
4083+
true
4084+
true
4085+
true
4086+
false
40834087
false
40844088
false
40854089
false
40864090
false
4087-
true
4088-
true
40894091
40904092
- name: normals function
40914093
args:
4092-
- -c
4093-
- 'nan, infinite, -infinite, "", [], {}, 0, 9 | normals'
4094+
- '0, 2.2250738585072011e-308, 2.2250738585072014e-308, 1, 1.7976931348623157e+308, nan, infinite | ., -. | normals'
40944095
input: 'null'
40954096
expected: |
4096-
9
4097+
2.2250738585072014e-308
4098+
-2.2250738585072014e-308
4099+
1
4100+
-1
4101+
1.7976931348623157e+308
4102+
-1.7976931348623157e+308
4103+
4104+
- name: normals with nextafter function
4105+
args:
4106+
- '0, 2.2250738585072014e-308, 1.7976931348623157e+308, nan, infinite | nextafter(.; 0, infinite) | normals'
4107+
input: 'null'
4108+
expected: |
4109+
2.225073858507202e-308
4110+
1.7976931348623155e+308
4111+
1.7976931348623157e+308
40974112
40984113
- name: stringify nan and infinite
40994114
args:

func.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,8 +1411,11 @@ func funcIsnan(v interface{}) interface{} {
14111411
}
14121412

14131413
func funcIsnormal(v interface{}) interface{} {
1414-
x, ok := toFloat(v)
1415-
return ok && !math.IsNaN(x) && !math.IsInf(x, 0) && x != 0.0
1414+
if v, ok := toFloat(v); ok {
1415+
e := math.Float64bits(v) & 0x7ff0000000000000 >> 52
1416+
return 0 < e && e < 0x7ff
1417+
}
1418+
return false
14161419
}
14171420

14181421
// An `allocator` creates new maps and slices, stores the allocated addresses.

0 commit comments

Comments
 (0)