mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
isApproxEq function
This commit is contained in:
parent
9a3340950e
commit
4499f8c6f4
86 changed files with 583 additions and 542 deletions
|
@ -48,6 +48,7 @@ interface Num
|
|||
isLte,
|
||||
isGt,
|
||||
isGte,
|
||||
isApproxEq,
|
||||
sin,
|
||||
cos,
|
||||
tan,
|
||||
|
@ -661,6 +662,22 @@ isLte : Num a, Num a -> Bool
|
|||
## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).)
|
||||
isGte : Num a, Num a -> Bool
|
||||
|
||||
## Returns `Bool.true` if the first number and second number are within a specific threshold
|
||||
##
|
||||
## A specific relative and absolute tolerance can be provided to change the threshold
|
||||
##
|
||||
## If either argument is [*NaN*](Num.isNaN), returns `Bool.false` no matter what. (*NaN*
|
||||
## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).)
|
||||
isApproxEq : Frac a, Frac a, { rtol ? Frac a, atol ? Frac a } -> Bool
|
||||
isApproxEq = \value, refValue, { rtol ? 0.00001, atol ? 0.00000001 } -> value
|
||||
<= refValue
|
||||
&& value
|
||||
>= refValue
|
||||
|| Num.absDiff value refValue
|
||||
<= atol
|
||||
+ rtol
|
||||
* Num.abs refValue
|
||||
|
||||
## Returns `Bool.true` if the number is `0`, and `Bool.false` otherwise.
|
||||
isZero : Num a -> Bool
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue