f## = 1## / 3##
f## = (f## * 1000000000000000##) - 333333333333333##
PRINT f##
f# = 1# / 3#
f# = (f# * 1000000000000000#) - 333333333333333#
PRINT f#
but obviously _FLOAT is broken
DIM a AS _FLOAT
a = 1
n = 1000
IF n < 1755 THEN
FOR k = 1 TO n
a = a * k
NEXT
e = 0
WHILE a > 1F308
a = a / 10##
e = e + 1
WEND
f$ = STR$(a)
d = INSTR(f$, "D")
d$ = MID$(f$, d + 1)
e = e + VAL(MID$(f$, d + 1))
f$ = LEFT$(f$, LEN(f$) - LEN(d$) + 1) + LTRIM$(STR$(e))
PRINT "factorial of "; n; " = "; f$
ELSE
PRINT n; " is too large"
END IF
it works up to n = 1754I noticed that the 32-bit version of QB64 is more accurate, the 64-bit version doesn't preserve the precision of a _Float but rather that of a double
_FLOAT isn’t “broke” on 64-bit versions. You need to take a moment to read up on the long double variable type to try and understand the difference in behavior: https://en.wikipedia.org/wiki/Long_double
The precision results you see with _FLOAT depends heavily upon your system, the compiler you’re using, and sometimes even which option flags you have set with your compiler.
It’s not anything inside QB64 which is “broken”. It’s simply the nature of a long double data type (_FLOAT).
_FLOATs are *required* to be as precise as doubles, but often offer more precision than that. You can’t expect anything more from your programs than that, unless you want to write your own math routines or go to string math.
QB64 always allocates 32 bytes to store this value.
It is safe to assume this value is at least as precise as DOUBLE.
Under the current implementation it is stored in a 10-byte floating point variable.
_FLOAT variables can also use the ## variable name type suffix.
Values returned may be expressed using exponential or scientific notation using E for SINGLE or D for DOUBLE precision.
According to IEEE-754 this can store a value of up to 1.1897E+4932 compared to a DOUBLE which goes up to 1.7976E+308.
how can you say it's not broke if it does not work?
clearly _Float claims to be 80-bit float which it isn't, and if it isn't then why bother having it if it's the same as double?
I know MS C treats long double the same as double, but what does that have to do with _float?
btw, this same behavior is observed with QB64 under linux, now I know linux supports 80-bit long double
and if you had taken the trouble to look at my code you would have noticed that the calculations were done in quasi 80-bit float, otherwise why would it give a correct answer?
one thing is certain, it's stupid for me to waste my time on this forum and with QB64
from the QB64 Wiki
In C and related programming languages, long double refers to a floating-point data type that is often more precise than double-precision though the language standard only requires it to be at least as precise as double.