rpncalc/src/Util.elm

11 lines
308 B
Elm
Raw Normal View History

2018-03-15 17:40:44 +00:00
module Util exposing (..)
import Numerics exposing (Rational(..))
import BigInt exposing (BigInt(..))
floatToRatio : Int -> Float -> Rational
floatToRatio accuracy f =
let
acc = BigInt.fromInt accuracy
in
Numerics.over (f * Numerics.bigintToFloat acc |> floor |> BigInt.fromInt) acc