# PHP_FLOAT_MIN is positive

- Thread: https://externals.io/message/105037
- Original archive: https://news-web.php.net/php.internals/105037
- Started by Benjamin Morel on 2019-04-03T09:51:50+00:00
- Messages: 10
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #105037 — Benjamin Morel — 2019-04-03T09:51:50+00:00

URL: https://externals.io/message/105037#105037

Hi internals,

I just used `PHP_FLOAT_MIN` for the first time, and was surprised that it is
the smallest **positive** number representable. Is this expected?

This is unlike PHP_INT_MIN, which is the absolute smallest representable
integer, and as such is negative:

echo PHP_INT_MIN; // -9223372036854775808
echo PHP_FLOAT_MIN; // 2.2250738585072E-308

If it is intended, maybe the doc
<https://www.php.net/manual/en/reserved.constants.php> should be clear
about this, at the moment it is just:

Smallest representable floating point number.


Which is confusing IMO.

Cheers,
Ben

---

## #105038 — Diogo Neves — 2019-04-03T10:27:17+00:00

URL: https://externals.io/message/105037#105038

It really don't make much sense:

<?php

var_dump( `PHP_FLOAT_MIN` < 0 );
var_dump( `PHP_INT_MIN` < 0 );

On Wed, Apr 3, 2019 at 10:52 AM Benjamin Morel <benjamin.morel@gmail.com>
wrote:

> Hi internals,
>
> I just used `PHP_FLOAT_MIN` for the first time, and was surprised that it is
> the smallest **positive** number representable. Is this expected?
>
> This is unlike PHP_INT_MIN, which is the absolute smallest representable
> integer, and as such is negative:
>
> echo PHP_INT_MIN; // -9223372036854775808
> echo PHP_FLOAT_MIN; // 2.2250738585072E-308
>
> If it is intended, maybe the doc
> <https://www.php.net/manual/en/reserved.constants.php> should be clear
> about this, at the moment it is just:
>
> Smallest representable floating point number.
>
>
> Which is confusing IMO.
>
> Cheers,
> Ben

---

## #105039 — Joe Watkins — 2019-04-03T11:47:55+00:00

URL: https://externals.io/message/105037#105039

2.2250738585072E-308

This is negative.

Cheers
Joe



> It really don't make much sense:
>
> <?php
>
> var_dump( `PHP_FLOAT_MIN` < 0 );
> var_dump( `PHP_INT_MIN` < 0 );
>
> On Wed, Apr 3, 2019 at 10:52 AM Benjamin Morel <benjamin.morel@gmail.com>
> wrote:
>
> > […]
> is
> > […]

---

## #105040 — Michael Wallner — 2019-04-03T11:50:25+00:00

URL: https://externals.io/message/105037#105040

> It really don't make much sense:
> 
> <?php
> 
> var_dump( `PHP_FLOAT_MIN` < 0 );
> var_dump( `PHP_INT_MIN` < 0 );
> 
> On Wed, Apr 3, 2019 at 10:52 AM Benjamin Morel <benjamin.morel@gmail.com>
> wrote:
> 
> > […]

FLT_MIN is the smallest real near 0. Are you looking for -FLT_MAX?
With IEEE754 floats, there are positive and negative zeros, so the range
above and below 0 is the same.


-- 
Regards,
Mike

---

## #105042 — come@opensides.be — 2019-04-03T12:28:36+00:00

URL: https://externals.io/message/105037#105042

Le mercredi 3 avril 2019, 13:47:55 CEST Joe Watkins a écrit :
> 2.2250738585072E-308
> 
> This is negative.
> 
> Cheers
> Joe

No it’s not.
It’s positive and close to 0.

Côme

---

## #105043 — Benjamin Morel — 2019-04-03T12:33:27+00:00

URL: https://externals.io/message/105037#105043

>
> It really don't make much sense:
> var_dump( `PHP_FLOAT_MIN` < 0 );
> var_dump( `PHP_INT_MIN` < 0 );


I quite agree that this is an inconsistency, but I guess that it's here to
stay now for BC reasons. What we can do is fix the doc.


> 2.2250738585072E-308
> This is negative.


It isn't, it is a strictly positive number with a negative exponent:
0.000(...)00022250738585072.

FLT_MIN is the smallest real near 0. Are you looking for -FLT_MAX?
> With IEEE754 floats, there are positive and negative zeros, so the range
> above and below 0 is the same.


It's interesting to know that - `PHP_FLOAT_MAX` is actually the smallest
representable floating point number (unlike - PHP_INT_MAX). It would be
great to document this as well.

I would propose to change the current documentation to:

 `PHP_FLOAT_MIN` (float)
