E.g: Element.modular 16 1.25 1 yields 16 instead of 20
E.g: Element.modular 16 1.25 2 yields 20 instead of 25
E.g: Element.modular 16 1.25 3 yields 25 instead of 31.25
and so on
Expected behavior
With the above in mind, and with a base, a ratio, and a multiplier:
Only 0 for the multiplier should yield the base number unchanged. (16 in this example).
Element.modular 16 1.25 1 should yield 20 and not 16. (try 16*1.25*1 in a calc)
Versions
Elm Version: 0.19.1
Elm UI Version 1.1.8
Solution
The issue is caused by using the -1 in the function definition. The fix is super easy and saves an else if that's not needed because the negative multiplier suffice:
modular : Float -> Float -> Int -> Float
modular normal ratio rescale =
if rescale == 0 then
normal
else
normal * ratio ^ toFloat rescale
Hi and thank you for elm-ui π
Element.modular formula is off because of the use of
-1
.Current behavior
Each multiplier returns what the previous should:
Element.modular 16 1.25 1
yields16
instead of20
Element.modular 16 1.25 2
yields20
instead of25
Element.modular 16 1.25 3
yields25
instead of31.25
Expected behavior
With the above in mind, and with a
base
, aratio
, and amultiplier
:0
for themultiplier
should yield thebase
number unchanged. (16
in this example).Element.modular 16 1.25 1
should yield20
and not16
. (try16*1.25*1
in a calc)Versions
Solution
The issue is caused by using the
-1
in the function definition. The fix is super easy and saves anelse if
that's not needed because the negativemultiplier
suffice:I put a demo of this on Ellie: https://ellie-app.com/gm2bfCbKdtZa1
Also refer to these to corroborate my findings:
Docs Need Updating too
Contextually, the documentation examples should be fixed/updated as well, to match the corrected formula. Also, to add partial application to the (scaled) examples. Ref. https://github.com/mdgriffith/elm-ui/issues/36
Cheers :)
ps: if needed I would gladly do the PR(s) π―