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 @@...@@ -5,7 +5,7 @@
5 * See http://opensource.org/licenses/MIT5 * See http://opensource.org/licenses/MIT
6 */6 */
77
8// TODO in this file we cast between __float128 and long double8// TODO in this file we cast between __float128 and double
9// and lose precision. for now this is going to be a bug in9// 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) {
82void bigfloat_div_trunc(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) {82void 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}
9090
91void bigfloat_div_floor(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) {91void 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}
9494
95void bigfloat_rem(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) {95void 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}
9898
99void bigfloat_mod(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) {99void 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}
102102
103void bigfloat_write_buf(Buf *buf, const BigFloat *op) {103void 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}
106106
107Cmp bigfloat_cmp(const BigFloat *op1, const BigFloat *op2) {107Cmp 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}
165165
166bool bigfloat_has_fraction(const BigFloat *bigfloat) {166bool 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}