Fix issue #72 - 128-bit literal corruption

This commit is contained in:
Ginger Bill
2017-06-14 14:58:48 +01:00
parent c3b510c2d9
commit a134307dcd
2 changed files with 14 additions and 2 deletions

View File

@@ -76,7 +76,7 @@ ExactValue exact_value_i128(i128 i) {
}
ExactValue exact_value_u128(u128 i) {
ExactValue result = {ExactValue_Integer};
result.value_integer = *cast(i128 *)&i;
result.value_integer = u128_to_i128(i);
return result;
}
@@ -101,7 +101,7 @@ ExactValue exact_value_pointer(i64 ptr) {
ExactValue exact_value_integer_from_string(String string) {
return exact_value_i128(i128_from_string(string));
return exact_value_u128(u128_from_string(string));
}
f64 float_from_string(String string) {

View File

@@ -40,10 +40,12 @@ i128 i128_from_string(String string);
u64 u128_to_u64(u128 a);
i64 u128_to_i64(u128 a);
f64 u128_to_f64(u128 a);
i128 u128_to_i128(u128 a);
u64 i128_to_u64(i128 a);
i64 i128_to_i64(i128 a);
f64 i128_to_f64(i128 a);
u128 i128_to_u128(i128 a);
String u128_to_string(u128 a, char *buf, isize len);
String i128_to_string(i128 a, char *buf, isize len);
@@ -270,6 +272,12 @@ 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;
}
u64 i128_to_u64(i128 a) {
return (a.lo&BIT128_U64_BITS62) | (a.hi&BIT128_U64_HIGHBIT);
@@ -292,6 +300,10 @@ 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;
}
String u128_to_string(u128 v, char *out_buf, isize out_buf_len) {