|
-
Aug 7th, 2001, 11:56 AM
#1
Thread Starter
New Member
The day has come, where 9 is than 9
I was getting red in the face with this thing, trying to figure out
why 9 wasn't equal to 9. Took me a while to figure it out, but I finally found out why. You have a look, it'll make you go nuts if you don't see it at first 
Code:
Private Sub Command1_Click()
'Dim your variables
Dim i
Dim x
'Dim x. Count it with a calculator if you want, but x = 9.
x = 387420489 ^ (1 / 9)
'Finally, do a loop from 1 to 9. Once x = i (Or i = 9), it'll tell you it's equal. But it never does. Aparently, 9 is actually smaller than 9!
For i = 1 To 9
If x < i Then
MsgBox "Smaller"
ElseIf x = i Then
MsgBox "Equal"
Else
MsgBox "Bigger"
End If
Next i
End Sub
Have fun
Is that not the Beast you said you saw? The one from Hell, the one that strives to drown you in the deepest pits of darkness, the pits of insanity?
My soul is resting yet my body alert; my instincts rule, my mind is shut; I am an animal, a beast on guard, hidden in my cave I cannot sleep, I just watch, watch your every movement, ready to strike at you when you expect it least. Look behind you, my friend, you might see my dead eyes staring through you, and you, too, might put your soul to rest, to be protected from the demon that's stalking you.
-
Aug 7th, 2001, 12:06 PM
#2
transcendental analytic
?x-i
-1.77635683940025E-15
Don't use floating points for precise calculations, especially not variants.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 7th, 2001, 04:37 PM
#3
Frenzied Member
Round off.
The problem is due to round off error when computing the exponential. 1/9 is not exact in either binary or decimal. The exponential function is likely to result in round off error even if the operands are integers.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Aug 8th, 2001, 06:56 AM
#4
Frenzied Member
Re: Round off.
Originally posted by Guv
The problem is due to round off error when computing the exponential. 1/9 is not exact in either binary or decimal. The exponential function is likely to result in round off error even if the operands are integers.
Exactly. (1/9) cant be calculated exactly in binary...so the computer gets messed up. But it seems the windows calculator actually deals with the fraction so its fine.
You just proved that sig advertisements work.
-
Aug 8th, 2001, 08:49 AM
#5
Frenzied Member
Nishantp: A calulator which got exactly 9 for the result probably had some other internal result which rounded to 9 when displayed.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Aug 8th, 2001, 09:27 AM
#6
Frenzied Member
Originally posted by Guv
Nishantp: A calulator which got exactly 9 for the result probably had some other internal result which rounded to 9 when displayed.
I dont know about the Windows Calculator but i know that some calculators are able to do calculations based on the actual fractions so i know its possible (they are probably programmed with methods that we humans use).
You just proved that sig advertisements work.
-
Aug 27th, 2001, 12:08 PM
#7
Frenzied Member
X isn't really 9; its like 8.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999 or something and VB can't hold that so it rounds up. Either that or X is 9.00000000000000000000000000000000000000000000000000000000001 and the same thing happens.
Fractions don't need special math to calculate them; they are really just divisions that aren't calculated.
-
Aug 27th, 2001, 07:57 PM
#8
Frenzied Member
Well couldnt you hardcode some functions that do fractional calculations based on human techniques? I wrote something like that to get a huge number of decimals from a division. There SLOW but they work.
You just proved that sig advertisements work.
-
Aug 28th, 2001, 08:34 AM
#9
Frenzied Member
Thats pretty much how they work yeh. And they are slow.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|