Skip to content

Commit 99917a9

Browse files
Pablo1GustavoBenMorel
authored andcommitted
Remove duplicate nthRoot tests and add tightest Half* boundary cases
1 parent a7a2a73 commit 99917a9

2 files changed

Lines changed: 32 additions & 25 deletions

File tree

tests/BigDecimalTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3244,6 +3244,18 @@ public static function providerNthRoot(): Generator
32443244
['-17', 3, 0, RoundingMode::Down, '-2'],
32453245
['-17', 3, 0, RoundingMode::Up, '-3'],
32463246
['-17', 3, 0, RoundingMode::HalfUp, '-3'],
3247+
3248+
// Tightest possible Half* boundaries, where 2^n·|V| differs from (2·|t|+1)^n by ±1.
3249+
// V=43, n=3: 2^3·43 = 344 vs 7^3 = 343 (diff +1) → smallest "round up". ∛43 ≈ 3.5034.
3250+
['43', 3, 0, RoundingMode::Unnecessary, 'NTH_ROOT_NOT_EXACT'],
3251+
['43', 3, 0, RoundingMode::Down, '3'],
3252+
['43', 3, 0, RoundingMode::Up, '4'],
3253+
['43', 3, 0, RoundingMode::HalfUp, '4'],
3254+
// V=91, n=3: 2^3·91 = 728 vs 9^3 = 729 (diff -1) → smallest "round down". ∛91 ≈ 4.4979.
3255+
['91', 3, 0, RoundingMode::Unnecessary, 'NTH_ROOT_NOT_EXACT'],
3256+
['91', 3, 0, RoundingMode::Down, '4'],
3257+
['91', 3, 0, RoundingMode::Up, '5'],
3258+
['91', 3, 0, RoundingMode::HalfUp, '4'],
32473259
];
32483260

32493261
foreach ($tests as [$number, $n, $scale, $roundingMode, $expected]) {

tests/BigIntegerTest.php

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3939,31 +3939,26 @@ public static function providerNthRoot(): Generator
39393939
// 2^100 is exact.
39403940
['1267650600228229401496703205376', 100, RoundingMode::Unnecessary, '2'],
39413941

3942-
// ∛17 ≈ 2.5713
3943-
['17', 3, RoundingMode::Unnecessary, null],
3944-
['17', 3, RoundingMode::Down, '2'],
3945-
['17', 3, RoundingMode::Up, '3'],
3946-
['17', 3, RoundingMode::HalfUp, '3'],
3947-
// ∛16 ≈ 2.5198
3948-
['16', 3, RoundingMode::Unnecessary, null],
3949-
['16', 3, RoundingMode::Down, '2'],
3950-
['16', 3, RoundingMode::Up, '3'],
3951-
['16', 3, RoundingMode::HalfUp, '3'],
3952-
// ∛864 ≈ 9.5224
3953-
['864', 3, RoundingMode::Unnecessary, null],
3954-
['864', 3, RoundingMode::Down, '9'],
3955-
['864', 3, RoundingMode::Up, '10'],
3956-
['864', 3, RoundingMode::HalfUp, '10'],
3957-
// 8^¼ ≈ 1.6818
3958-
['8', 4, RoundingMode::Unnecessary, null],
3959-
['8', 4, RoundingMode::Down, '1'],
3960-
['8', 4, RoundingMode::Up, '2'],
3961-
['8', 4, RoundingMode::HalfUp, '2'],
3962-
// ∛-17 ≈ -2.5713
3963-
['-17', 3, RoundingMode::Unnecessary, null],
3964-
['-17', 3, RoundingMode::Down, '-2'],
3965-
['-17', 3, RoundingMode::Up, '-3'],
3966-
['-17', 3, RoundingMode::HalfUp, '-3'],
3942+
// Tightest possible Half* boundaries, where 2^n·|V| differs from (2·|t|+1)^n by ±1.
3943+
// V=43, n=3: 2^3·43 = 344 vs 7^3 = 343 (diff +1) → smallest "round up". ∛43 ≈ 3.5034.
3944+
['43', 3, RoundingMode::Unnecessary, null],
3945+
['43', 3, RoundingMode::Down, '3'],
3946+
['43', 3, RoundingMode::Up, '4'],
3947+
['43', 3, RoundingMode::HalfUp, '4'],
3948+
['-43', 3, RoundingMode::Unnecessary, null],
3949+
['-43', 3, RoundingMode::Down, '-3'],
3950+
['-43', 3, RoundingMode::Up, '-4'],
3951+
['-43', 3, RoundingMode::HalfUp, '-4'],
3952+
3953+
// V=91, n=3: 2^3·91 = 728 vs 9^3 = 729 (diff -1) → smallest "round down". ∛91 ≈ 4.4979.
3954+
['91', 3, RoundingMode::Unnecessary, null],
3955+
['91', 3, RoundingMode::Down, '4'],
3956+
['91', 3, RoundingMode::Up, '5'],
3957+
['91', 3, RoundingMode::HalfUp, '4'],
3958+
['-91', 3, RoundingMode::Unnecessary, null],
3959+
['-91', 3, RoundingMode::Down, '-4'],
3960+
['-91', 3, RoundingMode::Up, '-5'],
3961+
['-91', 3, RoundingMode::HalfUp, '-4'],
39673962
];
39683963

39693964
foreach ($tests as [$number, $n, $roundingMode, $expected]) {

0 commit comments

Comments
 (0)