double precision

Blitz3D Forums/Blitz3D Programming/double precision

Abram(Posted 2005) [#1]
Have ran into calculation problems where I need better precision than float can provide. Is there anyone that have implemented some dll for a double precision type? Would guess that a lot of you have had the need for double precision type before me.......


KuRiX(Posted 2005) [#2]
You can use a DLL with double precision, but if you get values to Blitz / from Blitz it will be converted to single precision.

Tell us exactly what u need to see if it can be done.

Good Luck. KURi


Abram(Posted 2005) [#3]
I was thinking to create a double in Blitz by creating a bank of 8 bytes in order to store the value, and then call a dll in order to operate on the value. The dll should then have normal functions like =,+,-,* and / only take pointers to the banks storing the value... In that way it should be possible to store a double in Blitz without ever converting it to a float, and keeping the precision by doing all operations in an external dll. In the end also call a function in the dll to convert double to float to be able to operate on it in Blitz.

Hope you could get some sense of what I mean :)


KuRiX(Posted 2005) [#4]
This is a good idea, but then you won't be able to use this values in Blitz3D, because if you convert them to blitz float, you lose the precision.

Then, using them, only in the dll is no sense, except that the dll makes some processing directly to memory, graphics, or something else...


Abram(Posted 2005) [#5]
I am working on a program that converts map coordinates back and forward between a lot of different coordinate systems. Doing these convertions a lot of times using floats means that I in every convertion loose a lot of precision, making me end up with coordinates that does not match in the end.

However converting only one single time in the end of the calculations would mean only loosing some centimeters in accuracy instead of meters (I end up with an accuracy of about 11 meters in this specific case).
So by doing everything in a dll and with one single "double to float" convertion I would get a very big improvement in accuracy. And as long as you create banks of 8 bytes for your varibles in Blitz you would be able to use double.
Guess that you would have to implement some more functions than only =+-*/ in order to cover all functions you would need, but I guess it could be done.... and thought that someone already had done this. No need to invent the wheel twice...


KuRiX(Posted 2005) [#6]
then you could just implement all your convertions into one dll.

so only one pass to the dll and one get from the dll!


Abram(Posted 2005) [#7]
That is also a solution ofcourse, but reimplementing all the converations into dll would probably take me longer than to implement a double in Blitz, so if it has not been done I think I will give it a try :)


KuRiX(Posted 2005) [#8]
Well, good luck then!


Abram(Posted 2005) [#9]
Have gotten it to work perfect. Can multiply, divide add and subtract doubles in blitz without any problems now.

If anyone wants the code just let me know


Abram(Posted 2007) [#10]
This topic has been continued in two other threads, see
http://www.blitzbasic.com/Community/posts.php?topic=58849
or
http://www.blitzbasic.com/codearcs/codearcs.php?code=1905
for source code and comments...