| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | // |
| 3 | 3 | // - frexp(+-0) = +-0, 0 |
| 4 | 4 | // - frexp(+-inf) = +-inf, 0 |
| 5 | | // - frexp(nan) = nan, 0 |
| 5 | // - frexp(nan) = nan, undefined |
| 6 | 6 | |
| 7 | 7 | const math = @import("index.zig"); |
| 8 | 8 | const assert = @import("../debug.zig").assert; |
| ... | ... | @@ -46,9 +46,15 @@ fn frexp32(x: f32) -> frexp32_result { |
| 46 | 46 | } |
| 47 | 47 | return result; |
| 48 | 48 | } else if (e == 0xFF) { |
| 49 | | // frexp(nan) = (nan, 0) |
| 49 | // frexp(nan) = (nan, undefined) |
| 50 | 50 | result.significand = x; |
| 51 | | result.exponent = 0; |
| 51 | result.exponent = undefined; |
| 52 | |
| 53 | // frexp(+-inf) = (+-inf, 0) |
| 54 | if (math.isInf(x)) { |
| 55 | result.exponent = 0; |
| 56 | } |
| 57 | |
| 52 | 58 | return result; |
| 53 | 59 | } |
| 54 | 60 | |
| ... | ... | @@ -77,8 +83,15 @@ fn frexp64(x: f64) -> frexp64_result { |
| 77 | 83 | } |
| 78 | 84 | return result; |
| 79 | 85 | } else if (e == 0x7FF) { |
| 86 | // frexp(nan) = (nan, undefined) |
| 80 | 87 | result.significand = x; |
| 81 | | result.exponent = 0; |
| 88 | result.exponent = undefined; |
| 89 | |
| 90 | // frexp(+-inf) = (+-inf, 0) |
| 91 | if (math.isInf(x)) { |
| 92 | result.exponent = 0; |
| 93 | } |
| 94 | |
| 82 | 95 | return result; |
| 83 | 96 | } |
| 84 | 97 | |
| ... | ... | @@ -137,7 +150,7 @@ test "math.frexp32.special" { |
| 137 | 150 | assert(math.isNegativeInf(r.significand) and r.exponent == 0); |
| 138 | 151 | |
| 139 | 152 | r = frexp32(math.nan(f32)); |
| 140 | | assert(math.isNan(r.significand) and r.exponent == 0); |
| 153 | assert(math.isNan(r.significand)); |
| 141 | 154 | } |
| 142 | 155 | |
| 143 | 156 | test "math.frexp64.special" { |
| ... | ... | @@ -156,5 +169,5 @@ test "math.frexp64.special" { |
| 156 | 169 | assert(math.isNegativeInf(r.significand) and r.exponent == 0); |
| 157 | 170 | |
| 158 | 171 | r = frexp64(math.nan(f64)); |
| 159 | | assert(math.isNan(r.significand) and r.exponent == 0); |
| 172 | assert(math.isNan(r.significand)); |
| 160 | 173 | } |