diff options
| author | Marc Tiehuis <marctiehuis@gmail.com> | 2017-06-20 23:01:04 +1200 |
|---|---|---|
| committer | Marc Tiehuis <marctiehuis@gmail.com> | 2017-06-20 23:10:22 +1200 |
| commit | 5bbec42a4edb3f6758a9d67fcf763c660ac3f204 (patch) | |
| tree | 3dc324d083f142935df53c5900edfc04c0f956f8 /std/math/asin.zig | |
| parent | c9fc8bd802f5ed52c4cc78b93f18fc5dc9b6bb7f (diff) | |
| download | zig-5bbec42a4edb3f6758a9d67fcf763c660ac3f204.tar.gz zig-5bbec42a4edb3f6758a9d67fcf763c660ac3f204.zip | |
Add math special case tests and general fixes
- Should cover special case inputs for most functions
- Fixed a number of runtime panicking behaviour reliant on shift
overflow/division by zero etc.
Diffstat (limited to 'std/math/asin.zig')
| -rw-r--r-- | std/math/asin.zig | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/std/math/asin.zig b/std/math/asin.zig index be8d006cac..3f705a9cf7 100644 --- a/std/math/asin.zig +++ b/std/math/asin.zig @@ -1,3 +1,8 @@ +// Special Cases: +// +// - asin(+-0) = +-0 +// - asin(x) = nan if x < -1 or x > 1 + const math = @import("index.zig"); const assert = @import("../debug.zig").assert; @@ -36,7 +41,7 @@ fn asin32(x: f32) -> f32 { if (ix == 0x3F800000) { return x * pio2 + 0x1.0p-120; // asin(+-1) = +-pi/2 with inexact } else { - return 0 / (x - x); // asin(|x| > 1) is nan + return math.nan(f32); // asin(|x| > 1) is nan } } @@ -95,7 +100,7 @@ fn asin64(x: f64) -> f64 { if ((ix - 0x3FF00000) | lx == 0) { return x * pio2_hi + 0x1.0p-120; } else { - return 0/ (x - x); + return math.nan(f64); } } @@ -158,3 +163,17 @@ test "math.asin64" { assert(math.approxEq(f64, asin64(0.5), 0.523599, epsilon)); assert(math.approxEq(f64, asin64(0.8923), 1.102415, epsilon)); } + +test "math.asin32.special" { + assert(asin32(0.0) == 0.0); + assert(asin32(-0.0) == -0.0); + assert(math.isNan(asin32(-2))); + assert(math.isNan(asin32(1.5))); +} + +test "math.asin64.special" { + assert(asin64(0.0) == 0.0); + assert(asin64(-0.0) == -0.0); + assert(math.isNan(asin64(-2))); + assert(math.isNan(asin64(1.5))); +} |
