1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.gen.c: support T.typ - an int for the type index of the generic type T (#11175)

This commit is contained in:
Delyan Angelov
2021-08-14 08:48:25 +03:00
committed by GitHub
parent fb3671107e
commit 900c37aa65
8 changed files with 142 additions and 46 deletions

View File

@@ -186,50 +186,10 @@ const (
]
)
fn tolerance(a f64, b f64, tol f64) bool {
mut ee := tol
// Multiplying by ee here can underflow denormal values to zero.
// Check a==b so that at least if a and b are small and identical
// we say they match.
if a == b {
return true
}
mut d := a - b
if d < 0 {
d = -d
}
// note: b is correct (expected) value, a is actual value.
// make error tolerance a fraction of b, not a.
if b != 0 {
ee = ee * b
if ee < 0 {
ee = -ee
}
}
return d < ee
}
fn close(a f64, b f64) bool {
return tolerance(a, b, 1e-14)
}
fn veryclose(a f64, b f64) bool {
return tolerance(a, b, 4e-16)
}
fn soclose(a f64, b f64, e f64) bool {
return tolerance(a, b, e)
}
fn alike(a f64, b f64) bool {
if is_nan(a) && is_nan(b) {
return true
} else if a == b {
return signbit(a) == signbit(b)
}
return false
}
fn test_nan() {
nan_f64 := nan()
assert nan_f64 != nan_f64