Summary

OS X / PowerPC failing test: remainder return -0.0

Metadata

Description

I recently added CHICKEN 5.3.0 to my package manager for OS X Tiger/PowerPC and Leopard/PowerPC: https://github.com/cellularmitosis/leopard.sh/commit/192014b920692434337783199742ceb217694f27

When I ran the tests, there was only one failure:

 (FAIL) remainder: flo/flo: expected 0.0 but got -0.0

I also verified it by hand:

 $ csi
 CHICKEN
 (c) 2008-2021, The CHICKEN Team
 (c) 2000-2007, Felix L. Winkelmann
 Version 5.3.0 (rev e31bbee5)
 macosx-unix-gnu-ppc [ 32bit dload ]
 
 Type ,? for help.
 #;1> (remainder 1.0 1.0)
 -0.0
 #;2> 

Thanks for all of your work on CHICKEN!

Changes and comments

[2023-02-06 09:03:01 UTC] cellularmitosis wrote:

Interestingly, 0.0 and -0.0 compare equal, so I'm not sure if this can actually cause a problem.

 #;1> (= 0.0 -0.0)
 #t

[2023-02-06 09:09:20 UTC] sjamaan wrote:

It shouldn't cause a problem in practice, I think. For dividing flonums we rely on the libc modf() function which is according to the standard is supposed to return the same sign as its input.

Perhaps you can test in a simple C function what modf(1.0, &x) returns and what it stores in x?

[2023-02-07 06:13:34 UTC] cellularmitosis wrote:

Surprisingly, `modf(1.0, &x)` puts 0.000000 in x.

[2023-02-07 06:13:34 UTC] cellularmitosis wrote:

1675746834658080

[2023-02-07 08:25:25 UTC] sjamaan wrote:

Since I don't have access to a PPC machine anymore, I'm afraid you're on your own for debugging this. Perhaps you can add some printfs to `C_s_a_i_remainder` in `runtime.c`. It's the most-indented code for flonums - check what the values of `dx`, `dy` and `tmp` are, and what the result is of the calculation it does in the call to `C_flonum`, i.e. `dx - tmp * dy`.

[2023-02-09 00:31:05 UTC] cellularmitosis wrote:

thanks for the pointers!