Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

mod() fails for values >= .95 && < 1.0. #71

Open
@kevindecapite

Description

@kevindecapite

When I run the DecimalModTest::testFiniteFiniteMod() test using the following data sets, I get failures:

Data Provider

            # Extant passing tests.
            ['10', '3', '1'],
            ['34', '3.4', '0'],
            ['15.1615', '3.156156', '2.536876'],
            ['15.1615', '3.156156', '2.5369', 4],
            ['-3.4', '-2', '-1.4'],
            ['3.4', '-2', '-0.6'],
            ['-3.4', '2', '0.6'],

            # New tests.
            ['0.949', '1', '0.949'],
            ['0.95', '1', '0.95'],
            ['0.99', '1', '0.99'],
            ['1', '1', '0'],

Test Results

PHPUnit 6.5.14 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.2.10-1+ubuntu18.04.1+deb.sury.org+1
Configuration: /home/vagrant/www/php-bignumbers/phpunit.xml
Error:         No code coverage driver is available

........FF.                                                       11 / 11 (100%)

Time: 338 ms, Memory: 6.00MB

There were 2 failures:

1) DecimalModTest::testFiniteFiniteMod with data set #8 ('0.95', '1', '0.95')
-0.05 % 1 must be equal to 0.95, but was -0.05
Failed asserting that false is true.

/home/vagrant/www/php-bignumbers/tests/Decimal/DecimalModTest.php:37

2) DecimalModTest::testFiniteFiniteMod with data set #9 ('0.99', '1', '0.99')
-0.01 % 1 must be equal to 0.99, but was -0.01
Failed asserting that false is true.

/home/vagrant/www/php-bignumbers/tests/Decimal/DecimalModTest.php:37

However, when I run the 2 failing tests through PHP's native fmod(), I get expected results:

php > echo fmod(.95, 1);
0.95
php > echo fmod(.99, 1);
0.99
php > 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions