Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Roave/no-floaters
:mag_right: static analysis rules to prevent IEEE-754 floating point errors
https://github.com/Roave/no-floaters
Last synced: 3 months ago
JSON representation
:mag_right: static analysis rules to prevent IEEE-754 floating point errors
- Host: GitHub
- URL: https://github.com/Roave/no-floaters
- Owner: Roave
- License: mit
- Created: 2019-01-08T07:59:33.000Z (almost 6 years ago)
- Default Branch: 1.12.x
- Last Pushed: 2024-05-22T22:23:25.000Z (5 months ago)
- Last Synced: 2024-05-22T23:30:09.637Z (5 months ago)
- Language: PHP
- Homepage:
- Size: 940 KB
- Stars: 206
- Watchers: 7
- Forks: 11
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# roave/no-floaters
![`roave/no-floaters`](logo/roave-no-floaters.png)
[![Latest Stable Version](https://poser.pugx.org/roave/no-floaters/v/stable.png)](https://packagist.org/packages/roave/no-floaters)
This library is a [PHPStan](https://github.com/phpstan/phpstan) plugin
that disallows:* declaration of `float` properties
* `float` method parameters
* `float` method return types
* assignment of `float` values to variables or propertiesThe reason for this restriction is that rounding errors coming
from floating point arithmetic operations are not acceptable in
certain business logic scenario, such as dealing with money,
evaluating exam results, rocket science, etc.An example of such problems can be seen with the following typical
[example](https://3v4l.org/MJqJe):```php
var_dump((0.7 + 0.1) === 0.8); // output: bool(false)
```This can mean no trouble at all, or a lot of trouble, depending
on how many numbers you are running through your system, so it
is advisable to avoid `float` for domains where rounding can
potentially lead to trouble.`float` is still perfectly acceptable in many programming contexts,
and this ruleset should only be applied where it is critical not
to introduce rounding errors.## Installation
```sh
composer require --dev roave/no-floaters
```## Configuration
In your `phpstan.neon` configuration, add following section:
```neon
includes:
- vendor/roave/no-floaters/rules.neon
```Optionally, you can configure the library to disallow any
`float`-producing expression at all, by adding following to your
`phpstan.neon`:```neon
parameters:
disallowFloatsEverywhere: true
```If the above is enabled, given the following `example-file.php`
contents:```php
for consulting/support.