Maths

Blitz3D Forums/Blitz3D Beginners Area/Maths

bushsolo(Posted 2004) [#1]
I'm having some trouble saving my float value as a string, this may sound odd but it does not keep the format I need. If I had assigned 0.0000000001 to a float variable it changes to 1.e-010, how could I move it back to a string as 0.0000000001 again?


Ice9(Posted 2004) [#2]
You should probably only rely on a float 4 digits past the
decimal beyond that a float is unreliable. If you do any
math at all with the float you are using you won't get the
same value each time.


Floyd(Posted 2004) [#3]
There is no built-in formatting control in Blitz.
If you really need this then you will have to write your own formatting code.

But is 0.0000000001 really something you want? I can't tell what this number is without moving the cursor through the number and counting the zeroes. With 1.e-010 I don't have to count. It's nine zeroes followed by a one.


bushsolo(Posted 2004) [#4]
Yep, I really do want 0.0000000001 and I still don't really understand 1.e-010! If I save it as a string I get 0.0000000001 if it's a float 1.e-010 that needs to get back to 0.0000000001 in a string.

Another similar problem...

Answer# = number# + Float ( String$ )

if answer is 0.1111111111 and string is 3 answer is 3.1.

Basicall I'm trying to build a calculator app in B+ but these are a few of the obstacles I'm facing. If anyone knows of any good code, function etc.. that deal with this stuff please let me know. Basicall if a user adds 0.0000000001 and 3.0001 I want them to get 3.0001000001 not 3.0 :(


Floyd(Posted 2004) [#5]
The e notation tells you where to put the decimal point.
e+ means move the decimal point to the right, e- means move left.

So 1.3e+002 would mean 130 and 1.3e-004 would mean 0.00013.

As for adding 0.0000000001 and 3.0001 to get 3.0001000001, that's not going to happen.
Blitz floating point numbers are single precision, about seven digits.

That means 0.0000000001 + 3.0001 = 3.0001, the first number is simply too small compared to 3.

The upshot of this is that Blitz is really not suitable for a calculator.


bushsolo(Posted 2004) [#6]
Shame, everything I seem to try and do in Blitz ends up being a series of hurdles I need to jump...

Anywho I'm sure I can make a function to get that 1.e-010 back into a string as 0.0000000001, thanks for the info Floyd.


WolRon(Posted 2004) [#7]
You CAN do it the way you want, but you will have to handle EVERYTHING manually using strings.

You will just have to do the math the way you were taught to do it by hand back in school.

A lot of work, but it can be done.


bushsolo(Posted 2004) [#8]
OK, that makes sense and a lot of work, I can read the length of the string, check for a decimal point and add, divide, subtract and multiply one character at a time. Seems odd no one has written functions for this already...

Function Divide ( FirstNum$, SecondNum$ )

...... ; Do math here...

Return Answer$

End Function

If I do this and it's worth anything I'll put it in the Code Archives :)