newLISP Fan Club

Forum => Anything else we might add? => Topic started by: sjain59 on March 09, 2024, 10:33:24 PM

Title: v10.76 ffi interface does not read 32 bit float
Post by: sjain59 on March 09, 2024, 10:33:24 PM
There is a library, called exodriver downloadable from 'labjack' which gives its library version (2.07) as a 32 bit float through it's function LJUSB_GetLibraryVersion().This I have verified by importing this function in another programming language.

But newLisp v10.76 returns a value 0 instead of 2.07 when the following expression is used:

(import "liblabjackusb.so" "LJUSB_GetLibraryVersion" "float") followed by (LJUSB_GetLibrarVersion) returns a value 0 instead of 2.07.

Perhaps that is because "float" is a cut down version of "double"?

I just checked that there is segmentation fault reading a flost from libc on linux 64 bit, as follows:

(import "libc.so.6" "strtof" "float" "char*")
(strtof "2.07")
yields segmentation fault.

I would appreciate if this issue is resolved.
Title: Re: v10.76 ffi interface does not read 32 bit float
Post by: vashushpanov on March 12, 2024, 07:19:05 PM
(import "libc.so.6" "strtof" "float" "char*")
(println (strtof "3.07"))
result = 3

With comma:
(import "libc.so.6" "strtof" "float" "char*")
(println (strtof "3,07"))
result = 3,069999933242798


Title: Re: v10.76 ffi interface does not read 32 bit float
Post by: sjain59 on March 13, 2024, 08:11:45 AM
Try with value 2.07. It gives segmentation fault here. I was aware that 3.14 is reported as 3.14 (with some fractional error) but thought it fit only to report the segfault. Thanks. Kindly help.
Title: Re: v10.76 ffi interface does not read 32 bit float
Post by: vashushpanov on March 13, 2024, 09:19:57 PM
(import "libc.so.6" "strtof" "float" "char*")
(println (strtof "2,07"))

result 2,069999933242798
(with comma)

(import "libc.so.6" "strtof" "float" "char*")
(println (strtof "2.07"))

result 2

(import "libc.so.6" "strtod" "double" "char*")
(println (strtod "2,07"))

result 2,07

(import "libc.so.6" "strtod" "double" "char*")
(println (strtod "2.07"))

result 2




Title: Re: v10.76 ffi interface does not read 32 bit float
Post by: sjain59 on March 13, 2024, 11:41:57 PM
I apoligize humbly. I have reproduced your result. I must have done something wrong to get the segfault. Many thanks.