Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inaccurate log10 #1765

Open
librasteve opened this issue Aug 16, 2023 · 2 comments
Open

Inaccurate log10 #1765

librasteve opened this issue Aug 16, 2023 · 2 comments

Comments

@librasteve
Copy link

librasteve commented Aug 16, 2023

Expected Behaviour

log10(1000); #3 (Rat)

Actual Behaviour

log10(1000); #2.9999999999999996 (Num)

Rationale

raku is proud to handle decimals (and other rationals) in a way that avoids irrational results (geddit?)

python handles this "right"
https://gist.github.com/librasteve/fc2999c28654d219876c537abf554524

so does C
https://www.netlib.org/fdlibm/e_log10.c

Change Needed

looks like this:

log(x);

could maybe add new OP something like this:

            OP(log10_n): {
                MVMnum64 x = GET_REG(cur_op, 2).n64;
                GET_REG(cur_op, 0).n64 =
#ifdef MVM_HAS_SUBSTANDARD_LOG
                    x < 0 ? MVM_num_nan(tc) :
#endif
                    log10(x);
                cur_op += 4;
                goto NEXT;
            }
  • that is MoarVM is anyway using C operators - so why not use the specific one intended?
  • would need to back out and repoint the higher up bit of code that converts a log10 raku op to a log MoarVM OP
  • maybe there are other Rat oriented raku math operators to consider - ie. log2
@vushu
Copy link
Contributor

vushu commented Nov 4, 2023

@librasteve have you tried log(1000, 10) ?

@librasteve
Copy link
Author

librasteve commented Nov 4, 2023

[3] > log(1000,10) #2.9999999999999996

same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants