mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: float1 == float2 uses machine epsilon by default
This commit is contained in:

committed by
Alexander Medvednikov

parent
21f9dc6b7c
commit
6d483c0a56
@ -29,6 +29,15 @@ pub fn ptr_str(ptr voidptr) string {
|
||||
pub fn (a f64) eq(b f64) bool {
|
||||
return C.fabs(a - b) <= C.DBL_EPSILON
|
||||
}
|
||||
pub fn (a f32) eq(b f32) bool {
|
||||
return C.fabsf(a - b) <= C.FLT_EPSILON
|
||||
}
|
||||
pub fn (a f64) eqbit(b f64) bool {
|
||||
return C.DEFAULT_EQUAL(a, b)
|
||||
}
|
||||
pub fn (a f32) eqbit(b f32) bool {
|
||||
return C.DEFAULT_EQUAL(a, b)
|
||||
}
|
||||
|
||||
// fn (nn i32) str() string {
|
||||
// return i
|
||||
|
@ -11,6 +11,20 @@ fn test_const() {
|
||||
assert u == 1 // make sure this works without the cast
|
||||
}
|
||||
|
||||
fn test_float_equal_operator() {
|
||||
mut a := f32(1)
|
||||
a += 0.000001
|
||||
a -= 0.000001
|
||||
assert a == 1
|
||||
assert !a.eqbit(1)
|
||||
|
||||
a = f64(1)
|
||||
a += 0.000001
|
||||
a -= 0.000001
|
||||
assert a == 1
|
||||
assert !a.eqbit(1)
|
||||
}
|
||||
|
||||
fn test_str_methods() {
|
||||
assert i8(1).str() == '1'
|
||||
assert i8(-1).str() == '-1'
|
||||
|
Reference in New Issue
Block a user