On Tue, 26 May 2015, Michael Ferguson wrote:
> So, are you saying that we should either:
>
> 1) use 'trunc' instead of 'floor' in the mod for reals function, or
> 2) call C's fmod function to implement mod for reals?
>
> I (personally) think that either of these are reasonable options
> (and I'd vote for (2), but (1) would be very easy to do now).
Probably the furmer.
> The issue is what happens if x is negative, for example.
See below.
Other issues,
a) the integral and floating performance should be consistent which they
obviously are in Chapel.
b) (I am guessing), but I would have thought that fmod was something that
an aggressively optimizing compilers inline things and not call 'fmod'
I am not an expert on rounding, but As far as I can tell, that is the only
practical difference between the two. In C99-speak, one would
assert(fmod(-9.5, 2.1) == -1.1) // to some level of accuracy
assert(fmod(-9.5, -2.1) == -1.1) // to some level of accuracy
Chapel instead returns -1.1 and 1.1 respectively. I would have thought
that being different is not an option.
Reading the ever-so exciting standards documents gives you little help.
Do (1) now as you suggest, and eventually, check out explicitly with an
email to the Julia and D lists, how say they do it, and check how some
other production C/C++ compilers do it. I would also check the latest
papers/drafts/discussion-listsof the new C++ and Fortran standards, both
of which I believe are still open, e.g. while on rounding but not on our
specific 'modulo' topic,
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4448.html
- Damian
Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer
------------------------------------------------------------------------------
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users