limited Math in Blitz3d/2d

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

Kepu(Posted 2006) [#1]
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


Floyd(Posted 2006) [#2]
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.


Damien Sturdy(Posted 2006) [#3]
"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...)


Kepu(Posted 2006) [#4]
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, .........
:)


jfk EO-11110(Posted 2006) [#5]
not a bug, but I would like to have double precision too.

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


Abram(Posted 2007) [#6]
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.


markcw(Posted 2007) [#7]
yes, i would be interested Abram.

Also, source code would be cool.


Abram(Posted 2007) [#8]
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


humanspacecraft(Posted 2007) [#9]
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


Abram(Posted 2007) [#10]
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


humanspacecraft(Posted 2007) [#11]
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


Abram(Posted 2007) [#12]
Just happy that I could help somebody, wish you the best of luck adding whatever functionality you need for your own purposes!


markcw(Posted 2007) [#13]
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.


Kepu(Posted 2007) [#14]
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)


Abram(Posted 2007) [#15]
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...


RGR(Posted 2007) [#16]
.

Last edited 2012


RGR(Posted 2007) [#17]
.

Last edited 2012


Floyd(Posted 2007) [#18]
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.


Abram(Posted 2007) [#19]
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


RGR(Posted 2007) [#20]
.

Last edited 2012


humanspacecraft(Posted 2007) [#21]
It´s updated!

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


Floyd(Posted 2007) [#22]
... 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.


Abram(Posted 2007) [#23]
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)


Floyd(Posted 2007) [#24]
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.


RGR(Posted 2007) [#25]
.

Last edited 2012


Abram(Posted 2007) [#26]
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 :)


humanspacecraft(Posted 2007) [#27]
Also the newest version:
http://www.electricdesire.com/blitz/blitzdoubleXL.rar


Danny(Posted 2007) [#28]
[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 ;)]


humanspacecraft(Posted 2009) [#29]
[offtopic @Danny]
thausend years later
no i did´nt knew this.
I´ve been a fair kid,but i would assume that if i had known this back then, i had been too keen to try this one and of course a department store would be the choice.


Sake906(Posted 2009) [#30]
My main problem with the floats is... while Abram's DLL gives you doubles, it still does not fix the problem existing in the 3D space of the API. Objects for example are still being positioned on it using the limited floats, simply because their coordinates are not casted as doubles but as floats when you use "PositionEntity(X,Y,Z)" and the like. Me and my programming partner believe that these need to be changed (and a lot of other internal world-positioning routines) so the XYZ parameters are casted into doubles within Blitz3D instead of Floats.

Use Abram's doubles in commands such as "PositionEntity()"; you will always have them turning into the limited floats... I really hope Mark does something about this because right now it is one of the main limitations we are having in our project and we are so far in development that implementing a world "grid" workaround for it is out of the question.


Xaron(Posted 2009) [#31]
If you have a huge world you get problems not only with the z-buffer. The best solution would be to have the camera always at 0,0,0 and move (and scale) the world around.