Exemple
Construct and convert BigRational fractions, handle non-terminating decimal conversions with toScale, and navigate asymmetric mixed-type arithmetic in brick/math
sha256:b39a510dfa2b50e48cb4d90b401409435dcc53ffa14bdcfd57e27be2fa382a1c
PUBLISHED
L3_CONTRACT_PASS
MIT-0
Cas
- Objectif
- Construct and convert BigRational fractions, handle non-terminating decimal conversions with toScale, and navigate asymmetric mixed-type arithmetic in brick/math HOW
- Paquets
- brick/math 0.19.1
- Environnement
- php
- Créé
- 2026-08-16T08:29:22Z
Contrat
- BigRational::of(1, 3) takes only 1 argument and silently evaluates to 1/1; fractions require ofFraction(1, 3) or of('1/3')
- BigRational::ofFraction(2, -4) eagerly normalizes to -1/2 with strictly positive BigInteger denominator
- BigRational::ofFraction(1, 0) throws brick/math's DivisionByZeroException implementing MathException, not native DivisionByZeroError
- toBigDecimal() on non-terminating rational 1/3 throws RoundingNecessaryException; terminating 1/4 returns 0.25
- toScale(2) on 1/3 without RoundingMode defaults to Unnecessary and throws; explicit RoundingMode produces 0.33
- BigRational::plus(BigInteger) succeeds (1/3 + 5 = 16/3), but BigInteger::plus(BigRational) and BigDecimal::plus(BigRational) throw RoundingNecessaryException
- BigRational::power(-2) inverts and exponentiates ((2/3)^-2 = 9/4), while BigInteger::power(-2) and BigDecimal::power(-2) throw InvalidArgumentException
Fichiers
- NOTES.md
- composer.json
- composer.lock
- csx.json
- src/RationalHelper.php
- test/contract.php
Télécharger l'artefact vérifié (tar.gz) — les octets exacts sur lesquels le contrat s'est exécuté
Seeder d'origine
Reçus de vérification
- php 8 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · composer@1 · 2026-08-16 · ed25519:d91480838ac982c9