authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-09-13 20:33:05+12:00
committergravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-09-13 20:33:05+12:00
loge70c543bc4c097d7c3287feb0f233a13d4dc3829
treeeed3f73ee9e52cbeb801fa85b407b5342d0e26f6
parentafe6316d32d0e61687c58d152207252bdc33dad7

math/complex: cexp test correction and ldexp usage fix


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) {
4444 else if (ix < 0x4340b1e7) {
4545 const v = Complex(f32).new(math.fabs(x), y);
4646 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));
4848 }
4949 // x >= 192.7: result always overflows
5050 else {
......@@ -112,7 +112,7 @@ fn cosh64(z: *const Complex(f64)) Complex(f64) {
112112 else if (ix < 0x4096bbaa) {
113113 const v = Complex(f64).new(math.fabs(x), y);
114114 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));
116116 }
117117 // x >= 1455: result always overflows
118118 else {
std/math/complex/exp.zig+4-5
......@@ -69,7 +69,7 @@ fn exp64(z: Complex(f64)) Complex(f64) {
6969 const y = z.im;
7070
7171 const fy = @bitCast(u64, y);
72 const hy = u32(fy >> 32) & 0x7fffffff;
72 const hy = @intCast(u32, (fy >> 32) & 0x7fffffff);
7373 const ly = @truncate(u32, fy);
7474
7575 // cexp(x + i0) = exp(x) + i0
......@@ -78,7 +78,7 @@ fn exp64(z: Complex(f64)) Complex(f64) {
7878 }
7979
8080 const fx = @bitCast(u64, x);
81 const hx = u32(fx >> 32);
81 const hx = @intCast(u32, fx >> 32);
8282 const lx = @truncate(u32, fx);
8383
8484 // cexp(0 + iy) = cos(y) + isin(y)
......@@ -101,8 +101,7 @@ fn exp64(z: Complex(f64)) Complex(f64) {
101101
102102 // 709.7 <= x <= 1454.3 so must scale
103103 if (hx >= exp_overflow and hx <= cexp_overflow) {
104 const r = ldexp_cexp(z, 0);
105 return r.*;
104 return ldexp_cexp(z, 0);
106105 } // - x < exp_overflow => exp(x) won't overflow (common)
107106 // - x > cexp_overflow, so exp(x) * s overflows for s > 0
108107 // - x = +-inf
......@@ -124,7 +123,7 @@ test "complex.cexp32" {
124123}
125124
126125test "complex.cexp64" {
127 const a = Complex(f32).new(5, 3);
126 const a = Complex(f64).new(5, 3);
128127 const c = exp(a);
129128
130129 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) {
4444 else if (ix < 0x4340b1e7) {
4545 const v = Complex(f32).new(math.fabs(x), y);
4646 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);
4848 }
4949 // x >= 192.7: result always overflows
5050 else {
......@@ -111,7 +111,7 @@ fn sinh64(z: Complex(f64)) Complex(f64) {
111111 else if (ix < 0x4096bbaa) {
112112 const v = Complex(f64).new(math.fabs(x), y);
113113 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);
115115 }
116116 // x >= 1455: result always overflows
117117 else {