| ... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
| 2 | // | 2 | // |
| 3 | // - frexp(+-0) = +-0, 0 | 3 | // - frexp(+-0) = +-0, 0 |
| 4 | // - frexp(+-inf) = +-inf, 0 | 4 | // - frexp(+-inf) = +-inf, 0 |
| 5 | // - frexp(nan) = nan, 0 | 5 | // - frexp(nan) = nan, undefined |
| 6 | | 6 | |
| 7 | const math = @import("index.zig"); | 7 | const math = @import("index.zig"); |
| 8 | const assert = @import("../debug.zig").assert; | 8 | const assert = @import("../debug.zig").assert; |
| ... | @@ -46,9 +46,15 @@ fn frexp32(x: f32) -> frexp32_result { | ... | @@ -46,9 +46,15 @@ fn frexp32(x: f32) -> frexp32_result { |
| 46 | } | 46 | } |
| 47 | return result; | 47 | return result; |
| 48 | } else if (e == 0xFF) { | 48 | } else if (e == 0xFF) { |
| 49 | // frexp(nan) = (nan, 0) | 49 | // frexp(nan) = (nan, undefined) |
| 50 | result.significand = x; | 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 | return result; | 58 | return result; |
| 53 | } | 59 | } |
| 54 | | 60 | |
| ... | @@ -77,8 +83,15 @@ fn frexp64(x: f64) -> frexp64_result { | ... | @@ -77,8 +83,15 @@ fn frexp64(x: f64) -> frexp64_result { |
| 77 | } | 83 | } |
| 78 | return result; | 84 | return result; |
| 79 | } else if (e == 0x7FF) { | 85 | } else if (e == 0x7FF) { |
| | 86 | // frexp(nan) = (nan, undefined) |
| 80 | result.significand = x; | 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 | return result; | 95 | return result; |
| 83 | } | 96 | } |
| 84 | | 97 | |
| ... | @@ -137,7 +150,7 @@ test "math.frexp32.special" { | ... | @@ -137,7 +150,7 @@ test "math.frexp32.special" { |
| 137 | assert(math.isNegativeInf(r.significand) and r.exponent == 0); | 150 | assert(math.isNegativeInf(r.significand) and r.exponent == 0); |
| 138 | | 151 | |
| 139 | r = frexp32(math.nan(f32)); | 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 | test "math.frexp64.special" { | 156 | test "math.frexp64.special" { |
| ... | @@ -156,5 +169,5 @@ test "math.frexp64.special" { | ... | @@ -156,5 +169,5 @@ test "math.frexp64.special" { |
| 156 | assert(math.isNegativeInf(r.significand) and r.exponent == 0); | 169 | assert(math.isNegativeInf(r.significand) and r.exponent == 0); |
| 157 | | 170 | |
| 158 | r = frexp64(math.nan(f64)); | 171 | r = frexp64(math.nan(f64)); |
| 159 | assert(math.isNan(r.significand) and r.exponent == 0); | 172 | assert(math.isNan(r.significand)); |
| 160 | } | 173 | } |