|
-
Oct 20th, 2001, 11:59 AM
#1
Thread Starter
Frenzied Member
Output and Math Precision
VB Code:
Option Explicit
Private Sub Form_Load()
Dim d As Double
d = CDbl("999999999999999.01")
d = d - CDbl("999999999999999")
MsgBox d
MsgBox 0.0000000001
MsgBox CDbl("99999999999999999999999")
MsgBox Sin(CDbl("99999999999999999999999"))
End Sub
Why does the first msgbox not output with any precision
when the second does?
Sin takes a double as an argument, so why does the last
statement give an error?
-
Oct 20th, 2001, 12:08 PM
#2
Thread Starter
Frenzied Member
Code:
#include <iostream.h>
#include <math.h>
void main(void){
double d;
d = 999999999999999.01;
d -= 999999999999999;
cout << d << endl;
cout << 0.0000000001 << endl;
cout << (double)99999999999999999999999;
cout << sin(99999999999999999999999);
}
Won't compile.
-
Oct 20th, 2001, 12:14 PM
#3
Frenzied Member
From MSDN
Invalid procedure call or argument (Error 5)
Anargument probably exceeds the range of permitted values. For example, the Sin function can only accept values within a certain range. Positive arguments less than 2,147,483,648 are accepted, while 2,147,483,648 generates this error.
Greg
Free VB Add-In - The Reference Librarian
Click Here for screen shot and download link.
-
Oct 20th, 2001, 12:39 PM
#4
Thread Starter
Frenzied Member
That explains it.
What about the loss of precision?
-
Oct 20th, 2001, 01:14 PM
#5
Frenzied Member
What about the loss of precision?
I have no idea, sorry.
Greg
Free VB Add-In - The Reference Librarian
Click Here for screen shot and download link.
-
Oct 20th, 2001, 05:34 PM
#6
PowerPoster
Originally posted by wey97
What about the loss of precision?
Sometimes u can work around the inprecision by reorganising the calculation. It would be difficult to do for a large number of complicated transactions.
eg
VB Code:
Private Sub Form_Load()
Dim d As Double
Dim e As Double
Dim x As Integer
Dim Mydouble As Double
For x = 1 To 10
Mydouble = Mydouble + 9 ^ x
'This works exactly
d = Mydouble + 1
d = (d - Mydouble) / 10
MsgBox d
'while this doesnt
d = Mydouble + 0.01
d = d - Mydouble
MsgBox d
Next
End Sub
regards
Stuart
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
|