Need Help with Double Precision Float Variables

Blitz3D Forums/Blitz3D Programming/Need Help with Double Precision Float Variables

RustyKristi(Posted 2015) [#1]
I'm trying to calculate some precised SIN and PI equations and I noticed that the float variable is not that accurate.

Is there an updated workaround or solution re: this issue?

Thanks.


Rroff(Posted 2015) [#2]
I think someone implemented a DLL for dealing with larger numbers/higher floating point accuracy but I don't recall the details off hand.


Floyd(Posted 2015) [#3]
The relevant code archive entry is here: http://www.blitzbasic.com/codearcs/codearcs.php?code=1905

Some potential headaches:

1. That is source code only. You need a C/C++ compiler to build the DLL, or find someone who still has it. Contacting the author probably won't work. He hasn't posted here in eight years.

2. Using it is awkward. Look at the first example, which just mutliplies two numbers. It's not just a = b * c.

3. Even if you get everything working it may not help, depending on how you want to use the results. Vertex coordinates, entity position and rotation etc. are handled by Direct3D and are single precision only. Any double precision results would have to be turned back into single precision if used in the 3D system.

The upshot is that your first task is to decide if you really need double precision and can actually use the results.


RustyKristi(Posted 2015) [#4]
Thanks guys. Yeah, I just tested Abram's code but it crashes and unusable. Can this be done by modifying the source in B3D?

That's ok, I don't need it on the final entity position or vectors, just the preliminary computation on the coordinates. I still need it though because I'm comparing my formula to other languages and the angle floats are not the same :/


Floyd(Posted 2015) [#5]
Abram's code needs the DLL, which is not available here.

How wrong are your test results? If angles are off by factor of about 57.3 then you are mixing up degrees and radians.


RustyKristi(Posted 2015) [#6]
Yes, I already downloaded the DLL. I think you were the one who uploaded it as a 'txt' extension file

http://floyd2.webs.com/blitzdouble.txt


If angles are off by factor of about 57.3 then you are mixing up degrees and radians.



Ok can you provide an example?

Thanks.


Floyd(Posted 2015) [#7]
Oh yeah, that was me.

The sample code certainly shouldn't crash. Did you put both the .decls and .dll files in your userlibs folder?

Degrees versus radians:

180 degrees is the same angle as Pi radians; 57.3 is roughly 180/Pi.

As an example, 45 degrees has both Sin() and Cos() exactly equal to Sqr(2)/2, which is about 0.7071.

So you should get Sin( 45 ) equal to about 0.7071 if degrees are used, as in Blitz. Note 45 is 180/4.
In case of radians Sin( Pi/4 ) would be 0.7071.


RustyKristi(Posted 2015) [#8]
Ok thanks Floyd. I might not need double float if I can solve this blitz math conversion..

Here's a sample of my code..

n = 3
m# = 2*Pi/n

For i = 0 To n
   Print Cos(m * i)
Next


I should be getting..

1.0
-0.5
-0.5


like this in Python or C. I'm just new to Blitz3d math so im a bit confused.


Floyd(Posted 2015) [#9]
As mentioned, Blitz3D ( and Blitz everything else ) uses degrees rather than radians.

2*Pi radians is 360 degrees, so your example should be:

n = 3
m# = 360 / n  ; not (2*Pi)/n

For i = 0 To n
   Print Cos(m * i)
Next


I've just noticed that Chrome thinks radians is misspelled. Same with Blitz3D but that one is understandable.


RustyKristi(Posted 2015) [#10]
Ok thanks again Floyd. now it's clear.