elm-ui icon indicating copy to clipboard operation
elm-ui copied to clipboard

Element.modular returns Float but Font.size requires Int

Open colinf opened this issue 7 years ago • 3 comments

There is a discrepancy between the docs and the implementation for use of Element.modular. The example in the docs is

scaled =
    Scale.modular 16 1.25

Font.size (scaled 4) -- 16 * 1.25 ^ (4 - 1) results in 31.25

But this fails as Font.size expects an Int rather than a Float.

colinf avatar Sep 28 '18 15:09 colinf

I think that changing teh return type will be a breaking change, so this isn't just going to be a bug fix as it would force a new version. Here is my workaround:

scaled : Int -> Int
scaled factor =
  let
    base = 16
      
  in
      
    if factor > 0 then
      base * 1.25^(toFloat(factor-1)) |> round
    else if factor == 0 then
      base
    else -- negative factor
      base * 1.25^(toFloat(factor)) |> round

jmedding avatar Jan 31 '19 05:01 jmedding

Why not just

scaled : Int -> Int
scaled factor =
    Element.modular 16 1.25 factor |> round

manofearth avatar May 18 '19 11:05 manofearth

I too had the same issue today. the bug it's in the docs, rather than the function.

this is what I used (with help from Manuel Baumann on slack):

scaled fs =
    Basics.round (Element.modular 16 1.25 fs)

As you can see, the example in the docs is using partial application but there's no mention of this, hence the confusion.

andreacfromtheapp avatar Jan 07 '22 20:01 andreacfromtheapp