Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sin(pi) not zero

Status
Not open for further replies.

fawkes

Technical User
Sep 12, 2003
343
0
0
GB
Can anyone explain why the following isn't zero

Code:
System.Math.Sin(System.Math.PI)

The answer comes back as 1.22460635382238E-16
 
It is woth noting that

Code:
System.Math.Cos(System.Math.PI)

Returns -1
 
What type of variable are you assigning the result to?

If you assign it to an Integer it comes out as zero e.g.
Code:
Dim i As Integer = System.Math.Sin(System.Math.PI)
and if you assing it to a double it comes out as 0.00000000000000012246063538223773 e.g.
Code:
Dim i As Integer = System.Math.Sin(System.Math.PI)



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Oops...just noticed my last statement had a Type of Integer. It should have read:

and if you assing it to a double it comes out as 0.00000000000000012246063538223773 e.g.
Code:
Dim i As Double = System.Math.Sin(System.Math.PI)


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
And I must stop copying that bit of text that says "and if you assing it"!


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
From MSDN:

System.Double and System.Single have inexact precision of decimal digits because internally they are a floating point binary numbers. As such, beyond a certain number of significant digits, their decimal representation becomes approximate.


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top