I’d like to read in an enormous fraction like this one from a text file as a string …
156348578434374084375/147573952589676412928
… and get a float from it. If I try to parse this as two integers and do the math, there is an overflow and I get a NaN or division by zero error. I know it’s possible to use libraries like Bob Delaney’s fp plugin. My question is whether there is there any way to do it in pure Xojo. Someone told me they can do this in C, and I told them I don’t believe them, because in order to get a value out of the string, the following has to happen:
convert the string to numbers
do the math
… and doing the math simply fails. What am I missing?
I thought so too, but I get the same exceptions. I mean, to begin with UInt64 is supposed to be able to handle those integers, but somehow it doesn’t work. … Wait, no 156,348,578,434,374,084,375 is beyond 18,446,744,073,709,551,615 so that’s why it fails with UInt64
See if you can find common prime numbers that can be used to reduce each value to manageable levels
you might not be able to do direct operations, but doing a prime integer division should be easy enough to code
[2, 3, 5] for example (if the last digit is even, you can divide by 2, if the sum of the digits can be divided by 3 so can the whole thing)
just an idea… up to you to figure how to implement it
Hey Dave, Isnt it early in the morning in California now ?
(There are so many years since the last time I phoned to Cupertino at 16:20 French summer time I forget the California time).
[quote=405387:@Emile Schwarz]Hey Dave, Isnt it early in the morning in California now ?
(There are so many years since the last time I phoned to Cupertino at 16:20 French summer time I forget the California time).[/quote]
It is 7:30 AM here right now
[code]// fails
dim x as double = 156348578434374084375 / 147573952589676412928 // too big as int literals
MsgBox str(x)
// fails
dim uin, uid as UInt64
uin = 156348578434374084375 // too big for Uint64
uid = 147573952589676412928 // too big for Uint64
x = uin / uid
MsgBox str(x)
// appears to work
x = Double.FromText(“156348578434374084375”) / Double.FromText(“147573952589676412928”)
MsgBox str(x)
// also appears to work
dim n, d as double
n = val( “156348578434374084375” )
d = val( “147573952589676412928” )
x = n / d
MsgBox str(x)[/code]
So, the answer appears to be that pure Xojo CAN do this – not that well, but just as well as any other language without using a big number library.