Summary

float and double foreign-lambdas return wrong values

Metadata

Attachments

Description

Sometimes I've had better luck with double, but now I wrote an egg just to demonstrate this, and it's failing pretty consistently for both float and double, at least for me, on 64-bit Arch Linux.

Version 4.8.0.3 (stability/4.8.0) (rev 091c3d9)

#;1> (use getafloat)

loading /usr/lib/chicken/6/getafloat.import.so ...
loading /usr/lib/chicken/6/getafloat.so ...

#;2> (get-float) get_float returning 1368477568.000000 38.0 #;3> (get-double) get_float returning 1368477622.402598 38.0 #;4> (get-int) 5 #;5> (get-pair) get_float returning 1368477696.000000 get_float returning 1368477696.000000 (38.0 . 38.0)

Changes and comments

[2013-05-13 22:47:16 UTC] ecloud attached getafloat.tgz (description=egg to demonstrate the bug)

[2013-05-13 23:14:31 UTC] ecloud changed status from new to closed

[2013-05-13 23:14:31 UTC] ecloud set resolution to invalid

[2013-05-13 23:14:31 UTC] ecloud wrote:

The solution is to declare the C function prototypes, e.g. declare them in a header and include it in the scm, or declare them inline. Despite the fact that the foreign-lambda looks like it declares the signature, chicken still assumes the return value will be an int unless it has the C function prototype. (This is still a bit of an annoyance, IMO.)

 (module getafloat *
    (import ...)
 #>
 #include "impl.h"
 <#
 ...
 )

See also https://lists.gnu.org/archive/html/chicken-users/2013-05/msg00045.html

[2013-05-13 23:17:05 UTC] ecloud wrote:

Or rather the C compiler assumes int.