| author | |
| committer | |
| log | 634d11ab28839ebc3caae2bf18cbc028a7a1c3e9 |
| tree | 7bc045c19029230e9a0b4a3545cf8ce76ba823af |
| parent | 5f5364ad73dc6c31e1e189596f407970f852701a |
And add std.math.f128_* constants.
The routines are:
__fixdfdi, __fixdfsi, __fixdfti,
__fixsfdi, __fixsfsi, __fixsfti,
__fixtfdi, __fixtfsi, __fixtfti.
These all call fixint which is a generic zig function that does the
conversion:
pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t
There are also a set tests:
__fixdfdi_test, __fixdfsi_test, __fixdfti_test,
__fixsfdi_test, __fixsfsi_test, __fixsfti_test,
__fixtfdi_test, __fixtfsi_test, __fixtfti_test.23 files changed, 1004 insertions(+), 0 deletions(-)
CMakeLists.txt+10| ... | ... | @@ -623,6 +623,16 @@ set(ZIG_STD_FILES |
| 623 | 623 | "special/compiler_rt/fixunstfdi.zig" |
| 624 | 624 | "special/compiler_rt/fixunstfsi.zig" |
| 625 | 625 | "special/compiler_rt/fixunstfti.zig" |
| 626 | "special/compiler_rt/fixint.zig" | |
| 627 | "special/compiler_rt/fixdfdi.zig" | |
| 628 | "special/compiler_rt/fixdfsi.zig" | |
| 629 | "special/compiler_rt/fixdfti.zig" | |
| 630 | "special/compiler_rt/fixsfdi.zig" | |
| 631 | "special/compiler_rt/fixsfsi.zig" | |
| 632 | "special/compiler_rt/fixsfti.zig" | |
| 633 | "special/compiler_rt/fixtfdi.zig" | |
| 634 | "special/compiler_rt/fixtfsi.zig" | |
| 635 | "special/compiler_rt/fixtfti.zig" | |
| 626 | 636 | "special/compiler_rt/floattidf.zig" |
| 627 | 637 | "special/compiler_rt/floattisf.zig" |
| 628 | 638 | "special/compiler_rt/floattitf.zig" |
std/math/index.zig+7| ... | ... | @@ -6,6 +6,13 @@ const assert = std.debug.assert; |
| 6 | 6 | pub const e = 2.71828182845904523536028747135266249775724709369995; |
| 7 | 7 | pub const pi = 3.14159265358979323846264338327950288419716939937510; |
| 8 | 8 | |
| 9 | // From a small c++ [program using boost float128](https://github.com/winksaville/cpp_boost_float128) | |
| 10 | pub const f128_true_min = @bitCast(f128, u128(0x00000000000000000000000000000001)); | |
| 11 | pub const f128_min = @bitCast(f128, u128(0x00010000000000000000000000000000)); | |
| 12 | pub const f128_max = @bitCast(f128, u128(0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF)); | |
| 13 | pub const f128_epsilon = @bitCast(f128, u128(0x3F8F0000000000000000000000000000)); | |
| 14 | pub const f128_toint = 1.0 / f128_epsilon; | |
| 15 | ||
| 9 | 16 | // float.h details |
| 10 | 17 | pub const f64_true_min = 4.94065645841246544177e-324; |
| 11 | 18 | pub const f64_min = 2.2250738585072014e-308; |
std/special/compiler_rt/fixdfdi.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const fixint = @import("fixint.zig").fixint; | |
| 2 | const builtin = @import("builtin"); | |
| 3 | ||
| 4 | pub extern fn __fixdfdi(a: f64) i64 { | |
| 5 | @setRuntimeSafety(builtin.is_test); | |
| 6 | return fixint(f64, i64, a); | |
| 7 | } | |
| 8 | ||
| 9 | test "import fixdfdi" { | |
| 10 | _ = @import("fixdfdi_test.zig"); | |
| 11 | } |
std/special/compiler_rt/fixdfdi_test.zig created+66| ... | ... | @@ -0,0 +1,66 @@ |
| 1 | const __fixdfdi = @import("fixdfdi.zig").__fixdfdi; | |
| 2 | const std = @import("std"); | |
| 3 | const math = std.math; | |
| 4 | const assert = std.debug.assert; | |
| 5 | const warn = std.debug.warn; | |
| 6 | ||
| 7 | fn test__fixdfdi(a: f64, expected: i64) void { | |
| 8 | const x = __fixdfdi(a); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)); | |
| 10 | assert(x == expected); | |
| 11 | } | |
| 12 | ||
| 13 | test "fixdfdi" { | |
| 14 | //warn("\n"); | |
| 15 | ||
| 16 | test__fixdfdi(-math.f64_max, math.minInt(i64)); | |
| 17 | ||
| 18 | test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); | |
| 19 | test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000); | |
| 20 | ||
| 21 | test__fixdfdi(-0x1.0000000000000p+127, -0x8000000000000000); | |
| 22 | test__fixdfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000); | |
| 23 | test__fixdfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000); | |
| 24 | ||
| 25 | test__fixdfdi(-0x1.0000000000001p+63, -0x8000000000000000); | |
| 26 | test__fixdfdi(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 27 | test__fixdfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00); | |
| 28 | test__fixdfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800); | |
| 29 | ||
| 30 | test__fixdfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 31 | test__fixdfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 32 | ||
| 33 | test__fixdfdi(-2.01, -2); | |
| 34 | test__fixdfdi(-2.0, -2); | |
| 35 | test__fixdfdi(-1.99, -1); | |
| 36 | test__fixdfdi(-1.0, -1); | |
| 37 | test__fixdfdi(-0.99, 0); | |
| 38 | test__fixdfdi(-0.5, 0); | |
| 39 | test__fixdfdi(-math.f64_min, 0); | |
| 40 | test__fixdfdi(0.0, 0); | |
| 41 | test__fixdfdi(math.f64_min, 0); | |
| 42 | test__fixdfdi(0.5, 0); | |
| 43 | test__fixdfdi(0.99, 0); | |
| 44 | test__fixdfdi(1.0, 1); | |
| 45 | test__fixdfdi(1.5, 1); | |
| 46 | test__fixdfdi(1.99, 1); | |
| 47 | test__fixdfdi(2.0, 2); | |
| 48 | test__fixdfdi(2.01, 2); | |
| 49 | ||
| 50 | test__fixdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 51 | test__fixdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 52 | ||
| 53 | test__fixdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 54 | test__fixdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 55 | test__fixdfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF); | |
| 56 | test__fixdfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF); | |
| 57 | ||
| 58 | test__fixdfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF); | |
| 59 | test__fixdfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF); | |
| 60 | test__fixdfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF); | |
| 61 | ||
| 62 | test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF); | |
| 63 | test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64)); | |
| 64 | ||
| 65 | test__fixdfdi(math.f64_max, math.maxInt(i64)); | |
| 66 | } |
std/special/compiler_rt/fixdfsi.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const fixint = @import("fixint.zig").fixint; | |
| 2 | const builtin = @import("builtin"); | |
| 3 | ||
| 4 | pub extern fn __fixdfsi(a: f64) i32 { | |
| 5 | @setRuntimeSafety(builtin.is_test); | |
| 6 | return fixint(f64, i32, a); | |
| 7 | } | |
| 8 | ||
| 9 | test "import fixdfsi" { | |
| 10 | _ = @import("fixdfsi_test.zig"); | |
| 11 | } |
std/special/compiler_rt/fixdfsi_test.zig created+74| ... | ... | @@ -0,0 +1,74 @@ |
| 1 | const __fixdfsi = @import("fixdfsi.zig").__fixdfsi; | |
| 2 | const std = @import("std"); | |
| 3 | const math = std.math; | |
| 4 | const assert = std.debug.assert; | |
| 5 | const warn = std.debug.warn; | |
| 6 | ||
| 7 | fn test__fixdfsi(a: f64, expected: i32) void { | |
| 8 | const x = __fixdfsi(a); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)); | |
| 10 | assert(x == expected); | |
| 11 | } | |
| 12 | ||
| 13 | test "fixdfsi" { | |
| 14 | //warn("\n"); | |
| 15 | ||
| 16 | test__fixdfsi(-math.f64_max, math.minInt(i32)); | |
| 17 | ||
| 18 | test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); | |
| 19 | test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000); | |
| 20 | ||
| 21 | test__fixdfsi(-0x1.0000000000000p+127, -0x80000000); | |
| 22 | test__fixdfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000); | |
| 23 | test__fixdfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000); | |
| 24 | ||
| 25 | test__fixdfsi(-0x1.0000000000001p+63, -0x80000000); | |
| 26 | test__fixdfsi(-0x1.0000000000000p+63, -0x80000000); | |
| 27 | test__fixdfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000); | |
| 28 | test__fixdfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000); | |
| 29 | ||
| 30 | test__fixdfsi(-0x1.FFFFFEp+62, -0x80000000); | |
| 31 | test__fixdfsi(-0x1.FFFFFCp+62, -0x80000000); | |
| 32 | ||
| 33 | test__fixdfsi(-0x1.000000p+31, -0x80000000); | |
| 34 | test__fixdfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0); | |
| 35 | test__fixdfsi(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 36 | ||
| 37 | test__fixdfsi(-2.01, -2); | |
| 38 | test__fixdfsi(-2.0, -2); | |
| 39 | test__fixdfsi(-1.99, -1); | |
| 40 | test__fixdfsi(-1.0, -1); | |
| 41 | test__fixdfsi(-0.99, 0); | |
| 42 | test__fixdfsi(-0.5, 0); | |
| 43 | test__fixdfsi(-math.f64_min, 0); | |
| 44 | test__fixdfsi(0.0, 0); | |
| 45 | test__fixdfsi(math.f64_min, 0); | |
| 46 | test__fixdfsi(0.5, 0); | |
| 47 | test__fixdfsi(0.99, 0); | |
| 48 | test__fixdfsi(1.0, 1); | |
| 49 | test__fixdfsi(1.5, 1); | |
| 50 | test__fixdfsi(1.99, 1); | |
| 51 | test__fixdfsi(2.0, 2); | |
| 52 | test__fixdfsi(2.01, 2); | |
| 53 | ||
| 54 | test__fixdfsi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 55 | test__fixdfsi(0x1.FFFFFFp+30, 0x7FFFFFC0); | |
| 56 | test__fixdfsi(0x1.000000p+31, 0x7FFFFFFF); | |
| 57 | ||
| 58 | test__fixdfsi(0x1.FFFFFCp+62, 0x7FFFFFFF); | |
| 59 | test__fixdfsi(0x1.FFFFFEp+62, 0x7FFFFFFF); | |
| 60 | ||
| 61 | test__fixdfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF); | |
| 62 | test__fixdfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF); | |
| 63 | test__fixdfsi(0x1.0000000000000p+63, 0x7FFFFFFF); | |
| 64 | test__fixdfsi(0x1.0000000000001p+63, 0x7FFFFFFF); | |
| 65 | ||
| 66 | test__fixdfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF); | |
| 67 | test__fixdfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF); | |
| 68 | test__fixdfsi(0x1.0000000000000p+127, 0x7FFFFFFF); | |
| 69 | ||
| 70 | test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF); | |
| 71 | test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32)); | |
| 72 | ||
| 73 | test__fixdfsi(math.f64_max, math.maxInt(i32)); | |
| 74 | } |
std/special/compiler_rt/fixdfti.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const fixint = @import("fixint.zig").fixint; | |
| 2 | const builtin = @import("builtin"); | |
| 3 | ||
| 4 | pub extern fn __fixdfti(a: f64) i128 { | |
| 5 | @setRuntimeSafety(builtin.is_test); | |
| 6 | return fixint(f64, i128, a); | |
| 7 | } | |
| 8 | ||
| 9 | test "import fixdfti" { | |
| 10 | _ = @import("fixdfti_test.zig"); | |
| 11 | } |
std/special/compiler_rt/fixdfti_test.zig created+66| ... | ... | @@ -0,0 +1,66 @@ |
| 1 | const __fixdfti = @import("fixdfti.zig").__fixdfti; | |
| 2 | const std = @import("std"); | |
| 3 | const math = std.math; | |
| 4 | const assert = std.debug.assert; | |
| 5 | const warn = std.debug.warn; | |
| 6 | ||
| 7 | fn test__fixdfti(a: f64, expected: i128) void { | |
| 8 | const x = __fixdfti(a); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)); | |
| 10 | assert(x == expected); | |
| 11 | } | |
| 12 | ||
| 13 | test "fixdfti" { | |
| 14 | //warn("\n"); | |
| 15 | ||
| 16 | test__fixdfti(-math.f64_max, math.minInt(i128)); | |
| 17 | ||
| 18 | test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); | |
| 19 | test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000); | |
| 20 | ||
| 21 | test__fixdfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000); | |
| 22 | test__fixdfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000); | |
| 23 | test__fixdfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000); | |
| 24 | ||
| 25 | test__fixdfti(-0x1.0000000000001p+63, -0x8000000000000800); | |
| 26 | test__fixdfti(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 27 | test__fixdfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00); | |
| 28 | test__fixdfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800); | |
| 29 | ||
| 30 | test__fixdfti(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 31 | test__fixdfti(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 32 | ||
| 33 | test__fixdfti(-2.01, -2); | |
| 34 | test__fixdfti(-2.0, -2); | |
| 35 | test__fixdfti(-1.99, -1); | |
| 36 | test__fixdfti(-1.0, -1); | |
| 37 | test__fixdfti(-0.99, 0); | |
| 38 | test__fixdfti(-0.5, 0); | |
| 39 | test__fixdfti(-math.f64_min, 0); | |
| 40 | test__fixdfti(0.0, 0); | |
| 41 | test__fixdfti(math.f64_min, 0); | |
| 42 | test__fixdfti(0.5, 0); | |
| 43 | test__fixdfti(0.99, 0); | |
| 44 | test__fixdfti(1.0, 1); | |
| 45 | test__fixdfti(1.5, 1); | |
| 46 | test__fixdfti(1.99, 1); | |
| 47 | test__fixdfti(2.0, 2); | |
| 48 | test__fixdfti(2.01, 2); | |
| 49 | ||
| 50 | test__fixdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 51 | test__fixdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 52 | ||
| 53 | test__fixdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 54 | test__fixdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 55 | test__fixdfti(0x1.0000000000000p+63, 0x8000000000000000); | |
| 56 | test__fixdfti(0x1.0000000000001p+63, 0x8000000000000800); | |
| 57 | ||
| 58 | test__fixdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000); | |
| 59 | test__fixdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000); | |
| 60 | test__fixdfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 61 | ||
| 62 | test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 63 | test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128)); | |
| 64 | ||
| 65 | test__fixdfti(math.f64_max, math.maxInt(i128)); | |
| 66 | } |
std/special/compiler_rt/fixint.zig created+74| ... | ... | @@ -0,0 +1,74 @@ |
| 1 | const is_test = @import("builtin").is_test; | |
| 2 | const std = @import("std"); | |
| 3 | const math = std.math; | |
| 4 | const Log2Int = std.math.Log2Int; | |
| 5 | const maxInt = std.math.maxInt; | |
| 6 | const minInt = std.math.minInt; | |
| 7 | ||
| 8 | const DBG = false; | |
| 9 | ||
| 10 | pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t { | |
| 11 | @setRuntimeSafety(is_test); | |
| 12 | ||
| 13 | const rep_t = switch (fp_t) { | |
| 14 | f32 => u32, | |
| 15 | f64 => u64, | |
| 16 | f128 => u128, | |
| 17 | else => unreachable, | |
| 18 | }; | |
| 19 | const significandBits = switch (fp_t) { | |
| 20 | f32 => 23, | |
| 21 | f64 => 52, | |
| 22 | f128 => 112, | |
| 23 | else => unreachable, | |
| 24 | }; | |
| 25 | ||
| 26 | const typeWidth = rep_t.bit_count; | |
| 27 | const exponentBits = (typeWidth - significandBits - 1); | |
| 28 | const signBit = (rep_t(1) << (significandBits + exponentBits)); | |
| 29 | const maxExponent = ((1 << exponentBits) - 1); | |
| 30 | const exponentBias = (maxExponent >> 1); | |
| 31 | ||
| 32 | const implicitBit = (rep_t(1) << significandBits); | |
| 33 | const significandMask = (implicitBit - 1); | |
| 34 | ||
| 35 | // Break a into sign, exponent, significand | |
| 36 | const aRep: rep_t = @bitCast(rep_t, a); | |
| 37 | const absMask = signBit - 1; | |
| 38 | const aAbs: rep_t = aRep & absMask; | |
| 39 | ||
| 40 | const negative = (aRep & signBit) != 0; | |
| 41 | const exponent = @intCast(i32, aAbs >> significandBits) - exponentBias; | |
| 42 | const significand: rep_t = (aAbs & significandMask) | implicitBit; | |
| 43 | ||
| 44 | // If exponent is negative, the uint_result is zero. | |
| 45 | if (exponent < 0) return 0; | |
| 46 | ||
| 47 | // The unsigned result needs to be large enough to handle an fixint_t or rep_t | |
| 48 | const fixuint_t = @IntType(false, fixint_t.bit_count); | |
| 49 | const UintResultType = if (fixint_t.bit_count > rep_t.bit_count) fixuint_t else rep_t; | |
| 50 | var uint_result: UintResultType = undefined; | |
| 51 | ||
| 52 | // If the value is too large for the integer type, saturate. | |
| 53 | if (@intCast(usize, exponent) >= fixint_t.bit_count) { | |
| 54 | return if (negative) fixint_t(minInt(fixint_t)) else fixint_t(maxInt(fixint_t)); | |
| 55 | } | |
| 56 | ||
| 57 | // If 0 <= exponent < significandBits, right shift else left shift | |
| 58 | if (exponent < significandBits) { | |
| 59 | uint_result = @intCast(UintResultType, significand) >> @intCast(Log2Int(UintResultType), significandBits - exponent); | |
| 60 | } else { | |
| 61 | uint_result = @intCast(UintResultType, significand) << @intCast(Log2Int(UintResultType), exponent - significandBits); | |
| 62 | } | |
| 63 | ||
| 64 | // Cast to final signed result | |
| 65 | if (negative) { | |
| 66 | return if (uint_result >= -math.minInt(fixint_t)) math.minInt(fixint_t) else -@intCast(fixint_t, uint_result); | |
| 67 | } else { | |
| 68 | return if (uint_result >= math.maxInt(fixint_t)) math.maxInt(fixint_t) else @intCast(fixint_t, uint_result); | |
| 69 | } | |
| 70 | } | |
| 71 | ||
| 72 | test "import fixint" { | |
| 73 | _ = @import("fixint_test.zig"); | |
| 74 | } |
std/special/compiler_rt/fixint_test.zig created+152| ... | ... | @@ -0,0 +1,152 @@ |
| 1 | const is_test = @import("builtin").is_test; | |
| 2 | const std = @import("std"); | |
| 3 | const math = std.math; | |
| 4 | const assert = std.debug.assert; | |
| 5 | const warn = std.debug.warn; | |
| 6 | ||
| 7 | const fixint = @import("fixint.zig").fixint; | |
| 8 | ||
| 9 | fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) void { | |
| 10 | const x = fixint(fp_t, fixint_t, a); | |
| 11 | //warn("a={} x={}:{x} expected={}:{x})\n", a, x, x, expected, expected); | |
| 12 | assert(x == expected); | |
| 13 | } | |
| 14 | ||
| 15 | test "fixint.i1" { | |
| 16 | test__fixint(f32, i1, -math.inf_f32, -1); | |
| 17 | test__fixint(f32, i1, -math.f32_max, -1); | |
| 18 | test__fixint(f32, i1, -2.0, -1); | |
| 19 | test__fixint(f32, i1, -1.1, -1); | |
| 20 | test__fixint(f32, i1, -1.0, -1); | |
| 21 | test__fixint(f32, i1, -0.9, 0); | |
| 22 | test__fixint(f32, i1, -0.1, 0); | |
| 23 | test__fixint(f32, i1, -math.f32_min, 0); | |
| 24 | test__fixint(f32, i1, -0.0, 0); | |
| 25 | test__fixint(f32, i1, 0.0, 0); | |
| 26 | test__fixint(f32, i1, math.f32_min, 0); | |
| 27 | test__fixint(f32, i1, 0.1, 0); | |
| 28 | test__fixint(f32, i1, 0.9, 0); | |
| 29 | test__fixint(f32, i1, 1.0, 0); | |
| 30 | test__fixint(f32, i1, 2.0, 0); | |
| 31 | test__fixint(f32, i1, math.f32_max, 0); | |
| 32 | test__fixint(f32, i1, math.inf_f32, 0); | |
| 33 | } | |
| 34 | ||
| 35 | test "fixint.i2" { | |
| 36 | test__fixint(f32, i2, -math.inf_f32, -2); | |
| 37 | test__fixint(f32, i2, -math.f32_max, -2); | |
| 38 | test__fixint(f32, i2, -2.0, -2); | |
| 39 | test__fixint(f32, i2, -1.9, -1); | |
| 40 | test__fixint(f32, i2, -1.1, -1); | |
| 41 | test__fixint(f32, i2, -1.0, -1); | |
| 42 | test__fixint(f32, i2, -0.9, 0); | |
| 43 | test__fixint(f32, i2, -0.1, 0); | |
| 44 | test__fixint(f32, i2, -math.f32_min, 0); | |
| 45 | test__fixint(f32, i2, -0.0, 0); | |
| 46 | test__fixint(f32, i2, 0.0, 0); | |
| 47 | test__fixint(f32, i2, math.f32_min, 0); | |
| 48 | test__fixint(f32, i2, 0.1, 0); | |
| 49 | test__fixint(f32, i2, 0.9, 0); | |
| 50 | test__fixint(f32, i2, 1.0, 1); | |
| 51 | test__fixint(f32, i2, 2.0, 1); | |
| 52 | test__fixint(f32, i2, math.f32_max, 1); | |
| 53 | test__fixint(f32, i2, math.inf_f32, 1); | |
| 54 | } | |
| 55 | ||
| 56 | test "fixint.i3" { | |
| 57 | test__fixint(f32, i3, -math.inf_f32, -4); | |
| 58 | test__fixint(f32, i3, -math.f32_max, -4); | |
| 59 | test__fixint(f32, i3, -4.0, -4); | |
| 60 | test__fixint(f32, i3, -3.0, -3); | |
| 61 | test__fixint(f32, i3, -2.0, -2); | |
| 62 | test__fixint(f32, i3, -1.9, -1); | |
| 63 | test__fixint(f32, i3, -1.1, -1); | |
| 64 | test__fixint(f32, i3, -1.0, -1); | |
| 65 | test__fixint(f32, i3, -0.9, 0); | |
| 66 | test__fixint(f32, i3, -0.1, 0); | |
| 67 | test__fixint(f32, i3, -math.f32_min, 0); | |
| 68 | test__fixint(f32, i3, -0.0, 0); | |
| 69 | test__fixint(f32, i3, 0.0, 0); | |
| 70 | test__fixint(f32, i3, math.f32_min, 0); | |
| 71 | test__fixint(f32, i3, 0.1, 0); | |
| 72 | test__fixint(f32, i3, 0.9, 0); | |
| 73 | test__fixint(f32, i3, 1.0, 1); | |
| 74 | test__fixint(f32, i3, 2.0, 2); | |
| 75 | test__fixint(f32, i3, 3.0, 3); | |
| 76 | test__fixint(f32, i3, 4.0, 3); | |
| 77 | test__fixint(f32, i3, math.f32_max, 3); | |
| 78 | test__fixint(f32, i3, math.inf_f32, 3); | |
| 79 | } | |
| 80 | ||
| 81 | test "fixint.i32" { | |
| 82 | test__fixint(f64, i32, -math.inf_f64, math.minInt(i32)); | |
| 83 | test__fixint(f64, i32, -math.f64_max, math.minInt(i32)); | |
| 84 | test__fixint(f64, i32, f64(math.minInt(i32)), math.minInt(i32)); | |
| 85 | test__fixint(f64, i32, f64(math.minInt(i32))+1, math.minInt(i32)+1); | |
| 86 | test__fixint(f64, i32, -2.0, -2); | |
| 87 | test__fixint(f64, i32, -1.9, -1); | |
| 88 | test__fixint(f64, i32, -1.1, -1); | |
| 89 | test__fixint(f64, i32, -1.0, -1); | |
| 90 | test__fixint(f64, i32, -0.9, 0); | |
| 91 | test__fixint(f64, i32, -0.1, 0); | |
| 92 | test__fixint(f64, i32, -math.f32_min, 0); | |
| 93 | test__fixint(f64, i32, -0.0, 0); | |
| 94 | test__fixint(f64, i32, 0.0, 0); | |
| 95 | test__fixint(f64, i32, math.f32_min, 0); | |
| 96 | test__fixint(f64, i32, 0.1, 0); | |
| 97 | test__fixint(f64, i32, 0.9, 0); | |
| 98 | test__fixint(f64, i32, 1.0, 1); | |
| 99 | test__fixint(f64, i32, f64(math.maxInt(i32))-1, math.maxInt(i32)-1); | |
| 100 | test__fixint(f64, i32, f64(math.maxInt(i32)), math.maxInt(i32)); | |
| 101 | test__fixint(f64, i32, math.f64_max, math.maxInt(i32)); | |
| 102 | test__fixint(f64, i32, math.inf_f64, math.maxInt(i32)); | |
| 103 | } | |
| 104 | ||
| 105 | test "fixint.i64" { | |
| 106 | test__fixint(f64, i64, -math.inf_f64, math.minInt(i64)); | |
| 107 | test__fixint(f64, i64, -math.f64_max, math.minInt(i64)); | |
| 108 | test__fixint(f64, i64, f64(math.minInt(i64)), math.minInt(i64)); | |
| 109 | test__fixint(f64, i64, f64(math.minInt(i64))+1, math.minInt(i64)); | |
| 110 | test__fixint(f64, i64, f64(math.minInt(i64)/2), math.minInt(i64)/2); | |
| 111 | test__fixint(f64, i64, -2.0, -2); | |
| 112 | test__fixint(f64, i64, -1.9, -1); | |
| 113 | test__fixint(f64, i64, -1.1, -1); | |
| 114 | test__fixint(f64, i64, -1.0, -1); | |
| 115 | test__fixint(f64, i64, -0.9, 0); | |
| 116 | test__fixint(f64, i64, -0.1, 0); | |
| 117 | test__fixint(f64, i64, -math.f32_min, 0); | |
| 118 | test__fixint(f64, i64, -0.0, 0); | |
| 119 | test__fixint(f64, i64, 0.0, 0); | |
| 120 | test__fixint(f64, i64, math.f32_min, 0); | |
| 121 | test__fixint(f64, i64, 0.1, 0); | |
| 122 | test__fixint(f64, i64, 0.9, 0); | |
| 123 | test__fixint(f64, i64, 1.0, 1); | |
| 124 | test__fixint(f64, i64, f64(math.maxInt(i64))-1, math.maxInt(i64)); | |
| 125 | test__fixint(f64, i64, f64(math.maxInt(i64)), math.maxInt(i64)); | |
| 126 | test__fixint(f64, i64, math.f64_max, math.maxInt(i64)); | |
| 127 | test__fixint(f64, i64, math.inf_f64, math.maxInt(i64)); | |
| 128 | } | |
| 129 | ||
| 130 | test "fixint.i128" { | |
| 131 | test__fixint(f64, i128, -math.inf_f64, math.minInt(i128)); | |
| 132 | test__fixint(f64, i128, -math.f64_max, math.minInt(i128)); | |
| 133 | test__fixint(f64, i128, f64(math.minInt(i128)), math.minInt(i128)); | |
| 134 | test__fixint(f64, i128, f64(math.minInt(i128))+1, math.minInt(i128)); | |
| 135 | test__fixint(f64, i128, -2.0, -2); | |
| 136 | test__fixint(f64, i128, -1.9, -1); | |
| 137 | test__fixint(f64, i128, -1.1, -1); | |
| 138 | test__fixint(f64, i128, -1.0, -1); | |
| 139 | test__fixint(f64, i128, -0.9, 0); | |
| 140 | test__fixint(f64, i128, -0.1, 0); | |
| 141 | test__fixint(f64, i128, -math.f32_min, 0); | |
| 142 | test__fixint(f64, i128, -0.0, 0); | |
| 143 | test__fixint(f64, i128, 0.0, 0); | |
| 144 | test__fixint(f64, i128, math.f32_min, 0); | |
| 145 | test__fixint(f64, i128, 0.1, 0); | |
| 146 | test__fixint(f64, i128, 0.9, 0); | |
| 147 | test__fixint(f64, i128, 1.0, 1); | |
| 148 | test__fixint(f64, i128, f64(math.maxInt(i128))-1, math.maxInt(i128)); | |
| 149 | test__fixint(f64, i128, f64(math.maxInt(i128)), math.maxInt(i128)); | |
| 150 | test__fixint(f64, i128, math.f64_max, math.maxInt(i128)); | |
| 151 | test__fixint(f64, i128, math.inf_f64, math.maxInt(i128)); | |
| 152 | } |
std/special/compiler_rt/fixsfdi.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const fixint = @import("fixint.zig").fixint; | |
| 2 | const builtin = @import("builtin"); | |
| 3 | ||
| 4 | pub extern fn __fixsfdi(a: f32) i64 { | |
| 5 | @setRuntimeSafety(builtin.is_test); | |
| 6 | return fixint(f32, i64, a); | |
| 7 | } | |
| 8 | ||
| 9 | test "import fixsfdi" { | |
| 10 | _ = @import("fixsfdi_test.zig"); | |
| 11 | } |
std/special/compiler_rt/fixsfdi_test.zig created+68| ... | ... | @@ -0,0 +1,68 @@ |
| 1 | const __fixsfdi = @import("fixsfdi.zig").__fixsfdi; | |
| 2 | const std = @import("std"); | |
| 3 | const math = std.math; | |
| 4 | const assert = std.debug.assert; | |
| 5 | const warn = std.debug.warn; | |
| 6 | ||
| 7 | fn test__fixsfdi(a: f32, expected: i64) void { | |
| 8 | const x = __fixsfdi(a); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)); | |
| 10 | assert(x == expected); | |
| 11 | } | |
| 12 | ||
| 13 | test "fixsfdi" { | |
| 14 | //warn("\n"); | |
| 15 | ||
| 16 | test__fixsfdi(-math.f32_max, math.minInt(i64)); | |
| 17 | ||
| 18 | test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); | |
| 19 | test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000); | |
| 20 | ||
| 21 | test__fixsfdi(-0x1.0000000000000p+127, -0x8000000000000000); | |
| 22 | test__fixsfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000); | |
| 23 | test__fixsfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000); | |
| 24 | ||
| 25 | test__fixsfdi(-0x1.0000000000001p+63, -0x8000000000000000); | |
| 26 | test__fixsfdi(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 27 | test__fixsfdi(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000); | |
| 28 | test__fixsfdi(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000); | |
| 29 | ||
| 30 | test__fixsfdi(-0x1.FFFFFFp+62, -0x8000000000000000); | |
| 31 | test__fixsfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 32 | test__fixsfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 33 | ||
| 34 | test__fixsfdi(-2.01, -2); | |
| 35 | test__fixsfdi(-2.0, -2); | |
| 36 | test__fixsfdi(-1.99, -1); | |
| 37 | test__fixsfdi(-1.0, -1); | |
| 38 | test__fixsfdi(-0.99, 0); | |
| 39 | test__fixsfdi(-0.5, 0); | |
| 40 | test__fixsfdi(-math.f32_min, 0); | |
| 41 | test__fixsfdi(0.0, 0); | |
| 42 | test__fixsfdi(math.f32_min, 0); | |
| 43 | test__fixsfdi(0.5, 0); | |
| 44 | test__fixsfdi(0.99, 0); | |
| 45 | test__fixsfdi(1.0, 1); | |
| 46 | test__fixsfdi(1.5, 1); | |
| 47 | test__fixsfdi(1.99, 1); | |
| 48 | test__fixsfdi(2.0, 2); | |
| 49 | test__fixsfdi(2.01, 2); | |
| 50 | ||
| 51 | test__fixsfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 52 | test__fixsfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 53 | test__fixsfdi(0x1.FFFFFFp+62, 0x7FFFFFFFFFFFFFFF); | |
| 54 | ||
| 55 | test__fixsfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFFFFF); | |
| 56 | test__fixsfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFFFF); | |
| 57 | test__fixsfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF); | |
| 58 | test__fixsfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF); | |
| 59 | ||
| 60 | test__fixsfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF); | |
| 61 | test__fixsfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF); | |
| 62 | test__fixsfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF); | |
| 63 | ||
| 64 | test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF); | |
| 65 | test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64)); | |
| 66 | ||
| 67 | test__fixsfdi(math.f64_max, math.maxInt(i64)); | |
| 68 | } |
std/special/compiler_rt/fixsfsi.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const fixint = @import("fixint.zig").fixint; | |
| 2 | const builtin = @import("builtin"); | |
| 3 | ||
| 4 | pub extern fn __fixsfsi(a: f32) i32 { | |
| 5 | @setRuntimeSafety(builtin.is_test); | |
| 6 | return fixint(f32, i32, a); | |
| 7 | } | |
| 8 | ||
| 9 | test "import fixsfsi" { | |
| 10 | _ = @import("fixsfsi_test.zig"); | |
| 11 | } |
std/special/compiler_rt/fixsfsi_test.zig created+76| ... | ... | @@ -0,0 +1,76 @@ |
| 1 | const __fixsfsi = @import("fixsfsi.zig").__fixsfsi; | |
| 2 | const std = @import("std"); | |
| 3 | const math = std.math; | |
| 4 | const assert = std.debug.assert; | |
| 5 | const warn = std.debug.warn; | |
| 6 | ||
| 7 | fn test__fixsfsi(a: f32, expected: i32) void { | |
| 8 | const x = __fixsfsi(a); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)); | |
| 10 | assert(x == expected); | |
| 11 | } | |
| 12 | ||
| 13 | test "fixsfsi" { | |
| 14 | //warn("\n"); | |
| 15 | ||
| 16 | test__fixsfsi(-math.f32_max, math.minInt(i32)); | |
| 17 | ||
| 18 | test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); | |
| 19 | test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000); | |
| 20 | ||
| 21 | test__fixsfsi(-0x1.0000000000000p+127, -0x80000000); | |
| 22 | test__fixsfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000); | |
| 23 | test__fixsfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000); | |
| 24 | ||
| 25 | test__fixsfsi(-0x1.0000000000001p+63, -0x80000000); | |
| 26 | test__fixsfsi(-0x1.0000000000000p+63, -0x80000000); | |
| 27 | test__fixsfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000); | |
| 28 | test__fixsfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000); | |
| 29 | ||
| 30 | test__fixsfsi(-0x1.FFFFFEp+62, -0x80000000); | |
| 31 | test__fixsfsi(-0x1.FFFFFCp+62, -0x80000000); | |
| 32 | ||
| 33 | test__fixsfsi(-0x1.000000p+31, -0x80000000); | |
| 34 | test__fixsfsi(-0x1.FFFFFFp+30, -0x80000000); | |
| 35 | test__fixsfsi(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 36 | test__fixsfsi(-0x1.FFFFFCp+30, -0x7FFFFF00); | |
| 37 | ||
| 38 | test__fixsfsi(-2.01, -2); | |
| 39 | test__fixsfsi(-2.0, -2); | |
| 40 | test__fixsfsi(-1.99, -1); | |
| 41 | test__fixsfsi(-1.0, -1); | |
| 42 | test__fixsfsi(-0.99, 0); | |
| 43 | test__fixsfsi(-0.5, 0); | |
| 44 | test__fixsfsi(-math.f32_min, 0); | |
| 45 | test__fixsfsi(0.0, 0); | |
| 46 | test__fixsfsi(math.f32_min, 0); | |
| 47 | test__fixsfsi(0.5, 0); | |
| 48 | test__fixsfsi(0.99, 0); | |
| 49 | test__fixsfsi(1.0, 1); | |
| 50 | test__fixsfsi(1.5, 1); | |
| 51 | test__fixsfsi(1.99, 1); | |
| 52 | test__fixsfsi(2.0, 2); | |
| 53 | test__fixsfsi(2.01, 2); | |
| 54 | ||
| 55 | test__fixsfsi(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 56 | test__fixsfsi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 57 | test__fixsfsi(0x1.FFFFFFp+30, 0x7FFFFFFF); | |
| 58 | test__fixsfsi(0x1.000000p+31, 0x7FFFFFFF); | |
| 59 | ||
| 60 | test__fixsfsi(0x1.FFFFFCp+62, 0x7FFFFFFF); | |
| 61 | test__fixsfsi(0x1.FFFFFEp+62, 0x7FFFFFFF); | |
| 62 | ||
| 63 | test__fixsfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF); | |
| 64 | test__fixsfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF); | |
| 65 | test__fixsfsi(0x1.0000000000000p+63, 0x7FFFFFFF); | |
| 66 | test__fixsfsi(0x1.0000000000001p+63, 0x7FFFFFFF); | |
| 67 | ||
| 68 | test__fixsfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF); | |
| 69 | test__fixsfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF); | |
| 70 | test__fixsfsi(0x1.0000000000000p+127, 0x7FFFFFFF); | |
| 71 | ||
| 72 | test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF); | |
| 73 | test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32)); | |
| 74 | ||
| 75 | test__fixsfsi(math.f32_max, math.maxInt(i32)); | |
| 76 | } |
std/special/compiler_rt/fixsfti.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const fixint = @import("fixint.zig").fixint; | |
| 2 | const builtin = @import("builtin"); | |
| 3 | ||
| 4 | pub extern fn __fixsfti(a: f32) i128 { | |
| 5 | @setRuntimeSafety(builtin.is_test); | |
| 6 | return fixint(f32, i128, a); | |
| 7 | } | |
| 8 | ||
| 9 | test "import fixsfti" { | |
| 10 | _ = @import("fixsfti_test.zig"); | |
| 11 | } |
std/special/compiler_rt/fixsfti_test.zig created+84| ... | ... | @@ -0,0 +1,84 @@ |
| 1 | const __fixsfti = @import("fixsfti.zig").__fixsfti; | |
| 2 | const std = @import("std"); | |
| 3 | const math = std.math; | |
| 4 | const assert = std.debug.assert; | |
| 5 | const warn = std.debug.warn; | |
| 6 | ||
| 7 | fn test__fixsfti(a: f32, expected: i128) void { | |
| 8 | const x = __fixsfti(a); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)); | |
| 10 | assert(x == expected); | |
| 11 | } | |
| 12 | ||
| 13 | test "fixsfti" { | |
| 14 | //warn("\n"); | |
| 15 | ||
| 16 | test__fixsfti(-math.f32_max, math.minInt(i128)); | |
| 17 | ||
| 18 | test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); | |
| 19 | test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000); | |
| 20 | ||
| 21 | test__fixsfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000); | |
| 22 | test__fixsfti(-0x1.FFFFFFFFFFFFFp+126, -0x80000000000000000000000000000000); | |
| 23 | test__fixsfti(-0x1.FFFFFFFFFFFFEp+126, -0x80000000000000000000000000000000); | |
| 24 | test__fixsfti(-0x1.FFFFFF0000000p+126, -0x80000000000000000000000000000000); | |
| 25 | test__fixsfti(-0x1.FFFFFE0000000p+126, -0x7FFFFF80000000000000000000000000); | |
| 26 | test__fixsfti(-0x1.FFFFFC0000000p+126, -0x7FFFFF00000000000000000000000000); | |
| 27 | ||
| 28 | test__fixsfti(-0x1.0000000000001p+63, -0x8000000000000000); | |
| 29 | test__fixsfti(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 30 | test__fixsfti(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000); | |
| 31 | test__fixsfti(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000); | |
| 32 | ||
| 33 | test__fixsfti(-0x1.FFFFFFp+62, -0x8000000000000000); | |
| 34 | test__fixsfti(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 35 | test__fixsfti(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 36 | ||
| 37 | test__fixsfti(-0x1.000000p+31, -0x80000000); | |
| 38 | test__fixsfti(-0x1.FFFFFFp+30, -0x80000000); | |
| 39 | test__fixsfti(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 40 | test__fixsfti(-0x1.FFFFFCp+30, -0x7FFFFF00); | |
| 41 | ||
| 42 | test__fixsfti(-2.01, -2); | |
| 43 | test__fixsfti(-2.0, -2); | |
| 44 | test__fixsfti(-1.99, -1); | |
| 45 | test__fixsfti(-1.0, -1); | |
| 46 | test__fixsfti(-0.99, 0); | |
| 47 | test__fixsfti(-0.5, 0); | |
| 48 | test__fixsfti(-math.f32_min, 0); | |
| 49 | test__fixsfti(0.0, 0); | |
| 50 | test__fixsfti(math.f32_min, 0); | |
| 51 | test__fixsfti(0.5, 0); | |
| 52 | test__fixsfti(0.99, 0); | |
| 53 | test__fixsfti(1.0, 1); | |
| 54 | test__fixsfti(1.5, 1); | |
| 55 | test__fixsfti(1.99, 1); | |
| 56 | test__fixsfti(2.0, 2); | |
| 57 | test__fixsfti(2.01, 2); | |
| 58 | ||
| 59 | test__fixsfti(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 60 | test__fixsfti(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 61 | test__fixsfti(0x1.FFFFFFp+30, 0x80000000); | |
| 62 | test__fixsfti(0x1.000000p+31, 0x80000000); | |
| 63 | ||
| 64 | test__fixsfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 65 | test__fixsfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 66 | test__fixsfti(0x1.FFFFFFp+62, 0x8000000000000000); | |
| 67 | ||
| 68 | test__fixsfti(0x1.FFFFFFFFFFFFEp+62, 0x8000000000000000); | |
| 69 | test__fixsfti(0x1.FFFFFFFFFFFFFp+62, 0x8000000000000000); | |
| 70 | test__fixsfti(0x1.0000000000000p+63, 0x8000000000000000); | |
| 71 | test__fixsfti(0x1.0000000000001p+63, 0x8000000000000000); | |
| 72 | ||
| 73 | test__fixsfti(0x1.FFFFFC0000000p+126, 0x7FFFFF00000000000000000000000000); | |
| 74 | test__fixsfti(0x1.FFFFFE0000000p+126, 0x7FFFFF80000000000000000000000000); | |
| 75 | test__fixsfti(0x1.FFFFFF0000000p+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 76 | test__fixsfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 77 | test__fixsfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 78 | test__fixsfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 79 | ||
| 80 | test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 81 | test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128)); | |
| 82 | ||
| 83 | test__fixsfti(math.f32_max, math.maxInt(i128)); | |
| 84 | } |
std/special/compiler_rt/fixtfdi.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const fixint = @import("fixint.zig").fixint; | |
| 2 | const builtin = @import("builtin"); | |
| 3 | ||
| 4 | pub extern fn __fixtfdi(a: f128) i64 { | |
| 5 | @setRuntimeSafety(builtin.is_test); | |
| 6 | return fixint(f128, i64, a); | |
| 7 | } | |
| 8 | ||
| 9 | test "import fixtfdi" { | |
| 10 | _ = @import("fixtfdi_test.zig"); | |
| 11 | } |
std/special/compiler_rt/fixtfdi_test.zig created+76| ... | ... | @@ -0,0 +1,76 @@ |
| 1 | const __fixtfdi = @import("fixtfdi.zig").__fixtfdi; | |
| 2 | const std = @import("std"); | |
| 3 | const math = std.math; | |
| 4 | const assert = std.debug.assert; | |
| 5 | const warn = std.debug.warn; | |
| 6 | ||
| 7 | fn test__fixtfdi(a: f128, expected: i64) void { | |
| 8 | const x = __fixtfdi(a); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)); | |
| 10 | assert(x == expected); | |
| 11 | } | |
| 12 | ||
| 13 | test "fixtfdi" { | |
| 14 | //warn("\n"); | |
| 15 | ||
| 16 | test__fixtfdi(-math.f128_max, math.minInt(i64)); | |
| 17 | ||
| 18 | test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); | |
| 19 | test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000); | |
| 20 | ||
| 21 | test__fixtfdi(-0x1.0000000000000p+127, -0x8000000000000000); | |
| 22 | test__fixtfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000); | |
| 23 | test__fixtfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000); | |
| 24 | ||
| 25 | test__fixtfdi(-0x1.0000000000001p+63, -0x8000000000000000); | |
| 26 | test__fixtfdi(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 27 | test__fixtfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00); | |
| 28 | test__fixtfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800); | |
| 29 | ||
| 30 | test__fixtfdi(-0x1.FFFFFEp+62, -0x7FFFFF8000000000); | |
| 31 | test__fixtfdi(-0x1.FFFFFCp+62, -0x7FFFFF0000000000); | |
| 32 | ||
| 33 | test__fixtfdi(-0x1.000000p+31, -0x80000000); | |
| 34 | test__fixtfdi(-0x1.FFFFFFp+30, -0x7FFFFFC0); | |
| 35 | test__fixtfdi(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 36 | test__fixtfdi(-0x1.FFFFFCp+30, -0x7FFFFF00); | |
| 37 | ||
| 38 | test__fixtfdi(-2.01, -2); | |
| 39 | test__fixtfdi(-2.0, -2); | |
| 40 | test__fixtfdi(-1.99, -1); | |
| 41 | test__fixtfdi(-1.0, -1); | |
| 42 | test__fixtfdi(-0.99, 0); | |
| 43 | test__fixtfdi(-0.5, 0); | |
| 44 | test__fixtfdi(-math.f64_min, 0); | |
| 45 | test__fixtfdi(0.0, 0); | |
| 46 | test__fixtfdi(math.f64_min, 0); | |
| 47 | test__fixtfdi(0.5, 0); | |
| 48 | test__fixtfdi(0.99, 0); | |
| 49 | test__fixtfdi(1.0, 1); | |
| 50 | test__fixtfdi(1.5, 1); | |
| 51 | test__fixtfdi(1.99, 1); | |
| 52 | test__fixtfdi(2.0, 2); | |
| 53 | test__fixtfdi(2.01, 2); | |
| 54 | ||
| 55 | test__fixtfdi(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 56 | test__fixtfdi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 57 | test__fixtfdi(0x1.FFFFFFp+30, 0x7FFFFFC0); | |
| 58 | test__fixtfdi(0x1.000000p+31, 0x80000000); | |
| 59 | ||
| 60 | test__fixtfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 61 | test__fixtfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 62 | ||
| 63 | test__fixtfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 64 | test__fixtfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 65 | test__fixtfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF); | |
| 66 | test__fixtfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF); | |
| 67 | ||
| 68 | test__fixtfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF); | |
| 69 | test__fixtfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF); | |
| 70 | test__fixtfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF); | |
| 71 | ||
| 72 | test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF); | |
| 73 | test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64)); | |
| 74 | ||
| 75 | test__fixtfdi(math.f128_max, math.maxInt(i64)); | |
| 76 | } |
std/special/compiler_rt/fixtfsi.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const fixint = @import("fixint.zig").fixint; | |
| 2 | const builtin = @import("builtin"); | |
| 3 | ||
| 4 | pub extern fn __fixtfsi(a: f128) i32 { | |
| 5 | @setRuntimeSafety(builtin.is_test); | |
| 6 | return fixint(f128, i32, a); | |
| 7 | } | |
| 8 | ||
| 9 | test "import fixtfsi" { | |
| 10 | _ = @import("fixtfsi_test.zig"); | |
| 11 | } |
std/special/compiler_rt/fixtfsi_test.zig created+76| ... | ... | @@ -0,0 +1,76 @@ |
| 1 | const __fixtfsi = @import("fixtfsi.zig").__fixtfsi; | |
| 2 | const std = @import("std"); | |
| 3 | const math = std.math; | |
| 4 | const assert = std.debug.assert; | |
| 5 | const warn = std.debug.warn; | |
| 6 | ||
| 7 | fn test__fixtfsi(a: f128, expected: i32) void { | |
| 8 | const x = __fixtfsi(a); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)); | |
| 10 | assert(x == expected); | |
| 11 | } | |
| 12 | ||
| 13 | test "fixtfsi" { | |
| 14 | //warn("\n"); | |
| 15 | ||
| 16 | test__fixtfsi(-math.f128_max, math.minInt(i32)); | |
| 17 | ||
| 18 | test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); | |
| 19 | test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000); | |
| 20 | ||
| 21 | test__fixtfsi(-0x1.0000000000000p+127, -0x80000000); | |
| 22 | test__fixtfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000); | |
| 23 | test__fixtfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000); | |
| 24 | ||
| 25 | test__fixtfsi(-0x1.0000000000001p+63, -0x80000000); | |
| 26 | test__fixtfsi(-0x1.0000000000000p+63, -0x80000000); | |
| 27 | test__fixtfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000); | |
| 28 | test__fixtfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000); | |
| 29 | ||
| 30 | test__fixtfsi(-0x1.FFFFFEp+62, -0x80000000); | |
| 31 | test__fixtfsi(-0x1.FFFFFCp+62, -0x80000000); | |
| 32 | ||
| 33 | test__fixtfsi(-0x1.000000p+31, -0x80000000); | |
| 34 | test__fixtfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0); | |
| 35 | test__fixtfsi(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 36 | test__fixtfsi(-0x1.FFFFFCp+30, -0x7FFFFF00); | |
| 37 | ||
| 38 | test__fixtfsi(-2.01, -2); | |
| 39 | test__fixtfsi(-2.0, -2); | |
| 40 | test__fixtfsi(-1.99, -1); | |
| 41 | test__fixtfsi(-1.0, -1); | |
| 42 | test__fixtfsi(-0.99, 0); | |
| 43 | test__fixtfsi(-0.5, 0); | |
| 44 | test__fixtfsi(-math.f32_min, 0); | |
| 45 | test__fixtfsi(0.0, 0); | |
| 46 | test__fixtfsi(math.f32_min, 0); | |
| 47 | test__fixtfsi(0.5, 0); | |
| 48 | test__fixtfsi(0.99, 0); | |
| 49 | test__fixtfsi(1.0, 1); | |
| 50 | test__fixtfsi(1.5, 1); | |
| 51 | test__fixtfsi(1.99, 1); | |
| 52 | test__fixtfsi(2.0, 2); | |
| 53 | test__fixtfsi(2.01, 2); | |
| 54 | ||
| 55 | test__fixtfsi(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 56 | test__fixtfsi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 57 | test__fixtfsi(0x1.FFFFFFp+30, 0x7FFFFFC0); | |
| 58 | test__fixtfsi(0x1.000000p+31, 0x7FFFFFFF); | |
| 59 | ||
| 60 | test__fixtfsi(0x1.FFFFFCp+62, 0x7FFFFFFF); | |
| 61 | test__fixtfsi(0x1.FFFFFEp+62, 0x7FFFFFFF); | |
| 62 | ||
| 63 | test__fixtfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF); | |
| 64 | test__fixtfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF); | |
| 65 | test__fixtfsi(0x1.0000000000000p+63, 0x7FFFFFFF); | |
| 66 | test__fixtfsi(0x1.0000000000001p+63, 0x7FFFFFFF); | |
| 67 | ||
| 68 | test__fixtfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF); | |
| 69 | test__fixtfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF); | |
| 70 | test__fixtfsi(0x1.0000000000000p+127, 0x7FFFFFFF); | |
| 71 | ||
| 72 | test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF); | |
| 73 | test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32)); | |
| 74 | ||
| 75 | test__fixtfsi(math.f128_max, math.maxInt(i32)); | |
| 76 | } |
std/special/compiler_rt/fixtfti.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const fixint = @import("fixint.zig").fixint; | |
| 2 | const builtin = @import("builtin"); | |
| 3 | ||
| 4 | pub extern fn __fixtfti(a: f128) i128 { | |
| 5 | @setRuntimeSafety(builtin.is_test); | |
| 6 | return fixint(f128, i128, a); | |
| 7 | } | |
| 8 | ||
| 9 | test "import fixtfti" { | |
| 10 | _ = @import("fixtfti_test.zig"); | |
| 11 | } |
std/special/compiler_rt/fixtfti_test.zig created+66| ... | ... | @@ -0,0 +1,66 @@ |
| 1 | const __fixtfti = @import("fixtfti.zig").__fixtfti; | |
| 2 | const std = @import("std"); | |
| 3 | const math = std.math; | |
| 4 | const assert = std.debug.assert; | |
| 5 | const warn = std.debug.warn; | |
| 6 | ||
| 7 | fn test__fixtfti(a: f128, expected: i128) void { | |
| 8 | const x = __fixtfti(a); | |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)); | |
| 10 | assert(x == expected); | |
| 11 | } | |
| 12 | ||
| 13 | test "fixtfti" { | |
| 14 | //warn("\n"); | |
| 15 | ||
| 16 | test__fixtfti(-math.f128_max, math.minInt(i128)); | |
| 17 | ||
| 18 | test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); | |
| 19 | test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000); | |
| 20 | ||
| 21 | test__fixtfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000); | |
| 22 | test__fixtfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000); | |
| 23 | test__fixtfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000); | |
| 24 | ||
| 25 | test__fixtfti(-0x1.0000000000001p+63, -0x8000000000000800); | |
| 26 | test__fixtfti(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 27 | test__fixtfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00); | |
| 28 | test__fixtfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800); | |
| 29 | ||
| 30 | test__fixtfti(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 31 | test__fixtfti(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 32 | ||
| 33 | test__fixtfti(-2.01, -2); | |
| 34 | test__fixtfti(-2.0, -2); | |
| 35 | test__fixtfti(-1.99, -1); | |
| 36 | test__fixtfti(-1.0, -1); | |
| 37 | test__fixtfti(-0.99, 0); | |
| 38 | test__fixtfti(-0.5, 0); | |
| 39 | test__fixtfti(-math.f128_min, 0); | |
| 40 | test__fixtfti(0.0, 0); | |
| 41 | test__fixtfti(math.f128_min, 0); | |
| 42 | test__fixtfti(0.5, 0); | |
| 43 | test__fixtfti(0.99, 0); | |
| 44 | test__fixtfti(1.0, 1); | |
| 45 | test__fixtfti(1.5, 1); | |
| 46 | test__fixtfti(1.99, 1); | |
| 47 | test__fixtfti(2.0, 2); | |
| 48 | test__fixtfti(2.01, 2); | |
| 49 | ||
| 50 | test__fixtfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 51 | test__fixtfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 52 | ||
| 53 | test__fixtfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 54 | test__fixtfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 55 | test__fixtfti(0x1.0000000000000p+63, 0x8000000000000000); | |
| 56 | test__fixtfti(0x1.0000000000001p+63, 0x8000000000000800); | |
| 57 | ||
| 58 | test__fixtfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000); | |
| 59 | test__fixtfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000); | |
| 60 | test__fixtfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 61 | ||
| 62 | test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 63 | test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128)); | |
| 64 | ||
| 65 | test__fixtfti(math.f128_max, math.maxInt(i128)); | |
| 66 | } |
std/special/compiler_rt/index.zig+10| ... | ... | @@ -52,6 +52,16 @@ comptime { |
| 52 | 52 | @export("__fixunstfdi", @import("fixunstfdi.zig").__fixunstfdi, linkage); |
| 53 | 53 | @export("__fixunstfti", @import("fixunstfti.zig").__fixunstfti, linkage); |
| 54 | 54 | |
| 55 | @export("__fixdfdi", @import("fixdfdi.zig").__fixdfdi, linkage); | |
| 56 | @export("__fixdfsi", @import("fixdfsi.zig").__fixdfsi, linkage); | |
| 57 | @export("__fixdfti", @import("fixdfti.zig").__fixdfti, linkage); | |
| 58 | @export("__fixsfdi", @import("fixsfdi.zig").__fixsfdi, linkage); | |
| 59 | @export("__fixsfsi", @import("fixsfsi.zig").__fixsfsi, linkage); | |
| 60 | @export("__fixsfti", @import("fixsfti.zig").__fixsfti, linkage); | |
| 61 | @export("__fixtfdi", @import("fixtfdi.zig").__fixtfdi, linkage); | |
| 62 | @export("__fixtfsi", @import("fixtfsi.zig").__fixtfsi, linkage); | |
| 63 | @export("__fixtfti", @import("fixtfti.zig").__fixtfti, linkage); | |
| 64 | ||
| 55 | 65 | @export("__udivmoddi4", @import("udivmoddi4.zig").__udivmoddi4, linkage); |
| 56 | 66 | |
| 57 | 67 | @export("__udivsi3", __udivsi3, linkage); |