php.net |  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
 [2005-02-02 04:16 UTC] thiago_mata at yahoo dot com dot br
Description:
------------
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-02 08:39 UTC] derick@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 10:01:29 2024 UTC