v10.76 ffi interface does not read 32 bit float

Started by sjain59, March 09, 2024, 10:33:24 PM

Previous topic - Next topic

sjain59

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.

vashushpanov

#1
(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



sjain59

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.

vashushpanov

#3
(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





sjain59

I apoligize humbly. I have reproduced your result. I must have done something wrong to get the segfault. Many thanks.