| ... | @@ -5,7 +5,7 @@ | ... | @@ -5,7 +5,7 @@ |
| 5 | * See http://opensource.org/licenses/MIT | 5 | * See http://opensource.org/licenses/MIT |
| 6 | */ | 6 | */ |
| 7 | | 7 | |
| 8 | // TODO in this file we cast between __float128 and long double | 8 | // TODO in this file we cast between __float128 and double |
| 9 | // and lose precision. for now this is going to be a bug in | 9 | // and lose precision. for now this is going to be a bug in |
| 10 | // the compiler because I don't want to add a dependency on libquadmath. | 10 | // the compiler because I don't want to add a dependency on libquadmath. |
| 11 | // when we self host we can use zig's f128 and the problem is fixed. | 11 | // when we self host we can use zig's f128 and the problem is fixed. |
| ... | @@ -51,7 +51,7 @@ int bigfloat_init_buf_base10(BigFloat *dest, const uint8_t *buf_ptr, size_t buf_ | ... | @@ -51,7 +51,7 @@ int bigfloat_init_buf_base10(BigFloat *dest, const uint8_t *buf_ptr, size_t buf_ |
| 51 | char *str_begin = (char *)buf_ptr; | 51 | char *str_begin = (char *)buf_ptr; |
| 52 | char *str_end; | 52 | char *str_end; |
| 53 | errno = 0; | 53 | errno = 0; |
| 54 | dest->value = (__float128)strtold(str_begin, &str_end); | 54 | dest->value = (__float128)strtod(str_begin, &str_end); |
| 55 | if (errno) { | 55 | if (errno) { |
| 56 | return ErrorOverflow; | 56 | return ErrorOverflow; |
| 57 | } | 57 | } |
| ... | @@ -82,26 +82,26 @@ void bigfloat_div(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) { | ... | @@ -82,26 +82,26 @@ void bigfloat_div(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) { |
| 82 | void bigfloat_div_trunc(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) { | 82 | void bigfloat_div_trunc(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) { |
| 83 | dest->value = op1->value / op2->value; | 83 | dest->value = op1->value / op2->value; |
| 84 | if (dest->value >= 0.0) { | 84 | if (dest->value >= 0.0) { |
| 85 | dest->value = (__float128)floorl((long double)dest->value); | 85 | dest->value = (__float128)floor((double)dest->value); |
| 86 | } else { | 86 | } else { |
| 87 | dest->value = (__float128)ceill((long double)dest->value); | 87 | dest->value = (__float128)ceil((double)dest->value); |
| 88 | } | 88 | } |
| 89 | } | 89 | } |
| 90 | | 90 | |
| 91 | void bigfloat_div_floor(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) { | 91 | void bigfloat_div_floor(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) { |
| 92 | dest->value = (__float128)floorl((long double)(op1->value / op2->value)); | 92 | dest->value = (__float128)floor((double)(op1->value / op2->value)); |
| 93 | } | 93 | } |
| 94 | | 94 | |
| 95 | void bigfloat_rem(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) { | 95 | void bigfloat_rem(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) { |
| 96 | dest->value = (__float128)fmodl((long double)op1->value, (long double)op2->value); | 96 | dest->value = (__float128)fmod((double)op1->value, (double)op2->value); |
| 97 | } | 97 | } |
| 98 | | 98 | |
| 99 | void bigfloat_mod(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) { | 99 | void bigfloat_mod(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) { |
| 100 | dest->value = (__float128)fmodl(fmodl((long double)op1->value, (long double)op2->value) + (long double)op2->value, (long double)op2->value); | 100 | dest->value = (__float128)fmod(fmod((double)op1->value, (double)op2->value) + (double)op2->value, (double)op2->value); |
| 101 | } | 101 | } |
| 102 | | 102 | |
| 103 | void bigfloat_write_buf(Buf *buf, const BigFloat *op) { | 103 | void bigfloat_write_buf(Buf *buf, const BigFloat *op) { |
| 104 | buf_appendf(buf, "%Lf", (long double)op->value); | 104 | buf_appendf(buf, "%f", (double)op->value); |
| 105 | } | 105 | } |
| 106 | | 106 | |
| 107 | Cmp bigfloat_cmp(const BigFloat *op1, const BigFloat *op2) { | 107 | Cmp bigfloat_cmp(const BigFloat *op1, const BigFloat *op2) { |
| ... | @@ -164,5 +164,5 @@ Cmp bigfloat_cmp_zero(const BigFloat *bigfloat) { | ... | @@ -164,5 +164,5 @@ Cmp bigfloat_cmp_zero(const BigFloat *bigfloat) { |
| 164 | } | 164 | } |
| 165 | | 165 | |
| 166 | bool bigfloat_has_fraction(const BigFloat *bigfloat) { | 166 | bool bigfloat_has_fraction(const BigFloat *bigfloat) { |
| 167 | return ((__float128)floorl((long double)bigfloat->value)) != bigfloat->value; | 167 | return ((__float128)floor((double)bigfloat->value)) != bigfloat->value; |
| 168 | } | 168 | } |