core icon indicating copy to clipboard operation
core copied to clipboard

Use native log10 for logBase with base of 10

Open richyliu opened this issue 6 years ago • 4 comments

Current logBase implementation is not precise enough. For example: logBase 10 100 == 2 but logBase 10 1000 /= 3.

The proposed change is to use a separate native Javascript log10 function for logs with base 10.

This would close #1048

richyliu avatar Oct 23 '19 04:10 richyliu

Would it make sense to special case also Math.log2 and Math.log1p?

gampleman avatar Nov 11 '20 13:11 gampleman

This seems to fail to compile, due to using the == operator in Base.elm, where it is defined:

> elm make
Detected problems in 1 module.
-- UNKNOWN OPERATOR --------------------------------------------- src/Basics.elm

I do not recognize the (==) operator.

621|   if base == 10 then
               ^^
Is there an `import` and `exposing` entry for it?

It needs to be done like this:

if eq base 10 then

rupertlssmith avatar Feb 18 '22 12:02 rupertlssmith

I would like to add this PR to elm-janitor: https://github.com/elm-janitor/manifesto/blob/master/README.md

Would you be able to fix the compile error to get this patch over the line?

rupertlssmith avatar Feb 18 '22 13:02 rupertlssmith

I have another suggestion, which is to extend the test over a larger range of powers of 10. This will test the entire range of a double precision float:

        log10Tests =
          describe "Check accuracy of log base 10"
            (List.map
              (\i -> test ("logBase 10 " ++ (10^i |> toString)) <|
                \() -> Expect.equal (toFloat i) (logBase 10 (10^(toFloat i)))
              )
              (List.range -308 308)
            )

rupertlssmith avatar Feb 18 '22 13:02 rupertlssmith