mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
strconv: fix assert .f64() == 0
This commit is contained in:
parent
b2538e83da
commit
0f01236e52
@ -936,3 +936,19 @@ fn test_index_any() {
|
||||
assert x.index_any('ef') == 4
|
||||
assert x.index_any('fe') == 4
|
||||
}
|
||||
|
||||
fn test_string_f64() {
|
||||
assert ''.f64() == 0
|
||||
assert '123'.f64() == 123
|
||||
assert '-123'.f64() == -123
|
||||
assert '-123.456'.f64() == -123.456
|
||||
}
|
||||
|
||||
const f32_epsilon = 0.0000000001
|
||||
|
||||
fn test_string_f32() {
|
||||
assert ''.f32() - 0 <= f32_epsilon
|
||||
assert '123'.f32() - 123 < f32_epsilon
|
||||
assert '-123'.f32() - (-123) < f32_epsilon
|
||||
assert '-123.456'.f32() - (-123.456) <= f32_epsilon
|
||||
}
|
||||
|
@ -78,9 +78,7 @@ fn sub96(s2 u32, s1 u32, s0 u32, d2 u32, d1 u32, d0 u32) (u32, u32, u32) {
|
||||
return r2, r1, r0
|
||||
}
|
||||
|
||||
/*
|
||||
Constants
|
||||
*/
|
||||
// Constants
|
||||
|
||||
pub const (
|
||||
//
|
||||
@ -118,9 +116,7 @@ pub const (
|
||||
c_ten = u32(10)
|
||||
)
|
||||
|
||||
/*
|
||||
Utility
|
||||
*/
|
||||
// Utility functions
|
||||
|
||||
// NOTE: Modify these if working with non-ASCII encoding
|
||||
fn is_digit(x byte) bool {
|
||||
@ -135,10 +131,6 @@ fn is_exp(x byte) bool {
|
||||
return (x == `E` || x == `e`) == true
|
||||
}
|
||||
|
||||
/*
|
||||
Support struct
|
||||
*/
|
||||
|
||||
/*
|
||||
String parser
|
||||
NOTE: #TOFIX need one char after the last char of the number
|
||||
@ -408,12 +400,13 @@ fn converter(mut pn PrepNumber) u64 {
|
||||
return result
|
||||
}
|
||||
|
||||
/*
|
||||
Public functions
|
||||
*/
|
||||
// Public functions
|
||||
|
||||
// atof64 return a f64 from a string doing a parsing operation
|
||||
pub fn atof64(s string) f64 {
|
||||
if s.len == 0 {
|
||||
return 0
|
||||
}
|
||||
mut pn := PrepNumber{}
|
||||
mut res_parsing := 0
|
||||
mut res := Float64u{}
|
||||
|
Loading…
Reference in New Issue
Block a user