Skip to content

bypassflow/rules-number-bcmath

Repository files navigation

bypassflow/rules-number-bcmath

bypassflow/rules-number-bcmath は、BCMathを使って大きな整数や高精度な10進小数を厳密比較するルールパッケージです。 PHPの整数範囲や浮動小数の丸めに依存させたくない値を、bypassflow/rulesRuleInterface として扱えます。

Requirements

  • PHP 8.5以上
  • ext-bcmath
  • bypassflow/rules
  • bypassflow/number-bcmath

Installation

composer require bypassflow/rules-number-bcmath

Quick Start

<?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'); // true

主要API

  • ExactIntegerMin 整数値が下限以上であることを検証します。
  • ExactIntegerMax 整数値が上限以下であることを検証します。
  • ExactIntegerRange 整数値が閉区間に含まれることを検証します。
  • ExactDecimalMin 10進小数値が下限以上であることを検証します。
  • ExactDecimalMax 10進小数値が上限以下であることを検証します。
  • ExactDecimalRange 10進小数値が閉区間に含まれることを検証します。

入力値

整数ルールは int と整数文字列を受け付けます。 10進小数ルールは int と10進小数文字列を受け付けます。 float と指数表記は、厳密比較の前提を崩しやすいため検証失敗として扱います。

補助文書

詳しい利用例は USAGE.md を参照してください。

About

BCMath依存の厳密な数値比較ルールを提供します。

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages