authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-18 12:43:48-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-18 12:43:48-04:00
loge1c225694df6b99b7541a99a59def52a5886c665
treeb87d5e121d02e1179851a56a409229b6e75b5af4
parent3a762e5a8d7fbea9fad5553d11558e47b44e872a

cast between __float128 and double to fix build in some places


1 files changed, 9 insertions(+), 9 deletions(-)

src/bigfloat.cpp+9-9
......@@ -5,7 +5,7 @@
55 * See http://opensource.org/licenses/MIT
66 */
77
8// TODO in this file we cast between __float128 and long double
8// TODO in this file we cast between __float128 and double
99// and lose precision. for now this is going to be a bug in
1010// the compiler because I don't want to add a dependency on libquadmath.
1111// 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_
5151 char *str_begin = (char *)buf_ptr;
5252 char *str_end;
5353 errno = 0;
54 dest->value = (__float128)strtold(str_begin, &str_end);
54 dest->value = (__float128)strtod(str_begin, &str_end);
5555 if (errno) {
5656 return ErrorOverflow;
5757 }
......@@ -82,26 +82,26 @@ void bigfloat_div(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) {
8282void bigfloat_div_trunc(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) {
8383 dest->value = op1->value / op2->value;
8484 if (dest->value >= 0.0) {
85 dest->value = (__float128)floorl((long double)dest->value);
85 dest->value = (__float128)floor((double)dest->value);
8686 } else {
87 dest->value = (__float128)ceill((long double)dest->value);
87 dest->value = (__float128)ceil((double)dest->value);
8888 }
8989}
9090
9191void 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));
9393}
9494
9595void 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);
9797}
9898
9999void 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);
101101}
102102
103103void 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);
105105}
106106
107107Cmp bigfloat_cmp(const BigFloat *op1, const BigFloat *op2) {
......@@ -164,5 +164,5 @@ Cmp bigfloat_cmp_zero(const BigFloat *bigfloat) {
164164}
165165
166166bool 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;
168168}