Skip to content

max/min return wrong value if signed (negative) zero #20221

@kkmuffme

Description

@kkmuffme

Description

The following code:

https://3v4l.org/JXU4T#v8.4.13

<?php
var_dump( min( round( -0.01 / 2, 0 ), 0 ) );
var_dump( max( round( -0.01 / 2, 0 ), 0 ) );

Resulted in this output:

int(0)
float(-0)

But I expected this output instead:

float(-0)
int(0)

For 99.9% of applications, this output is actually what people would expect however: (instead of -0)

float(0)
int(0)

so I guess it would make sense to also change that.

This does not have any impact on calculations or comparisons, this is purely visual but can lead to unexpected behavior if the returned number is used as a string (e.g. substr, strtok,...) since there suddenly is an additional character in front of the numbers.
This is especially unexpected, when the float is the result of float arithmetics, which can minimally negative numbers in some cases

PHP Version

8.4

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions