| ... | ... | @@ -244,6 +244,10 @@ pub fn buf_print_u64(out_buf: []u8, x: u64) -> isize { |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | pub fn buf_print_f64(out_buf: []u8, x: f64, decimals: isize) -> isize { |
| 247 | const numExpBits = 11; |
| 248 | const numRawSigBits = 52; // not including implicit 1 bit |
| 249 | const expBias = 1023; |
| 250 | |
| 247 | 251 | var decs = decimals; |
| 248 | 252 | if (decs >= max_u64_base10_digits) { |
| 249 | 253 | decs = max_u64_base10_digits - 1; |
| ... | ... | @@ -277,8 +281,8 @@ pub fn buf_print_f64(out_buf: []u8, x: f64, decimals: isize) -> isize { |
| 277 | 281 | len += 1; |
| 278 | 282 | } |
| 279 | 283 | |
| 280 | | const rexponent: i64 = i64((bits >> 52) & ((1 << 11) - 1)); |
| 281 | | const exponent = rexponent - 1023 - 52; |
| 284 | const rexponent: i64 = i64((bits >> numRawSigBits) & ((1 << numExpBits) - 1)); |
| 285 | const exponent = rexponent - expBias - numRawSigBits; |
| 282 | 286 | |
| 283 | 287 | if (rexponent == 0) { |
| 284 | 288 | buf[len] = '0'; |
| ... | ... | @@ -287,12 +291,12 @@ pub fn buf_print_f64(out_buf: []u8, x: f64, decimals: isize) -> isize { |
| 287 | 291 | return len; |
| 288 | 292 | } |
| 289 | 293 | |
| 290 | | const sig = (bits & ((1 << 52) - 1)) | (1 << 52); |
| 294 | const sig = (bits & ((1 << numRawSigBits) - 1)) | (1 << numRawSigBits); |
| 291 | 295 | |
| 292 | 296 | if (exponent >= 0) { |
| 293 | 297 | // number is an integer |
| 294 | 298 | |
| 295 | | if (exponent >= 11) { |
| 299 | if (exponent >= 64 - 53) { |
| 296 | 300 | // use XeX form |
| 297 | 301 | |
| 298 | 302 | // TODO support printing large floats |