PDA

View Full Version : Algo question for the math folks out there

HannKett
Mar 6, 2012, 04:57 AM
Hello,

I have a weird problem, and I can not think straight so I need some input on this one algo :)

I have a slider with values of 1-9, now what I want to use the floats for is that I get 1.0 - 9.0 in float values that I have rounded off so there are no 1.5 and 3.7 and so.

Now I want to reverse the 1.0 to use in multiplication as a 0.9 and 2.0 as 0.8 and so on. but I cant for some reason come up with how to do that.

Maybe I need more sleep, but it is like when you forgot a name and word but you have it on the back of your tongue..

robbieduncan
Mar 6, 2012, 05:07 AM
1) The first part is easy: cast to int then back to float (assuming you are using C types rather than NSNumber)

2) It's not clear by what you mean by "reverse". It appears you mean "divide by 10 then subtract that result from 1.0".

HannKett
Mar 6, 2012, 05:09 AM
2) It's not clear by what you mean by "reverse". It appears you mean "divide by 10 then subtract that result from 1.0".

LOL :) hahah thanks man :p (ashamed I am)

I need stronger coffe !

MorphingDragon
Mar 6, 2012, 05:10 AM
Hello,

I have a weird problem, and I can not think straight so I need some input on this one algo :)

I have a slider with values of 1-9, now what I want to use the floats for is that I get 1.0 - 9.0 in float values that I have rounded off so there are no 1.5 and 3.7 and so.

Now I want to reverse the 1.0 to use in multiplication as a 0.9 and 2.0 as 0.8 and so on. but I cant for some reason come up with how to do that.

Maybe I need more sleep, but it is like when you forgot a name and word but you have it on the back of your tongue..