bypassflow/rules-number-bcmath は、BCMathを使って大きな整数や高精度な10進小数を厳密比較するルールパッケージです。
PHPの整数範囲や浮動小数の丸めに依存させたくない値を、bypassflow/rules の RuleInterface として扱えます。
- PHP 8.5以上
- ext-bcmath
- bypassflow/rules
- bypassflow/number-bcmath
composer require bypassflow/rules-number-bcmath<?php
use bypassflow\RulesNumberBcmath\Rule\Decimal\ExactDecimalRange;
use bypassflow\RulesNumberBcmath\Rule\Integer\ExactIntegerRange;
$integer_rule = new ExactIntegerRange(
'92233720368547758079223372036854775807',
'92233720368547758079223372036854775809',
);
$decimal_rule = new ExactDecimalRange('0.10000000000000000001', '0.10000000000000000003');
$integer_rule->validate('92233720368547758079223372036854775808'); // true
$decimal_rule->validate('0.10000000000000000002'); // trueExactIntegerMin整数値が下限以上であることを検証します。ExactIntegerMax整数値が上限以下であることを検証します。ExactIntegerRange整数値が閉区間に含まれることを検証します。ExactDecimalMin10進小数値が下限以上であることを検証します。ExactDecimalMax10進小数値が上限以下であることを検証します。ExactDecimalRange10進小数値が閉区間に含まれることを検証します。
整数ルールは int と整数文字列を受け付けます。
10進小数ルールは int と10進小数文字列を受け付けます。
float と指数表記は、厳密比較の前提を崩しやすいため検証失敗として扱います。
詳しい利用例は USAGE.md を参照してください。