Hi Damian -

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).

The issue is what happens if x is negative, for example.

Thanks,

-michael

On 5/23/15, 11:00 AM, "Damian McGuckin" <[email protected]> wrote:

>
>Extracting a bit of code:
>
>   /* Computes the mod operator on the two numbers, defined as
>      ``mod(x,y) = x - y * floor(x / y)``.
>
>      The return value has the same type as `x`.
>   */
>   proc mod(x: real(?w), y: real(w)): real(w) {
>     // This codes up the standard definition, according to Wikipedia.
>     // Is there a more efficient implementation for reals?
>     return x - y*floor(x/y);
>   }
>
>Using a Wikipedia reference in intriguing. They quote a reference
>from Knuth as the source of the slgorithm.
>
>Anyway, the above is basically
>
>       n = floor(x/y)
>       return x - y * n
>
>I think 'floor' is really just
>
>       Directed Rounding toward negative infinity
>
>Both the C99 and D implementations, both of which are called 'fmod' and
>rely on the ISO specification, use
>
>       Directed Rounding - Tied Away From Zero
>
>Is there a good reason for Chapel to be different? I do note that the ISO
>document does not mandate the rounding mode although I should go back and
>check and see if there are updates. While it is a big ask to argue
>against 
>the ideas of Donald Knuth, nobody has really run with his idea of using
>'floor' as the basis for the computation of 'n' above, But again, why be
>different.
>
>There is also a 'REM' function (C99=remainder) in the ISO document which
>does mandate the use in the algorithm of the rounding mode as.
>
>       Round - Tied to Even
>
>Both C99 and D have this. Chapel does not.
>
>Regards - 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
>
>--------------------------------------------------------------------------
>----
>One dashboard for servers and applications across Physical-Virtual-Cloud
>Widest out-of-the-box monitoring support with 50+ applications
>Performance metrics, stats and reports that give you Actionable Insights
>Deep dive visibility with transaction tracing using APM Insight.
>http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
>_______________________________________________
>Chapel-users mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/chapel-users


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to