From d247ba4751d8189082849e114e3d4a6106b0d053 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 25 Feb 2018 15:09:16 +0000 Subject: Hexadecimal floats for "perfect values" 0h42f60000 == 123; use `bit_cast` in compiler --- src/integer128.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/integer128.cpp') diff --git a/src/integer128.cpp b/src/integer128.cpp index 583c67281..80f7e9cce 100644 --- a/src/integer128.cpp +++ b/src/integer128.cpp @@ -278,7 +278,7 @@ f64 u128_to_f64(u128 a) { return -((cast(f64)h * 18446744073709551616.0) + cast(f64)l); } i128 u128_to_i128(u128 a) { - return *cast(i128 *)&a; + return bit_cast(a); } @@ -306,7 +306,7 @@ f64 i128_to_f64(i128 a) { return -((cast(f64)h * 18446744073709551616.0) + cast(f64)l); } u128 i128_to_u128(i128 a) { - return *cast(u128 *)&a; + return bit_cast(a); } @@ -335,7 +335,7 @@ String i128_to_string(i128 a, char *out_buf, isize out_buf_len) { a = i128_neg(a); } - u128 v = *cast(u128 *)&a; + u128 v = bit_cast(a); u128 b = u128_from_u64(10);; while (u128_ge(v, b)) { buf[--i] = gb__num_to_char_table[u128_to_i64(u128_mod(v, b))]; @@ -692,9 +692,9 @@ void i128_divide(i128 a, i128 b, i128 *quo_, i128 *rem_) { irem = i128_from_i64(r); } else if (a.hi > 0 || b.hi > 0) { u128 q, r = {0}; - u128_divide(*cast(u128 *)&a, *cast(u128 *)&b, &q, &r); - iquo = *cast(i128 *)&q; - irem = *cast(i128 *)&r; + u128_divide(bit_cast(a), bit_cast(b), &q, &r); + iquo = bit_cast(q); + irem = bit_cast(r); } else if (i128_eq(b, I128_ZERO)) { iquo = i128_from_u64(a.lo/b.lo); } else { -- cgit v1.2.3