|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74451 Sine values exceed 1
Submitted: 2017-04-16 03:39 UTC Modified: 2017-04-30 04:22 UTC
From: m_sun at mail dot ru Assigned:
Status: No Feedback Package: Math related
PHP Version: 5.6.30 OS: Alpine Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
34 - 5 = ?
Subscribe to this entry?

 [2017-04-16 03:39 UTC] m_sun at mail dot ru
Absolute values of sine and cosine functions may somehow exceed 1 when argument is more then 2 * pi

Test script:
$sin = sin(60.0); // $sin contains 19880855899899 now
$sin = sin (fmod (60.0, M_PI * 2)); // Gives correct result now

Actual result:
Radian	Degrees	Sin	Cos
60	3,437.75	19880855899899	-84637265064481
60.1	3,443.48	20318846900770	-86648047391510
60.2	3,449.21	20765725188326	-88703090857283


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-16 10:17 UTC]
-Status: Open +Status: Feedback
 [2017-04-16 10:17 UTC]
I can't reproduce what you're reporting:

Please can you provide an actual runnable reproduce script.
 [2017-04-16 11:16 UTC] m_sun at mail dot ru
You are right: the problem can't be reproduced in a testbed for PHP 5.6.30. I suppose there is a problem in realization (librariess are compiled against musl libc on Alpine Linux) or a hardware issue...
Thank you danack at php dot com
  $start = 60.0;
  $a = $start;
  $da = 0.1;
  $target = M_PI + $start;
  $tab = array();
  while ($a < $target) {
    $item['rad'] = $a;
    $item['deg'] = number_format(rad2deg($a), 2);
    $item['sin'] = sin($a);
    $item['cos'] = cos($a);
    $tab[] = $item;
    $a += $da;
table, td, th {
  border:1px solid #000;
  <?php foreach($tab as $item): ?>
      <td><?= $item['rad'] ?></td>
      <td><?= $item['deg'] ?></td>
      <td><?= $item['sin'] ?></td>
      <td><?= $item['cos'] ?></td>
  <?php endforeach; ?>
 [2017-04-16 18:21 UTC]
Does a simple
  #include <math.h>
  #include <stdio.h>
  void main(void) { printf("%f\n", sin(60.0)); }
work correctly?
 [2017-04-16 22:07 UTC] m_sun at mail dot ru
Standard libc sin() works just fine. Bc also gives correct result on the machine in question:
echo 's(60)' | bc -l

But problem with php is still there:
php5 -r 'echo sin(60) . "\n";'
output is 19880855899899

Right now I use a workaround
echo sin(fmod(60, M_PI * 2));
 [2017-04-16 22:18 UTC] m_sun at mail dot ru
PS: Seems like this is not a hardware issue, neither musl libc. Result is always the same even after restarting php5-fpm. Alpine Linux uses grsec patch and loads binaries in arbitrary memory addresses on each start.
I additionally posted a bug report on Alpine Linux board.
 [2017-04-30 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Dec 09 16:01:27 2023 UTC