Skip to content

Floating point bug in range operation on Apple Silicon hardware #14140

Closed
@judahnator

Description

Description

The following code:

<?php
print_r(range(-0.03, 0.03, 0.01));

Resulted in this output:

Array
(
    [0] => -0.03
    [1] => -0.02
    [2] => -0.01
    [3] => 1.7347234759768E-18
    [4] => 0.01
    [5] => 0.02
)

But I expected this output instead:

Array
(
    [0] => -0.03
    [1] => -0.02
    [2] => -0.01
    [3] => 0
    [4] => 0.01
    [5] => 0.02
    [6] => 0.03
)

I tested this on a few devices with my peers. Every x86 processor we tested worked as expected, but reliably got the erroneous result using different Apple M2 devices.

PHP Version

PHP 8.3.6

Operating System

Sonoma 14.4.1

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions