|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31803 Erro in Cos function
Submitted: 2005-02-02 04:16 UTC Modified: 2008-03-27 14:22 UTC
From: thiago_mata at yahoo dot com dot br Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.3.10 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: thiago_mata at yahoo dot com dot br
New email:
PHP Version: OS:


 [2005-02-02 04:16 UTC] thiago_mata at yahoo dot com dot br
The funcion cos it is not return the espected result. While the sin it is ok.

Reproduce code:
$Angulo = Pi()/2;
print "cos(Angulo) = ".cos($Angulo)."<BR>\n";
print "cos(Pi/2) = ".cos(Pi()/2)."<BR>\n";
print "Angulo = $Angulo <br>\n";
$cos = sqrt(1 - sin($Angulo)*sin($Angulo));
print "Coseno = ".cos($Angulo)."<br>\n Cos = ".$cos."<BR>\n";
print "Seno = ".sin($Angulo)."<BR>\n";

Expected result:
cos(Angulo) = 0
cos(Pi/2) = 0
Angulo = 1.5707963267949
Coseno = 0
Cos = 0
Seno = 1

Actual result:
cos(Angulo) = 6.1230317691119E-017
cos(Pi/2) = 6.1230317691119E-017
Angulo = 1.5707963267949
Coseno = 6.1230317691119E-017
Cos = 0
Seno = 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-02 08:39 UTC]
Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.
Thank you for your interest in PHP.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Feb 08 16:05:48 2023 UTC