QB64 set's the FPU control word to double precision at least part of the time, making operations with _float unreliable at best
here's a very short demo for Windows, place the c_include.h in the QB64 folder
c_include.h
#define __USE_MINGW_ANSI_STDIO 1
#include <stdio.h>
#include <math.h>
void qbsprintf (char *ResultString, char *format, long double *x)
{
sprintf(ResultString, format, *x);
}
int qbsscanf (long double *result, char *InputString)
{
return sscanf(InputString, "%Lf", result);
}
long double qbdiv(long double *x, long double *y)
{
return (*x)/(*y);
}
long double qbdivf(long double *x, long double *y)
{
long double z;
short oldcw, extended = 0x37f;
//set fpu control word to extended precision
asm (
"fstcw %[oldcw] \n"
"fldcw %[extended] \n"
:[oldcw]"=m"(oldcw),[extended]"=m"(extended)
:
:
);
z=(*x)/(*y);
//restore fpu control word
asm (
"fldcw %[oldcw] \n"
:[oldcw]"=m"(oldcw)
:
:
);
return z;
}
demo.bas
' c_include.h needs to be in QB64 folder
$CONSOLE:ONLY
_DEST _CONSOLE
DECLARE CUSTOMTYPE LIBRARY ".\qb_include"
SUB qbsprintf (res AS STRING, frmt AS STRING, x AS _FLOAT)
FUNCTION qbsscanf& (f AS _FLOAT, sfloat AS STRING)
FUNCTION qbdiv## (x AS _FLOAT, y AS _FLOAT)
FUNCTION qbdivf## (x AS _FLOAT, y AS _FLOAT)
END DECLARE
DIM x AS _FLOAT
DIM y AS _FLOAT
DIM z AS _FLOAT
DIM SHARED strout AS STRING
x = 5##
y = x / 9##
PRINT "QB64 division "; print_strout(y)
s$ = "5L"
k& = qbsscanf(x, s$)
k& = qbsscanf(y, "9L")
z = qbdiv(x, y)
PRINT "C division low prec "; print_strout(z)
z = qbdivf(x, y)
PRINT "C division ext prec "; print_strout(z)
FUNCTION print_strout$ (x AS _FLOAT)
strout = " "
CALL qbsprintf(strout, " %.20Lg", x)
print_strout$ = strout
END FUNCTION
output
QB64 division 0.55555555555555558023
C division low prec 0.55555555555555558023
C division ext prec 0.55555555555555555556
I included the sscanf but it's probably not needed