# Thread: to all math genius!

1. ## to all math genius!

i want to update a value whcih should be not greater than 1 and the updated value should also be not greater than 1.if the given value is 0.9999 then the updated value should be 0.99999 but i dont know that how many 9s will be there in the given value. so ne ideas?

2. I certainly did not understand your question but maybe someone else can help out.

3. So you want a variable that's under 1 to increase but to stay
under 1, That's easy, Use floats.

Code:
```float number=0.5;

while(1)
{

if(number<0.999999999)
{
number+=0.000000001 // Don't know exactly how large floats can get
}
else
{
break;
}

cout << number;

}```

4. but still it is setting restriction on the input number so that it should be less than 0.999999999, what abt 0.99999999999999999999999? it should also accept that and update it with one more .000...9. got the idea?

5. in the past, I've used .0000001 or some variety as a "distance from a number"

for instance if you want to find out if n is approx 5 you can do this...

isapprox = fabs(n-5)<.0000001;
//fabs is of course absolute value of a float

I hope that helps.

6. Code:
```float IncreaseValue(float Value)
{
float Increaser = 1.0 - Value;
Increaser /= 10;
return (1.0 - Increaser);
}```
If Value is 0.99999, Increaser will be 1.0 - 0.99999 = 0.00001.
Increaser divided by 10 will give you 0.00001 / 10 = 0.000001.
Subtract Increaser from 1.0 and you will get 1.0 - 0.000001 = 0.999999, which is greater than 0.99999 but still less than 1.

Note that floats aren't always 100% exact so you might get some irregularities.

7. ya, there's a definite precision issue with floating point numbers. the .9999999 works to a degree of precision.

8. ## i got it!

x=1-value;
y=x*0.9;
value=value+y

9. You could always make an array of INT's of a dynamic size so that you can just keep adding them on once one reaches 9.

eg:
[code]
if (myArray[X] == 9)

10. You could always make an array of INT's of a dynamic size so that you can just keep adding them on once one reaches 9.

eg:
[code]
if (myArray[X] == 9)
{
myArray[++X] = new int;
myArray[X] = 1;
}

11. Am I the only one that hates pre/post incremented/decremented variables in the middle of an expression?

Is that a hardware supported feature? (I know some of them exists in Motorola processors) If it isn't, then it's one helluwa unneccessary way of complicating code...

12. Well I could have just written a whole extra statement saying X++; but then I remembered, theres no difference, and I'm slack, and my teacher won't be reading it.

13. Sometimes itīs nice to use pre/post increment/decrement, when an extra line of code seems unnecesary.

Example:

Code:
```int temp,index;
int array[BIG];

[...somewhere inside a loop]

temp = array[index++];```
In this case itīs obviously whatīs going on.

14. Originally posted by Hardboy
In this case itīs obviously whatīs going on.
Perhaps to those who know the functionality of pre/post decremented operators, but just looking at the expression an assignment and a variable increment are done on the same line. You can't tell which one is executed first. And it does matter which order they are.

15. The key is to create a power function, check the closeness to one, and then at 10 to the -whatever, depending on how many didits are past the decimal point.