strconv: remove an assert for now

pull/4195/head
Alexander Medvednikov 2020-04-02 14:26:35 +02:00
parent 5b53b3d7e3
commit be327962d3
1 changed files with 11 additions and 10 deletions

View File

@ -1,6 +1,6 @@
/********************************************************************** /**********************************************************************
* *
* f32/f64 to string utilities * f32/f64 to string utilities
* *
* Copyright (c) 2019-2020 Dario Deledda. All rights reserved. * Copyright (c) 2019-2020 Dario Deledda. All rights reserved.
* Use of this source code is governed by an MIT license * Use of this source code is governed by an MIT license
@ -9,11 +9,11 @@
* This file contains the f32/f64 to string utilities functions * This file contains the f32/f64 to string utilities functions
* *
* These functions are based on the work of: * These functions are based on the work of:
* Publication:PLDI 2018: Proceedings of the 39th ACM SIGPLAN * Publication:PLDI 2018: Proceedings of the 39th ACM SIGPLAN
* Conference on Programming Language Design and ImplementationJune 2018 * Conference on Programming Language Design and ImplementationJune 2018
* Pages 270282 https://doi.org/10.1145/3192366.3192369 * Pages 270282 https://doi.org/10.1145/3192366.3192369
* *
* inspired by the Go version here: * inspired by the Go version here:
* https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea * https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea
* *
**********************************************************************/ **********************************************************************/
@ -83,7 +83,7 @@ fn decimal_len_32(u u32) int {
// (9 digits are sufficient for round-tripping.) // (9 digits are sufficient for round-tripping.)
// This benchmarked faster than the log2 approach used for u64. // This benchmarked faster than the log2 approach used for u64.
assert1(u < 1000000000, "too big") assert1(u < 1000000000, "too big")
if u >= 100000000 { return 9 } if u >= 100000000 { return 9 }
else if u >= 10000000 { return 8 } else if u >= 10000000 { return 8 }
else if u >= 1000000 { return 7 } else if u >= 1000000 { return 7 }
@ -96,7 +96,8 @@ fn decimal_len_32(u u32) int {
} }
fn mul_shift_32(m u32, mul u64, ishift int) u32 { fn mul_shift_32(m u32, mul u64, ishift int) u32 {
assert ishift > 32 // QTODO
//assert ishift > 32
hi, lo := bits.mul_64(u64(m), mul) hi, lo := bits.mul_64(u64(m), mul)
shifted_sum := (lo >> u64(ishift)) + (hi << u64(64-ishift)) shifted_sum := (lo >> u64(ishift)) + (hi << u64(64-ishift))
@ -115,7 +116,7 @@ fn mul_pow5_div_pow2(m u32, i u32, j int) u32 {
fn pow5_factor_32(i_v u32) u32 { fn pow5_factor_32(i_v u32) u32 {
mut v := i_v mut v := i_v
for n := u32(0); ; n++ { for n := u32(0); ; n++ {
q := v/5 q := v/5
r := v%5 r := v%5
if r != 0 { if r != 0 {
return n return n
@ -235,7 +236,7 @@ pub fn f64_to_str_l(f f64) string {
// check for +inf -inf Nan // check for +inf -inf Nan
if s.len > 2 && (s[0] == `n` || s[1] == `i`) { if s.len > 2 && (s[0] == `n` || s[1] == `i`) {
return s return s
} }
m_sgn_flag := false m_sgn_flag := false
mut sgn := 1 mut sgn := 1
@ -289,7 +290,7 @@ pub fn f64_to_str_l(f f64) string {
// allocate exp+32 chars for the return string // allocate exp+32 chars for the return string
mut res := [`0`].repeat(exp+32) // TODO: Slow!! is there other possibilities to allocate this? mut res := [`0`].repeat(exp+32) // TODO: Slow!! is there other possibilities to allocate this?
mut r_i := 0 // result string buffer index mut r_i := 0 // result string buffer index
//println("s:${sgn} b:${b[0]} es:${exp_sgn} exp:${exp}") //println("s:${sgn} b:${b[0]} es:${exp_sgn} exp:${exp}")
if sgn == 1 { if sgn == 1 {
@ -328,7 +329,7 @@ pub fn f64_to_str_l(f f64) string {
} }
for b[i] != 0 { for b[i] != 0 {
res[r_i++] = b[i] res[r_i++] = b[i]
i++ i++
} }
} }
res[r_i] = 0 res[r_i] = 0