| author | |
| committer | |
| log | e70c543bc4c097d7c3287feb0f233a13d4dc3829 |
| tree | eed3f73ee9e52cbeb801fa85b407b5342d0e26f6 |
| parent | afe6316d32d0e61687c58d152207252bdc33dad7 |
3 files changed, 8 insertions(+), 9 deletions(-)
std/math/complex/cosh.zig+2-2| ... | @@ -44,7 +44,7 @@ fn cosh32(z: *const Complex(f32)) Complex(f32) { | ... | @@ -44,7 +44,7 @@ fn cosh32(z: *const Complex(f32)) Complex(f32) { |
| 44 | else if (ix < 0x4340b1e7) { | 44 | else if (ix < 0x4340b1e7) { |
| 45 | const v = Complex(f32).new(math.fabs(x), y); | 45 | const v = Complex(f32).new(math.fabs(x), y); |
| 46 | const r = ldexp_cexp(v, -1); | 46 | const r = ldexp_cexp(v, -1); |
| 47 | return Complex(f32).new(x, y * math.copysign(f32, 1, x)); | 47 | return Complex(f32).new(r.re, r.im * math.copysign(f32, 1, x)); |
| 48 | } | 48 | } |
| 49 | // x >= 192.7: result always overflows | 49 | // x >= 192.7: result always overflows |
| 50 | else { | 50 | else { |
| ... | @@ -112,7 +112,7 @@ fn cosh64(z: *const Complex(f64)) Complex(f64) { | ... | @@ -112,7 +112,7 @@ fn cosh64(z: *const Complex(f64)) Complex(f64) { |
| 112 | else if (ix < 0x4096bbaa) { | 112 | else if (ix < 0x4096bbaa) { |
| 113 | const v = Complex(f64).new(math.fabs(x), y); | 113 | const v = Complex(f64).new(math.fabs(x), y); |
| 114 | const r = ldexp_cexp(v, -1); | 114 | const r = ldexp_cexp(v, -1); |
| 115 | return Complex(f64).new(x, y * math.copysign(f64, 1, x)); | 115 | return Complex(f64).new(r.re, r.im * math.copysign(f64, 1, x)); |
| 116 | } | 116 | } |
| 117 | // x >= 1455: result always overflows | 117 | // x >= 1455: result always overflows |
| 118 | else { | 118 | else { |
std/math/complex/exp.zig+4-5| ... | @@ -69,7 +69,7 @@ fn exp64(z: Complex(f64)) Complex(f64) { | ... | @@ -69,7 +69,7 @@ fn exp64(z: Complex(f64)) Complex(f64) { |
| 69 | const y = z.im; | 69 | const y = z.im; |
| 70 | 70 | ||
| 71 | const fy = @bitCast(u64, y); | 71 | const fy = @bitCast(u64, y); |
| 72 | const hy = u32(fy >> 32) & 0x7fffffff; | 72 | const hy = @intCast(u32, (fy >> 32) & 0x7fffffff); |
| 73 | const ly = @truncate(u32, fy); | 73 | const ly = @truncate(u32, fy); |
| 74 | 74 | ||
| 75 | // cexp(x + i0) = exp(x) + i0 | 75 | // cexp(x + i0) = exp(x) + i0 |
| ... | @@ -78,7 +78,7 @@ fn exp64(z: Complex(f64)) Complex(f64) { | ... | @@ -78,7 +78,7 @@ fn exp64(z: Complex(f64)) Complex(f64) { |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | const fx = @bitCast(u64, x); | 80 | const fx = @bitCast(u64, x); |
| 81 | const hx = u32(fx >> 32); | 81 | const hx = @intCast(u32, fx >> 32); |
| 82 | const lx = @truncate(u32, fx); | 82 | const lx = @truncate(u32, fx); |
| 83 | 83 | ||
| 84 | // cexp(0 + iy) = cos(y) + isin(y) | 84 | // cexp(0 + iy) = cos(y) + isin(y) |
| ... | @@ -101,8 +101,7 @@ fn exp64(z: Complex(f64)) Complex(f64) { | ... | @@ -101,8 +101,7 @@ fn exp64(z: Complex(f64)) Complex(f64) { |
| 101 | 101 | ||
| 102 | // 709.7 <= x <= 1454.3 so must scale | 102 | // 709.7 <= x <= 1454.3 so must scale |
| 103 | if (hx >= exp_overflow and hx <= cexp_overflow) { | 103 | if (hx >= exp_overflow and hx <= cexp_overflow) { |
| 104 | const r = ldexp_cexp(z, 0); | 104 | return ldexp_cexp(z, 0); |
| 105 | return r.*; | ||
| 106 | } // - x < exp_overflow => exp(x) won't overflow (common) | 105 | } // - x < exp_overflow => exp(x) won't overflow (common) |
| 107 | // - x > cexp_overflow, so exp(x) * s overflows for s > 0 | 106 | // - x > cexp_overflow, so exp(x) * s overflows for s > 0 |
| 108 | // - x = +-inf | 107 | // - x = +-inf |
| ... | @@ -124,7 +123,7 @@ test "complex.cexp32" { | ... | @@ -124,7 +123,7 @@ test "complex.cexp32" { |
| 124 | } | 123 | } |
| 125 | 124 | ||
| 126 | test "complex.cexp64" { | 125 | test "complex.cexp64" { |
| 127 | const a = Complex(f32).new(5, 3); | 126 | const a = Complex(f64).new(5, 3); |
| 128 | const c = exp(a); | 127 | const c = exp(a); |
| 129 | 128 | ||
| 130 | debug.assert(math.approxEq(f64, c.re, -146.927917, epsilon)); | 129 | debug.assert(math.approxEq(f64, c.re, -146.927917, epsilon)); |
std/math/complex/sinh.zig+2-2| ... | @@ -44,7 +44,7 @@ fn sinh32(z: Complex(f32)) Complex(f32) { | ... | @@ -44,7 +44,7 @@ fn sinh32(z: Complex(f32)) Complex(f32) { |
| 44 | else if (ix < 0x4340b1e7) { | 44 | else if (ix < 0x4340b1e7) { |
| 45 | const v = Complex(f32).new(math.fabs(x), y); | 45 | const v = Complex(f32).new(math.fabs(x), y); |
| 46 | const r = ldexp_cexp(v, -1); | 46 | const r = ldexp_cexp(v, -1); |
| 47 | return Complex(f32).new(x * math.copysign(f32, 1, x), y); | 47 | return Complex(f32).new(r.re * math.copysign(f32, 1, x), r.im); |
| 48 | } | 48 | } |
| 49 | // x >= 192.7: result always overflows | 49 | // x >= 192.7: result always overflows |
| 50 | else { | 50 | else { |
| ... | @@ -111,7 +111,7 @@ fn sinh64(z: Complex(f64)) Complex(f64) { | ... | @@ -111,7 +111,7 @@ fn sinh64(z: Complex(f64)) Complex(f64) { |
| 111 | else if (ix < 0x4096bbaa) { | 111 | else if (ix < 0x4096bbaa) { |
| 112 | const v = Complex(f64).new(math.fabs(x), y); | 112 | const v = Complex(f64).new(math.fabs(x), y); |
| 113 | const r = ldexp_cexp(v, -1); | 113 | const r = ldexp_cexp(v, -1); |
| 114 | return Complex(f64).new(x * math.copysign(f64, 1, x), y); | 114 | return Complex(f64).new(r.re * math.copysign(f64, 1, x), r.im); |
| 115 | } | 115 | } |
| 116 | // x >= 1455: result always overflows | 116 | // x >= 1455: result always overflows |
| 117 | else { | 117 | else { |