[chuck-users] Integer divisions

Robert Poor rdpoor at gmail.com
Tue Dec 15 08:07:15 EST 2009


You've forced my hand.  Would you be interested in a rational number  
package (y'know, where numbers are represented as a fraction)?  I  
wrote one "by accident" when I thought that roundoff was causing a  
problem.  It wasn't, but I have a cleanly written and tested Rational  
class if anyone could use it.

Comes with a test suite.  Has a stable float-to-rational conversion  
algorithm where you get to specify the maximum denominator.  It even  
has a to_string() routine.

If someone tells me where to put the code, I'm happy to send it.

Yours in attempted helpfulness...

- Rob

On 15 Dec 2009, at 02:29, Hans Aberg wrote:

> I find the integer divisions C rule is problematic when working with  
> intervals. Suppose I have [8/7, 7/6, 7/6, 8/7] and implement it as
>  [Interval.r(8/7), Interval.r(7/6), Interval.r(7/6), Interval.r(8/7)]
> Then this is the same as:
>  [Interval.r(0), Interval.r(0), Interval.r(0), Interval.r(0)]
> One has to add ".0" one of the numerator/denominator:
>  [Interval.r(8.0/7), Interval.r(7.0/6), Interval.r(7.0/6),  
> Interval.r(8.0/7)],
> One possible rule might be converting 32-bit int to 64-bit floats,  
> and then only back to int when needed. The question if it then  
> affects some ChucK legacy code.
>  Hans
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

More information about the chuck-users mailing list