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/trunc.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/trunc.zig')
| -rw-r--r-- | std/math/trunc.zig | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/std/math/trunc.zig b/std/math/trunc.zig index 7311da2f15..33b37967a5 100644 --- a/std/math/trunc.zig +++ b/std/math/trunc.zig @@ -1,3 +1,9 @@ +// Special Cases: +// +// - trunc(+-0) = +-0 +// - trunc(+-inf) = +-inf +// - trunc(nan) = nan + const math = @import("index.zig"); const assert = @import("../debug.zig").assert; @@ -70,3 +76,19 @@ test "math.trunc64" { assert(trunc64(-1.3) == -1.0); assert(trunc64(0.2) == 0.0); } + +test "math.trunc32.special" { + assert(trunc32(0.0) == 0.0); // 0x3F800000 + assert(trunc32(-0.0) == -0.0); + assert(math.isPositiveInf(trunc32(math.inf(f32)))); + assert(math.isNegativeInf(trunc32(-math.inf(f32)))); + assert(math.isNan(trunc32(math.nan(f32)))); +} + +test "math.trunc64.special" { + assert(trunc64(0.0) == 0.0); + assert(trunc64(-0.0) == -0.0); + assert(math.isPositiveInf(trunc64(math.inf(f64)))); + assert(math.isNegativeInf(trunc64(-math.inf(f64)))); + assert(math.isNan(trunc64(math.nan(f64)))); +} |
