ianmackenzie/elm-float-extra/1.0.1

NOTE: the latest version is 1.1.0

Float.Extra

Convenience functions for working with Float values. Examples assume that this module has been imported using:

import Float.Extra as Float
equalWithin : Float -> Float -> Float -> Bool

Check if two values are equal within a given tolerance.

Float.equalWithin 1e-6 1.9999 2.0001
--> False


Float.equalWithin 1e-3 1.9999 2.0001
--> True
interpolateFrom : Float -> Float -> Float -> Float

Interpolate from the first value to the second, based on a parameter that ranges from zero to one. Passing a parameter value of zero will return the start value and passing a parameter value of one will return the end value.

Float.interpolateFrom 5 10 0
--> 5


Float.interpolateFrom 5 10 1
--> 10


Float.interpolateFrom 5 10 0.6
--> 8

The end value can be less than the start value:

Float.interpolateFrom 10 5 0.1
--> 9.5

Parameter values less than zero or greater than one can be used to extrapolate:

Float.interpolateFrom 5 10 1.5
--> 12.5


Float.interpolateFrom 5 10 -0.5
--> 2.5


Float.interpolateFrom 10 5 -0.2
--> 11