CodeSampleX

サンプル

brick/math 0.19.1: Construct and convert BigRational fractions, handle non-terminating decimal conversions with toScale, and navigate asymmetric mixed-type arithmetic in brick/math

検証済みサンプル — composer brick/math 0.19.1: Construct and convert BigRational fractions, handle non-terminating decimal conversions with toScale, and navigate…

sha256:b39a510dfa2b50e48cb4d90b401409435dcc53ffa14bdcfd57e27be2fa382a1c

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
2
ビルドした署名鍵
2
宣言された環境 php linux x64 php php composer

検証実行環境

環境 コントラクト ステージ 実行日
php 8 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · composer@1
2026-08-16
php 8 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · composer@1
2026-08-18

ケース

HOW
ゴール
Construct and convert BigRational fractions, handle non-terminating decimal conversions with toScale, and navigate asymmetric mixed-type arithmetic in brick/math
パッケージ
シンボル
  • Brick\Math\BigRational::ofFraction
  • Brick\Math\BigRational::toBigDecimal
  • Brick\Math\BigRational::toScale
  • Brick\Math\BigRational::power
環境
php
作成日
2026-08-16T08:29:22Z

コントラクト

  1. BigRational::of(1, 3) takes only 1 argument and silently evaluates to 1/1; fractions require ofFraction(1, 3) or of('1/3')
  2. BigRational::ofFraction(2, -4) eagerly normalizes to -1/2 with strictly positive BigInteger denominator
  3. BigRational::ofFraction(1, 0) throws brick/math's DivisionByZeroException implementing MathException, not native DivisionByZeroError
  4. toBigDecimal() on non-terminating rational 1/3 throws RoundingNecessaryException; terminating 1/4 returns 0.25
  5. toScale(2) on 1/3 without RoundingMode defaults to Unnecessary and throws; explicit RoundingMode produces 0.33
  6. BigRational::plus(BigInteger) succeeds (1/3 + 5 = 16/3), but BigInteger::plus(BigRational) and BigDecimal::plus(BigRational) throw RoundingNecessaryException
  7. BigRational::power(-2) inverts and exponentiates ((2/3)^-2 = 9/4), while BigInteger::power(-2) and BigDecimal::power(-2) throw InvalidArgumentException

ファイル

  • NOTES.md
  • composer.json
  • composer.lock
  • csx.json
  • src/RationalHelper.php
  • test/contract.php

ソースアーティファクトをダウンロード (tar.gz)

オリジンシーダー

csx-seed