php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63476 Unexpected output when using log() function results
Submitted: 2012-11-09 20:55 UTC Modified: 2012-11-10 17:18 UTC
From: ringtail dot jack at gmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.3.18 OS: Linux Mint 11
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ringtail dot jack at gmail dot com
New email:
PHP Version: OS:

 

 [2012-11-09 20:55 UTC] ringtail dot jack at gmail dot com
Description:
------------
Using the modulus operator with the results of a call to log(N, 10) produces unexpected results when N % 3 = 0.

Other arithmetic operations result as expected.

Equivalent operations using a call to log10(N) rather than log(N, 10) result as expected.

Using echo to display log() results will display the correct value. However, passing it through printf or sprintf will print or return the correct value minus 1.

[ Note: phpinfo() on my computer reports a PHP version of 5.3.5-1ubuntu7.11. I selected what seemed to be the closest version available in the web form. ]

Test script:
---------------
$exp = 15;
$n = pow(10, $exp);
$base = 10;
$log = log($n, $base);
echo "log: ".$log."\n";
echo "log % 3: ".$log % 3 ."\n";
echo "log via sprintf: ".sprintf('%d', $log)."\n";
$log = log10($n);
echo "log10: ".$log."\n";
echo "log10 % 3: ".$log % 3 ."\n";
echo "log10 via sprintf: ".sprintf('%d', $log)."\n";

Expected result:
----------------
log: 15
log % 3: 0
log via sprintf: 15
log10: 15
log10 % 3: 0
log10 via sprintf: 15

Actual result:
--------------
log: 15
log % 3: 2
log via sprintf: 14
log10: 15
log10 % 3: 0
log10 via sprintf: 15

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-10 17:18 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2012-11-10 17:18 UTC] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

log result is a float here. float is not accurate
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 03:01:28 2024 UTC