has math precision improved yet?

BlitzPlus Forums/BlitzPlus Programming/has math precision improved yet?

julianbury(Posted 2003) [#1]
Hi, I'm back.

Not been here for a long time.

Last time I was was here floating point values
were allocated only 32 bits space for
both the mantisa and the exponant.

This made high precision math impossible.

Has anything changed?

In C, a double is allotted 64 bits,
a long double gets 80 bits. Can BlitzPlus do this yet?

Ever hopefull,

Todd(Posted 2003) [#2]
Hi, Welcome back!

Nope, there's still no native support for bigger floats, but you could always find or write a userlib to do it for
you. In fact, I'm thinking of doing this myself.

FlameDuck(Posted 2003) [#3]
In C, a double is allotted 64 bits, a long double gets 80 bits. Can BlitzPlus do this yet?
Nope. Incidently, what do you need it for? Writing betatron control software in BlitzPlus? :o>

Warren(Posted 2003) [#4]
Yeah, I'm really wondering at this point what you need that sort of precision for ...

julianbury(Posted 2003) [#5]
Hi FlameDuck :-)

I want to write a scientific calculator to work planitary orbital predictions.

I need to be able to input real distances in meters and velocities in fractions of a meter per second.

Results are required to be extremely accurate at each step to avoid errors accumulating.

Cosines must be correct to millionths of a degree.

I can't afford Mathmatica so I want to write my own.

The great thing about blitz is that it makes application creation quick and easy.

The drawback is that it can't do two mission-critcal things:

detect all keypresses in text gadgets and do accurate numbers.

julianbury(Posted 2003) [#6]
Hi Todd :-)
you could always find or write a userlib

I have never written a userlib. How do you do it?

Imphenzia(Posted 2003) [#7]
; set float variable to 0

; add 0.1 three times to make it 0.3

; subtract 0.1 three times to make it 0

; is the result 0?
Print a#
Delay 2000

Floyd(Posted 2003) [#8]
If Blitz had double precision floats the result would be -2.77555756e-017.

It's interesting that single precision gives a positive number and double precision gives negative.
But the important lesson is that you will never get exactly zero.
That's life in the approximate world of floating point arithmetic.

Imphenzia(Posted 2003) [#9]
Yes, something I didn't consider until today.

I will have to review my code to ensure that I don't rely on something being exactly 0. Who knows, maybe I'll find some bugs =D

julianbury(Posted 2003) [#10]
Well, now I'm even more convinced of the nessecity of making a DLL with a C compiler.

The more bits you have to hold your number, the nearer you can get to the true value.

It's a bit like approaching the speed of light - the faster you go, the heavier you become and more energy it takes to maintain your acceleration.

I would love to be able to calculate and store and use a 3070 place value of PI :-D

That would yield some might fine cosines!

A long double is all I'm hoping for, really. An 80bit value should be good enough until I graduate to the Q Continuum.

MSW(Posted 2003) [#11]
Why not use strings and roll your own math functions on them?...tis what FORTRAN basicly used for decades on Cray super computers and such....it wouldn't be fast, but you could use PI out to however far you need it.

Andy_A(Posted 2003) [#12]
How about Binary Coded Decimal (BCD)? It uses 4bits per digit for 20 digits of precision you need 80 bits, but is much more precise than 80 bit floats (no dec2bin rounding errors). It seems that a BCD library would suit your needs much better. It's not as fast as double floats but faster than strings. Just a thought.

Floyd(Posted 2003) [#13]
This is all fantasy.

Nothing about this 'orbital simulator' really needs more than double precision.

The higher precision, and very slow, math packages are typically used for a reality check.
You run your algorithm in double precision. Then try again with very high precision.

If the results are significantly different then you know your algorithm needs work.

julianbury(Posted 2003) [#14]
The higher precision, and very slow, math packages are typically used for a reality check.

EXACTLY! Speed is not an issue, ACCURACY is.

None of this is getting A DLL made.

Does anybody have GCC code for a DLL?

BHoltzman(Posted 2003) [#15]
Maybe you can afford Mathmatica, student edition? I think it goes for $150. I've got it and it certainly can do what you're asking.

Also, I'll look at ibasic for you to see what percision it works in. Ok, ibasic uses 8 bytes for it's double percision variable.

Maybe you can download one of the free learning edition compilers out there.

MSW(Posted 2003) [#16]
Might also look at PowerBasic (www.Powerbasic.com IIRC)

Michael Reitzenstein(Posted 2003) [#17]
It's a bit like approaching the speed of light - the faster you go, the heavier you become and more energy it takes to maintain your acceleration.

Good God man, don't mention that around here!

Rottbott(Posted 2003) [#18]
I don't see why BCD shouldn't be plenty fast enough for a calculator. It doesn't matter if it takes 100 milliseconds to get your an answer, right?

Can't be that hard to write a BCD library in Blitz.

Should be almost as fast as getting doubles via DLL-call anyway.

Todd(Posted 2003) [#19]
Hi julianbury,

I'm working on writing a 64bit floating point Dll, and it's almost ready for the first version. The downside to using it, of course, is that you don't get to use operators (+,-,/,*) anymore, you're stuck with using functions to add, subtract, multiply and divide. As soon as I work out a couple little bugs, I'll post it here. It should be a little later today. Also, it's written in pure assembler, so it should be plenty fast. I'm also planning on converting it to 80-bit floats, and maybe even BCD.

julianbury(Posted 2003) [#20]
Hi Guys (^_^)

BHoltzman: "Mathmatica, student edition? I think it goes for $150"
I suppose I could. But - well I wanted to do my own - for fun! Strange, I know :-]
iBasic, I'll check that that out. Thanks for the suggestion!

MSW: PowerBasic another to check out. Thanks

Michael Reitzenstein: "Good God man, don't mention that around here!"
C'mon, Man - we're at least partially adult round here - are we not?

Rottbott: I'm not sure what you mean by binary coded decimal - is using that anything like doing it all in text?
How would you go about finding the square root for a 3D distance to find a gravitational influence?

Todd: "Also, it's written in pure assembler"
Now I'm really impressed! Intel processors have a HORRIBLE instruction set - well, they are compared with ARM processors.
If you are considering doing a 10 byte long float (2.5 registers),
why not consider keeping to register-sized 4 byte chunks
and go for the full bollocks and do a 3 register 96 bit float for that all important reality check?
Perhaps you could christen it a "reality float"?

Just a thort! ^@@^

Todd(Posted 2003) [#21]
Ok, here's the first version of the 64-bit float lib. Just unzip the files into a folder, and put the .decls and .dll in your Blitz+ or B3D folder. It also includes a help file that explains each of the commands. It's pretty limited right now, but I'll be improving on it.

Download Float64 Userlib (37.3kb)

julianbury(Posted 2003) [#22]
Thanks Todd, I've just been looking at it.

It occured to me to wonder how to keep an array of double.
Could your DLL be pursuaded to look after 64bit number arrays?
Could you also make 64bit signed and unsigned integers available?
Stella distances in meters can be bulky.

I ask a lot, I know. Blitz is so good at other things that I want to use it for everything.

(I use it now for stuff more appropriate scripting like automatically creating HTML files for my website or to rename bunches of files.)

Anyway, your DLL could fill in some of the holes in Blitz.

BlitzPlus's other major problem is not being able to detect the full suite of keypresses while in a string or text gadget - that has been such a pain! This is probably an inapropriate problem for a DLL to solve - but, you're a real programmer and might know better!

Well, it's not illegal to hope.

In principle, could a DLL actually allocate RAM for arrays, should it be required?

Jeez, I've just gotta find out how to write a DLL!


Perturbatio(Posted 2003) [#23]

Jeez, I've just gotta find out how to write a DLL!

If it's only for personal use, you could download the personal edition of delphi or c++ builder (www.borland.com).

Alternatively there's something like free pascal ( www.freepascal.org )

I know Delphi supports the Int64 variable which is a signed 64bit value with the range: -2^63..2^63-1

freepascal also has int64 support