> Smallest representable POSITIVE floating point number. If you need the
> smallest representable floating point number, use - PHP_FLOAT_MAX.
> Available as of PHP 7.2.0.


What we could also do is introduce another constant to represent the actual
smallest possible float, but its naming would likely conflict with
PHP_FLOAT_MIN, and it does not bring much value, so I'm not sure whether
this is a good idea.
We did introduce a `PHP_INT_MIN` though, even though it was available as ~
PHP_INT_MAX, so it's worth mentioning.

Thoughts?





> 
> > […]
> is
> > […]
>
> FLT_MIN is the smallest real near 0. Are you looking for -FLT_MAX?
> With IEEE754 floats, there are positive and negative zeros, so the range
> above and below 0 is the same.
>
>
> --
> Regards,
> Mike

---

## #105044 — Claude Pache — 2019-04-03T12:34:27+00:00

URL: https://externals.io/message/105037#105044

> Le 3 avr. 2019 à 11:51, Benjamin Morel <benjamin.morel@gmail.com> a écrit :
> 
> Hi internals,
> 
> I just used `PHP_FLOAT_MIN` for the first time, and was surprised that it is
> the smallest **positive** number representable. Is this expected?
> 
> This is unlike PHP_INT_MIN, which is the absolute smallest representable
> integer, and as such is negative:
> 
> echo PHP_INT_MIN; // -9223372036854775808
> echo PHP_FLOAT_MIN; // 2.2250738585072E-308
> 
> If it is intended, maybe the doc
> <https://www.php.net/manual/en/reserved.constants.php> should be clear
> about this, at the moment it is just:
> 
> Smallest representable floating point number.
> 
> 
> Which is confusing IMO.
> 
> Cheers,
> Ben

And in order to avoid further confusion, the constant ought to be renamed PHP_FLOAT_MIN_POSITIVE.

Rust named it correctly: https://doc.rust-lang.org/std/f64/constant.MIN_POSITIVE.html <https://doc.rust-lang.org/std/f64/constant.MIN_POSITIVE.html>

—Claude

---

## #105045 — Rowan Collins — 2019-04-03T12:40:00+00:00

URL: https://externals.io/message/105037#105045

On Wed, 3 Apr 2019 at 13:33, Benjamin Morel <benjamin.morel@gmail.com>
wrote:

> `PHP_FLOAT_MIN` (float)
> > […]
>


I'd avoid the word "smallest". `PHP_FLOAT_MIN` could be described as having
the "smallest magnitude", and -PHP_FLOAT as being "the largest magnitude,
but negative".

Perhaps:

> Closest representable positive floating point number to zero. If you need
the
> negative number furthest from zero, use -PHP_FLOAT_MAX.


Regards,
-- 
Rowan Collins
[IMSoP]

---

## #105047 — Joe Watkins — 2019-04-03T15:21:52+00:00

URL: https://externals.io/message/105037#105047

Thanks for explain.

Cheers
Joe



> On Wed, 3 Apr 2019 at 13:33, Benjamin Morel <benjamin.morel@gmail.com>
> wrote:
>
> > […]
>
>
> I'd avoid the word "smallest". `PHP_FLOAT_MIN` could be described as having
> the "smallest magnitude", and -PHP_FLOAT as being "the largest magnitude,
> but negative".
>
> Perhaps:
>
> > […]
> the
> > […]
>
>
> Regards,
> --
> Rowan Collins
> [IMSoP]

---

## #105049 — Sara Golemon — 2019-04-03T16:17:59+00:00

URL: https://externals.io/message/105037#105049

On Wed, Apr 3, 2019 at 4:52 AM Benjamin Morel <benjamin.morel@gmail.com>
wrote:

> I just used `PHP_FLOAT_MIN` for the first time, and was surprised that it is
> the smallest **positive** number representable. Is this expected?
>
> This is unlike PHP_INT_MIN, which is the absolute smallest representable
> integer, and as such is negative:
>
> echo PHP_INT_MIN; // -9223372036854775808
> echo PHP_FLOAT_MIN; // 2.2250738585072E-308
>
> If it is intended, maybe the doc
> <https://www.php.net/manual/en/reserved.constants.php> should be clear
> about this, at the moment it is just:
>
> Smallest representable floating point number.
>
>
> Which is confusing IMO.
>
> Perhaps confusing, but not without precedent.  See the C++ definitions for
::min() and ::lowest() on
https://en.cppreference.com/w/cpp/types/numeric_limits.

std::numeric_limits<double>::min() is a positive value very near zero.
std::numeric::limits<double>::lowest() is a very large negative value.

-Sara
