You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A fluent [bcmath](https://php.net/bcmath) based _Helper_ to handle high precision calculus in base 10 with a rather strict approach (want precision for something right?).
6
6
It does not try to be smart and just fails without `bcmath`, but it does auto detect [GMP](https://php.net/GMP) for faster base conversions.
@@ -19,7 +19,7 @@ composer require "fab2s/math"
19
19
20
20
## Prerequisites
21
21
22
-
`Math` requires [bcmath](https://php.net/bcmath), [GMP](https://php.net/GMP) is autodetected and used when available for faster base conversions (up to 62).
22
+
`Math` requires [bcmath](https://php.net/bcmath), [GMP](https://php.net/GMP) is auto-detected and used when available for faster base conversions (up to 62).
23
23
24
24
## In practice
25
25
@@ -110,7 +110,7 @@ Doing so is actually faster than casting a pre-existing instance to string becau
110
110
Arguments should be string or `Math`, but it is _ok_ to use integers up to `INT_(32|64)`.
111
111
112
112
**DO NOT** use `floats` as casting them to `string` may result in local dependent format, such as using a coma instead of a dot for decimals or just turn them exponential notation which is not supported by bcmath.
113
-
The way floats are handled in general and by PHP in particular is the very the reason why `bcmath` exists, so even if you trust your locale settings, using floats still kinda defeats the purpose of using such lib.
113
+
The way floats are handled in general and by PHP in particular is the very reason why `bcmath` exists, so even if you trust your locale settings, using floats still kinda defeats the purpose of using such lib.
$number->setPrecision(14); // will use precision 14 for any further calculations
127
127
```
128
128
129
+
## Laravel
130
+
131
+
For those using [Laravel](https://laravel.com/), `Math` comes with a Laravel caster: [MathCaster](./src/Laravel/MathCast.php) which you can use to directly cast your model properties.
132
+
133
+
````php
134
+
use fab2s\Math\Laravel\MathCast;
135
+
136
+
class MyModel extends Model
137
+
{
138
+
protected $casts = [
139
+
'not_nullable' => MathCast::class,
140
+
'nullable' => MathCast::class . ':nullable',
141
+
];
142
+
}
143
+
144
+
$model = new MyModel;
145
+
146
+
$model->not_nullable = 41;
147
+
$model->not_nullable->add(1)->eq(42); // true
148
+
149
+
$model->not_nullable = null; // throw a NotNullableException
150
+
151
+
$model->nullabe = null; // is ok
152
+
153
+
````
154
+
129
155
## Requirements
130
156
131
-
`Math` is tested against php 8.1 and 8.2
157
+
`Math` is tested against php 8.1 and 8.2. Additionally, MathCast is tested against Laravel 10 and 11.
0 commit comments