limited Math in Blitz3d/2d

Blitz3D Forums/Blitz3D Bug Reports/limited Math in Blitz3d/2d

Hi! This might sound stupid but,
Is it possible to get to next Blitz3d version more accurate float numbers (more digits)
(short float) max 32767.1 is way too limited (both ends ;))


This because I want use only one basic for my needs,
Now I have to use two different.
What I need, min 7 digits to' integer' part and 4 to 'decimal ' part
I have tried to find .dll for that, but no luck ,
yours
KK

This has been requested by many people, including me, over the past few years. But double precision floats were never added to the language. My guess is they never will.

The reality is that single precision is good enough for almost everything in game development. Adding double precision would increase the complexity with very little gain in functionality.

"Find & Replace" the B3D source code.

Find "FLOAT:" replace "DOUBLE:" or whatever the terms are :p

It's worth a shot, hahaha. (probrably cock some 3d up somewhere...)

BlitzBasic is excellent programming language, it migth be greated mostly for games, but also it would be an excellent tool.

For me it would be excellent tool for calculating measurements of different shapes and forms and also I want to visualize those in 3d, but it needs double floats to succeed.
( Blitz printer dll filled already one missing part.)

I am hoping that someone (Mark ?) can give a hint if we are getting double float soon or if there is some other option
I am willing to give few dollars for that extension if needed
Please, .........
:)

not a bug, but I would like to have double precision too.

That said, in games design I never really missed it.

I have made a dll that is able to calculate double precision in Blitz 3D, just let me know if you would like to have it.

yes, i would be interested Abram.

Also, source code would be cool.

Sure, not a problem. You have an email to where I can send it or how should we do it? You probably want to add some operations anyway, so the source code is ofcourse included :)

I created a new item in the code archieves that includes the source code and some examples, see under
http://www.blitzbasic.co.nz/codearcs/codearcs.php?code=1905#comments

Hey Abram, i´am very interested in this library. I would put it on my website for download until i get traffic problems ;) My email is included in my profile.

Beste Grüße

Hi Hannes,
the code has been sent! Wish you alot of fun with it.
If you then add a link to your page that others can find it as well it would be good.

Best Regards
Abram

Astonishingly this was exactly what i was looking for at the moment! Thanks for helping and sharing, Abram!

It can be downloaded from here:

http://www.electricdesire.com/blitz/blitzdouble.rar

Just happy that I could help somebody, wish you the best of luck adding whatever functionality you need for your own purposes!

Got it! Thanks very much Abram, and thanks for hosting humanspacecraft. This is cool to have for Blitz.

I will try using this some time with some fractal code I have to get more zooming power.

Thanks very much Abram and also humanspacecraft. Vow, this is something. (I didn't believe my eyes , thus I was begging those 9 months ago)

Well, it is kind of your own fault as well you know ;)
I thought that anyone that wanted a double dll would write to the topic I created 12 months ago :)
Look at http://www.blitzbasic.com/Community/posts.php?topic=49299#548162.

But at least now you have it.. better late than never...

Have you tested the results with a calculator or language that works with double precision?
Here all your results of your demo are wrong
Multiply 36337.58583466*4792.94923023755
Your DLL: 174164208
Windows Calculator: 174164204.054924547826823483
PureBasic: 174164204.05492455

Divide 36337.58583466/4792.94923023755
Your DLL: 7.5814666748046875
Windows Calculator 7.5814668775156257065644242414405
PureBasic: 7.5814668775156253

This is the same I ran into several month ago when I made a dll with double precision ... the dll works fine until it gets into the Blitz3D environment. Blitz3D blocks the CPU working with doubles! You get a result, but its wrong after the 7th digit.

I worked around it that way: I made a standalone exe instead of a dll - sending and getting variables via TCP. Not very quick but in the case I needed it for it was quick enough to do the job. Another way was communication between the 2 Programs though a file.
Since a standalone exe with double precision works perfect and 3 different dlls (my PureBasic, my PowerBasic and your VisualC) fail, it can only be Blitz3D making trouble.
Btw.: My dlls worked errorfree with other languages! Have not tried this dll though... but I presume it will, too.

http://www.blitzbasic.com/Community/posts.php?topic=58828#654531
.

I'm pretty sure Direct3D changes the FPU to single precision mode.

In order to use doubles in a Blitz3D program the DLL would have to allow mode changes. You would switch to double precision mode, do your calculations and then switch back to single precision.

Both of you are right of course, thank you for noticing me about the problem. Got blind when I saw the result just got more decimals. Not a problem to update the dll though to now REALLY handle double and thanks to you Floyd for telling me how I should do it ;).
With the updated dll the results are:
Multiply: 174164204.05492455
Divide; 7.5814668775156253
Which I believe matches your expected results exactly RaGR.
Sorry for the confusion, but I hope there are no more bugs... unfortunately it is a lot slower now, but at least correct.
Updated code has been mailed to humanspacecraft and I hope he will update the code.

/Abram

Hi, great work :-)
After several quick tests it looks as if all results are as expected now.
Will check your sourcecode.
Maybe I can update my old dlls - where I had some latitude longitude calculations included.
Thanks for the quick fix and delivery by mail.
Ralph

It´s updated!

donwload: www.electricdesire.com/blitz/blitzdouble.rar

... unfortunately it is a lot slower now


I should have been more clear about the mode changes, which are very slow. If they are done at every call to a DLL function then performance will suffer.

What I meant is that the DLL must provide a way for the programmer to change the mode within Blitz3D.
The proper usage in a Blitz program would then be:

Set double precision mode.
Do many calculations in double precision ( no mode changes here ).
Set single precision mode.
Continue with ordinary Blitz code.

The idea is to group the double precision calculations and change modes as infrequently as possible.

Thought of that as well, was not sure what would happen if somebody would use the dll and then forget to set the mode back to single mode after the calculations have been done. I dont want to be responsible for crashing someones computer . However I have tried it at my computer and it does not seem to crash anything if I let it stay in double mode even with the normal Blitz functions.... but I wanted to test it more before I released it....

Updated once again, got a request for a lot of functions that I had not included in the dll. Functions to compare doubles and some more maths functions. Also made an option to set the FPU to double mode only in the start of the program, which increases the speed of the dll a lot... Just remember to set it to single mode after the calculations are done, otherwise I have no idea if there will be secondary effects in other parts of your programs..
Or you can use compile with the ALWAYS_SET_DOUBLEPRECISION set to 1 and this will not be a problem.
Hope this will be the last update for a long while :)
(Code once again mailed to humanspacecraft, thanks a lot for hosting)

Leaving the FPU in double precision mode should be harmless, but will be slower than single precision.

All the values used by the 3D engine are single precision. So having the FPU calculate in higher precision is a waste of time.

As far as I know this is the only reason Direct3D uses single precision mode.

Code is still the one from 2007-03-15 20:00 at humanspacecraft. If there's a newer one, can you send it to me via email?

Sure, code has been sent! And regarding leaving the FPU in double precision mode I guess you are right Floyd.. seems to be really harmless. Did some speed measurements also, and it seems to be slower, but not extremly slower to leave it in double mode. No crashes until now anyway because of this :)

Also the newest version:
http://www.electricdesire.com/blitz/blitzdoubleXL.rar

[offtopic @ humanspacecraft: Did you knew that sys 64739 (note 9! not 8!) would destroy the computer after several hours! Seriously! It would skip the CLI statement to clear interupts, thus reset in a continues loop, eventually overheating the kernal after a couple hours! Tested it on several occasions at department stores - ahh good old days ;)]