floating points
Blitz3D Forums/Blitz3D Beginners Area/floating points
| ||
How far does the blitz floating point number system go? I can't figure out how to get anything more than 6 digits (on either side of the decimal)...Is there a way to do more? It rounds stuff down to zero that would be elsewhere 3.8897051e-6 I have compared this to my ti-84 calculater and identical c++ code and they both come out with 3.8897051e-6 while blitz comes out to zero... |
| ||
Blitz3D only provides single precision floats, which give 6 digits of precision, I think. Not much you can do about it, AFAIK. What do you need the increased precision for, BTW? |
| ||
trying to convert some c++ code to blitz...everything is so small and at the same time so large (like from the above example to 4414.7339, but I thought it could be done because there are no doubles in the code, just floating points...) It is affecting the code because it rounds down each frame, which means that instead of gradually becoming smaller or bigger it just stays at zero. |
| ||
Well, if the C++ code is using doubles, I'll assume it's using them because it needs them. Maybe you could compile the code into a DLL and call it from blitz? |
| ||
How would I go about doing that(compiling code into a dll) I said that there were no doubles in the c++ code... (I think that sin,cos,... use doubles, not sure...) Problem is that it calculates these itty bitty numbers and then add them each frame to different things, sometimes multiplying. If blitz changes them to zero, multiplying definately won't work, and adding does nothing...) |
| ||
The problem is something else. Single precision is the same in Blitz and C++. In either case if you try to add a very small number to a very large one there will be no change. For example 5000.0 + 0.00005 would produce 5000.0, because there is not enough precision to represent 5000.00005. |
| ||
And it is not the conversion from c++ cos/sin to blitz cos/sin ? With the deg/rad conversion? *pi/180? |
| ||
No, I figured the sin,cos,atan stuff out (after a couple of hard hours)...What I am saying is that the c++ code seems to update it's numbers to a higher decimal place than blitz...c++ might return 4.3888 and blitz might return a 4.4...the problem is when c++ almost goes to zero, then blitz goes to zero, making it impossible to get away from zero (because of multiplication) |
| ||
To compile a .dll, go to file->new in c++ an select dynamic link library as a project type. You can find examples of blitz userlibs on the net. If c++ makes the right calculations, the function will have a correct result. However, when the .dll is used in Blitz, it's result is still converted to a blitz float. |
| ||
Thanks bram32, will try! |
| ||
Uhhhhhhhhhh, I can't figure out how to create a .dll file in c++ (visual studio 6.0)...can someone please help? |
| ||
I use Delphi to create .DLL's. Since Pascal is more like Basic, I find it far more easy to work with it than C++. I tried the following thing: (1) In Visual Studio goto File->New->Projects->Win32 Dynamic Link Library (2) Enter project name "test2" and press "Ok" (3) Select "An empty DLL project" and press "Finish" (4) File -> New -> Files -> C++ Source File (5) Enter a file name and press "Ok" (6) Paste this: (7) Press Build (F7) (8) Copy the compiled .DLL in the userlibs directory (9) Make an empty text file in the userlibs directory, and paste this: .lib "test2.dll" Formula#(ax#, bx#, cx#, dx#, e#):"_Formula@20" --> And save it/rename it to "test2.decls" (10) **Notice that the .dll name in the decls should be the same as the compiled dll (11) **The @20 equals the number of bytes passed to the function. In this case, 5 floats x 4 bytes. Integers are 4 bytes, too. (12) Test the function in Blitz using this: Print Formula(1,1,1,1,1) WaitKey() End These links show examples of DLL's in C++: On this page is the original documentation: http://www.blitzbasic.com/sdkspecs/sdkspecs.php These are just random links containing DLL's: http://www.blitzbasic.com/Community/posts.php?topic=51944 http://www.blitzbasic.com/codearcs/codearcs.php?code=1639 http://www.google.nl/search?hl=nl&safe=active&q=bbcall+blitz3d&meta= http://www.blitzforum.de/forum/viewtopic.php?t=254&sid=1434dc251f0bca47fc770a1175c994b2 |
| ||
Thanks Bram32...This will help alot! |
| ||
Sorry to be such a bother, never have done this....When I build the code, it creates a .lib, and then when I try to use it in blitz it highlights the commands well enough but comes up with an error saying it can't find the userlib? EDIT: sorry about that, right after I posted found the dll file... |
| ||
There should be a .dll too in the same dir |
| ||
Had to go into project properties and specify that I wanted a .dll make, even though it was already selected that way, Thank you very much bram32 for helping me with all the trouble I have caused. |