php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14966 round() function doesn't always work
Submitted: 2002-01-10 09:53 UTC Modified: 2002-04-01 04:21 UTC
From: rpb at community dot net dot uk Assigned:
Status: Closed Package: *Math Functions
PHP Version: 4.0.6 OS: Compaq Tru64 v4.0E
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 !
Your email address:
MUST BE VALID
Solve the problem:
16 + 17 = ?
Subscribe to this entry?

 
 [2002-01-10 09:53 UTC] rpb at community dot net dot uk
If PHP is built without complete ANSI C prototypes in scope the 'round' function can fail.

This is because the second argument to 'pow' in ext/standard/math.c:143 is an integer, and without prototypes it doesn't receive its implicit cast to a double, causing the 'pow' function to receive an undefined value on the stack.

The simple fix is to put an explicit (double) cast in:

    f = pow(10.0, (double)places);

A better fix might be to ensure that the ANSI version of the prototypes from <math.h> are always in scope, but that may be difficult to achieve across a wide variety of systems.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-10 09:54 UTC] rpb at community dot net dot uk
The same code is used in PHP 4.1.1, BTW.

 [2002-04-01 04:21 UTC] derick@php.net
Fixed in CVS, for both 4.2.x and 4.3.x

Derick
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 13:01:30 2024 UTC