-
Notifications
You must be signed in to change notification settings - Fork 49
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
Make day + fraction separation more robust #40
Conversation
jd2cal.c assumed that for any x, x-fmod(x, 1.0) returns a value not smaller than x. Due to rounding effects, this does not always need to be the case. Especially on i386, the result might be slightly smaller. Therefore, the code floor(x-fmod(x, 1.0)) is not guaranteed to return the same (expected) value on all platforms. Since we know, that x-fmod(x,1.0) is close to an int, we just replace this by a normal rounding. This is done by adding 0.5, to stay away from such modern stuff like rint, which hopefully makes the code acceptable to old-style programmers from SOFA as well ;-)
Great! This definitely needs to go upstream to SOFA too... Not sure what the process is; cc @scottransom, @eteq. For ease of reference, let me copy your example calls from astropy/astropy#5425 (comment)
|
@eteq, @scottransom, could I ask for a comment here and in #41? I could add a bit on the README and/or contact the SOFA team. What would you propose? |
@olebole The usual process is:
I've been waiting to hear from @scottransom, as he has often conveyed it on, but he might be busy. If we haven't heard from him, by, say, Tuesday (it's been a holiday in the US since ~Wed), I'll try some of the other channels. But definitely want to get this fixed and into astropy by the next release (~5 weeks), so if we get stuck on waiting for SOFA we might just merge. |
Hi All... sorry for the delay. Yes, I've been doing US holiday and avoiding email. I'll send this to the SOFA board members and do a bit of testing myself. I suspect that it will go into the next SOFA release (assuming that it has no strange side-effects). |
Ok, great, thanks @scottransom! Let us know as soon as you know here if it looks like it will go in - if so we can go ahead and merge this after updating the README |
Quick update on this. This is a confirmed bug in SOFA and we are working on getting a new release out with a bug fix. The fix will be slightly different than the one proposed here as we will likely use the "dnint" macro in sofam.h which replicates the behavior of the original Fortran function ANINT which was used in SLALIB. If anyone has specific examples as to how the bug could show up and under what circumstances (and how likely that was), we would like to put that on the SOFA website when we release a new version. Thanks! |
@scottransom Here is an example for erfa (in Python). Translated to C:
This problem appears under i386 with the 387 FPU, with
while it should be
|
@scottransom - out of curiosity, do you have a sense of when the next SOFA release will be? Basically I'm wondering if we should merge this vs waiting for the new SOFA (if it'll be soon). Also, a side note (just for my own curiosity): @olebole, do you actually have a 386 w/387, or do you have an emulator of some kind? |
@eteq: I just run it in a 32-bit Debian chroot on a very recent CPU. What we call "386" is actually a 686; everything below Pentium Pro doesn't work anymore. |
SOFA has already acknowledged that #41 is a good fix and we have a version for testing already. So I think that is a good plan. I suspect a new release quite soon. |
Supposedly this is included in 12c, which we should rebase on (#44) |
Merging this so as to keep a record, but it well be superceded shortly by a PR to upgrade to the latest SOFA |
This should fix astropy/astropy#5425.
The code behaved diferently depending whether one uses the flags
-O2 -fcaller-save
(which gives correct results) or-O2 -fno-callers-save
(which gives wrong results).