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

Problem with sqrt #54

Closed
iyersathya opened this issue Feb 2, 2016 · 7 comments
Closed

Problem with sqrt #54

iyersathya opened this issue Feb 2, 2016 · 7 comments
Labels

Comments

@iyersathya
Copy link

Hello Udo,
Thank you producing such a useful library.
I came across an issue where sqrt function is getting stuck in this loop.
do {
ixPrev = ix;
ix = ix.add(n.divide(ix)).shiftRight(1);
// Give other threads a chance to work;
Thread.yield();
} while (ix.compareTo(ixPrev) != 0);

I ended up overriding the function with java's sqrtj implementation.

@uklimaschewski
Copy link
Collaborator

Thank you for the feedback, can you give me an example expression that reproduces this?

@iyersathya
Copy link
Author

please try SRRT(24)

@iyersathya
Copy link
Author

My mistake, I think it will only work on perfect squares.

@squeek502
Copy link
Contributor

SQRT(24) seems to work fine for me. Adding

assertEquals("4.8989794", new Expression("SQRT(24)").eval().toPlainString());

to the existing SQRT tests still passes.

@uklimaschewski
Copy link
Collaborator

What kind of Java and machine are you using? I tested in on a 64bit Intel Windows machine, without problem.

@iyersathya
Copy link
Author

I am using mac pro (2.6 GHz Intel Core i7), Yes running junit tests on native machine works fine.
I am using Android's emulator on genymotion (ARM hypervisor), I also tried it on Samsung Galaxy 7 note ( ARM) and it gets stuck in a while loop.
Since its android , it is running on Dalvik VM, and the code is Dex'ed Dalvik code.
do { ixPrev = ix; ix = ix.add(n.divide(ix)).shiftRight(1); // Give other threads a chance to work; Thread.yield(); } while (ix.compareTo(ixPrev) != 0);
here's the loop result.
loop 1:
ixPrev=ix=4
ix = 5
loop 2:
ixPrev = ix = 5;
ix = 4
loop 3:
ixPrev=ix=4
ix=5

Hope that helps.

uklimaschewski referenced this issue Mar 21, 2016
- Making declared functions,variables as well as operators case
insensitive
@uklimaschewski
Copy link
Collaborator

I have now tried out 4 different Android devices and 2 different emulator configurations, but I was unable to reproduce. I'll close this issue for now. If there is a way how I can reproduce this bug here, let me know.

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

No branches or pull requests

3 participants