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/ceil.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/ceil.zig')
| -rw-r--r-- | std/math/ceil.zig | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/std/math/ceil.zig b/std/math/ceil.zig index f5bc22500a..933182e771 100644 --- a/std/math/ceil.zig +++ b/std/math/ceil.zig @@ -1,3 +1,9 @@ +// Special Cases: +// +// - ceil(+-0) = +-0 +// - ceil(+-inf) = +-inf +// - ceil(nan) = nan + const builtin = @import("builtin"); const math = @import("index.zig"); const assert = @import("../debug.zig").assert; @@ -19,6 +25,11 @@ fn ceil32(x: f32) -> f32 { var e = i32((u >> 23) & 0xFF) - 0x7F; var m: u32 = undefined; + // TODO: Shouldn't need this explicit check. + if (x == 0.0) { + return x; + } + if (e >= 23) { return x; } @@ -90,3 +101,19 @@ test "math.ceil64" { assert(ceil64(-1.3) == -1.0); assert(ceil64(0.2) == 1.0); } + +test "math.ceil32.special" { + assert(ceil32(0.0) == 0.0); + assert(ceil32(-0.0) == -0.0); + assert(math.isPositiveInf(ceil32(math.inf(f32)))); + assert(math.isNegativeInf(ceil32(-math.inf(f32)))); + assert(math.isNan(ceil32(math.nan(f32)))); +} + +test "math.ceil64.special" { + assert(ceil64(0.0) == 0.0); + assert(ceil64(-0.0) == -0.0); + assert(math.isPositiveInf(ceil64(math.inf(f64)))); + assert(math.isNegativeInf(ceil64(-math.inf(f64)))); + assert(math.isNan(ceil64(math.nan(f64)))); +} |
