Hopefully a quick and easy maths problem...
BlitzMax Forums/BlitzMax Beginners Area/Hopefully a quick and easy maths problem...
| ||
In this code: [CODE] Graphics 800,600,0 Global blah:Float blah = 1/2 DrawText (blah,10,10) Flip Repeat Until KeyHit(KEY_ESCAPE) [/CODE] By my reasoning 'blah' should be equal to 0.5, so why does the value appear to be 0 ? I expect i'm missing something REALLY obvious :-\ |
| ||
Graphics 800,600,0 Global blah:Float blah = 1.0/2.0 DrawText (blah,10,10) Flip Repeat Until KeyHit(KEY_ESCAPE)Solved. |
| ||
Thanks.... but.... In my original code i'm actually dividing two elements from an array, e.g: blah = (myarray[0] - myarray[x])/myarray[0] (i need to find the difference between the current (x) value of the array and the first (0) value as a percentage of the first value) So is this still so easily solved? and how do I indicate code in the text (since [CODE][/CODE] obviously isn't right ;) |
| ||
blah = (Double(myarray[0]) - Double(myarray[x]))/Double(myarray[0])Solved again. Oh and forum codes are all lower case. See What are the forum codes? for more codes. |
| ||
Also see the Blitz Max help/language/types/type balancing for an explanation on what is happening in that equation. In the previous equation you could have got away with only casting one arguement.blah = (Double(myarray[0]) - myarray[x])/myarray[0]But it's safer just to cast them all. |
| ||
Works like a dream, many thanks for your rapid help when just when i needed it :) I'm assuming from this that calculating floats using integer values will give an integer result? Seems strange behaviour to my inexperienced mind, is there a reason for it? |
| ||
I only saw your last post after I'd posted my reply to the previous one. Thanks for pointing me to the correct part of the help file and bearing with me as I stumble on step further up the blitz learning curve :) |