# to all math genius!

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 02-05-2003
Mathy
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?
• 02-05-2003
laasunde
I certainly did not understand your question but maybe someone else can help out.
• 02-05-2003
Travis Dane
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; }```
• 02-05-2003
kohatian3279
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?
• 02-05-2003
FillYourBrain
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.
• 02-05-2003
Magos
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.
• 02-05-2003
FillYourBrain
ya, there's a definite precision issue with floating point numbers. the .9999999 works to a degree of precision.
• 02-05-2003
Kohatian3279
i got it!
x=1-value;
y=x*0.9;
value=value+y
• 02-06-2003
stovellp
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)
• 02-06-2003
stovellp
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;
}
• 02-06-2003
Magos
Am I the only one that hates pre/post incremented/decremented variables in the middle of an expression? :rolleyes: :confused:

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...
• 02-06-2003
stovellp
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.
• 02-06-2003
Hardboy
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.
• 02-07-2003
Magos
Quote:

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.
• 02-07-2003
SmashBro
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.
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last