From 4615ed5ea003516c8235728ac3f5f0ee2ccea8a7 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 22 Mar 2019 14:56:03 -0400 Subject: float literals now parse using musl's 128 bit float code fixes float literals not having 128 bit precision --- src/bigfloat.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/bigfloat.cpp') diff --git a/src/bigfloat.cpp b/src/bigfloat.cpp index cc442fa3b7..d746f1b68f 100644 --- a/src/bigfloat.cpp +++ b/src/bigfloat.cpp @@ -9,6 +9,7 @@ #include "bigint.hpp" #include "buffer.hpp" #include "softfloat.hpp" +#include "parse_f128.h" #include #include #include @@ -65,22 +66,18 @@ void bigfloat_init_bigint(BigFloat *dest, const BigInt *op) { } } -int bigfloat_init_buf_base10(BigFloat *dest, const uint8_t *buf_ptr, size_t buf_len) { +Error bigfloat_init_buf(BigFloat *dest, const uint8_t *buf_ptr, size_t buf_len) { char *str_begin = (char *)buf_ptr; char *str_end; errno = 0; - double value = strtod(str_begin, &str_end); // TODO actual f128 parsing + dest->value = parse_f128(str_begin, &str_end); if (errno) { return ErrorOverflow; } - float64_t value_f64; - memcpy(&value_f64, &value, sizeof(double)); - f64_to_f128M(value_f64, &dest->value); - assert(str_end <= ((char*)buf_ptr) + buf_len); - return 0; + return ErrorNone; } void bigfloat_add(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) { -- cgit v1.2.3