From 128106bdfdbf6ca032e855ace5c6a9503aaf5835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 24 Jan 2022 09:57:41 +0100 Subject: [PATCH] Enhancement: Use PHP_FLOAT_EPSILON --- CHANGELOG.md | 1 + psalm-baseline.xml | 3 +++ src/FloatProvider.php | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a8a1cb..b2af865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ For a full diff see [`1.0.0...main`][1.0.0...main]. ### Changed - Dropped support for PHP 7.3 ([#21]), by [@localheinz] +- Started using `PHP_FLOAT_EPSILON` instead of `0.1` in `FloatProvider` ([#23]), by [@localheinz] ## [`1.0.0`][1.0.0] diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 3368bca..d28e4b2 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -13,6 +13,9 @@ + + -1 * \PHP_FLOAT_EPSILON + \Generator<string, array{0: float}> \Generator<string, array{0: float}> diff --git a/src/FloatProvider.php b/src/FloatProvider.php index ae0d82b..d7a6870 100644 --- a/src/FloatProvider.php +++ b/src/FloatProvider.php @@ -91,11 +91,11 @@ private static function values(): array $faker = self::faker(); return [ - 'float-less-than-minus-one' => -0.01 - $faker->randomFloat(null, 1), + 'float-less-than-minus-one' => (-1 * \PHP_FLOAT_EPSILON) - $faker->randomFloat(null, 1), 'float-minus-one' => -1.0, 'float-zero' => 0.0, 'float-plus-one' => 1.0, - 'float-greater-than-plus-one' => 0.01 + $faker->randomFloat(null, 1), + 'float-greater-than-plus-one' => \PHP_FLOAT_EPSILON + $faker->randomFloat(null, 1), ]; } }