|
3 | 3 | import assert from 'assert' |
4 | 4 | import { approxEqual, approxDeepEqual } from '../../../../tools/approx.js' |
5 | 5 | import math from '../../../../src/defaultInstance.js' |
| 6 | +import { |
| 7 | + createBigNumberPhi |
| 8 | +} from '../../../../src/utils/bignumber/constants.js' |
6 | 9 | const bignumber = math.bignumber |
7 | 10 | const gamma = math.gamma |
8 | 11 |
|
@@ -68,34 +71,53 @@ describe('gamma', function () { |
68 | 71 | assert.deepStrictEqual(gamma(bignumber(-2)).toString(), 'Infinity') |
69 | 72 | assert.ok(gamma(bignumber(-Infinity)).isNaN()) |
70 | 73 | }) |
71 | | - /* |
72 | | - it('should calculate the gamma of a rational bignumber', function () { |
73 | | - assert.deepStrictEqual(gamma(bignumber(0.125)), bignumber('7.5339415987976')) |
74 | | - assert.deepStrictEqual(gamma(bignumber(0.25)), bignumber('3.62560990822191')) |
75 | | - assert.deepStrictEqual(gamma(bignumber(0.5)), bignumber('1.77245385090552')) |
76 | | - assert.deepStrictEqual(gamma(bignumber(1.5)), bignumber('0.886226925452758')) |
77 | | - assert.deepStrictEqual(gamma(bignumber(2.5)), bignumber('1.32934038817914')) |
78 | | -
|
79 | | - const bigmath = math.create({ precision: 15 }) |
80 | | - assert.deepStrictEqual(bigmath.gamma(bignumber(30.5)), '4.82269693349091e+31') |
81 | 74 |
|
82 | | - bigmath.config({ precision: 13 }) |
83 | | - assert.deepStrictEqual(bigmath.gamma(bignumber(-1.5)), bigmath.bignumber('2.363271801207')) |
84 | | - assert.deepStrictEqual(gamma(bignumber(-2.5)), bignumber('-0.9453087205')) |
| 75 | + it('should calculate the gamma of a rational bignumber', function () { |
| 76 | + assert.deepStrictEqual(gamma(bignumber(0.125)), bignumber('7.533941598798')) |
| 77 | + assert.deepStrictEqual(gamma(bignumber(0.25)), bignumber('3.625609908222')) |
| 78 | + // gamma(n + 1/2) are special values, so always return lots of digits |
| 79 | + approxEqual(gamma(bignumber(0.5)), bignumber('1.77245385090552')) |
| 80 | + approxEqual(gamma(bignumber(1.5)), bignumber('0.886226925452758')) |
| 81 | + approxEqual(gamma(bignumber(2.5)), bignumber('1.32934038817914')) |
| 82 | + |
| 83 | + const bigmath = math.create({ relTol: 1e-15, absTol: 1e-18, precision: 24 }) |
| 84 | + const bigresult = bigmath.gamma(bigmath.bignumber(30.5)) |
| 85 | + approxEqual(bigresult, bigmath.bignumber('4.82269693349091e+31')) |
| 86 | + assert.deepStrictEqual( |
| 87 | + bigmath.gamma(bigmath.bignumber(1).div(3)), |
| 88 | + bigmath.bignumber('2.678938534707748')) |
| 89 | + |
| 90 | + bigmath.config({ relTol: 1e-13, absTol: 1e-16, precision: 18 }) |
| 91 | + approxEqual( |
| 92 | + bigmath.gamma(bigmath.bignumber(-1.5)), |
| 93 | + bigmath.bignumber('2.363271801207')) |
| 94 | + assert.deepStrictEqual( |
| 95 | + bigmath.gamma(bigmath.bignumber(0.2)), |
| 96 | + bigmath.bignumber('4.5908437119988')) |
| 97 | + |
| 98 | + bigmath.config({ relTol: 1e-300, absTol: 1e-310, precision: 500 }) |
| 99 | + assert.deepStrictEqual( |
| 100 | + bigmath.gamma(bigmath.bignumber(2).div(3)), |
| 101 | + bigmath.bignumber('1.354117939426400416945288028154513785519327266056793698394022467963782965401742541675834147952972911106434823610033058854142261552586211826607191148114322833434155915620917505682592366523385211910858011501770153617023853945368317754599736504155930691384228034622762716150366499013846393144654597536751') |
| 102 | + ) |
| 103 | + approxEqual(gamma(bignumber(-2.5)), bignumber('-0.9453087205')) |
85 | 104 | }) |
86 | 105 |
|
87 | 106 | it('should calculate the gamma of an irrational bignumber', function () { |
88 | | - assert.deepStrictEqual(gamma(bigUtil.phi(math.precision).neg()), bignumber('2.3258497469')) |
89 | | - assert.deepStrictEqual(gamma(bigUtil.phi(math.precision)), bignumber('0.895673151705288')) |
| 107 | + const phi = createBigNumberPhi(math.BigNumber) |
| 108 | + assert.deepStrictEqual(gamma(phi.neg()), bignumber('2.325849746874')) |
| 109 | + assert.deepStrictEqual(gamma(phi), bignumber('0.895673151705')) |
90 | 110 |
|
91 | | - assert.deepStrictEqual(gamma(bigUtil.pi(20)), bignumber('2.28803779534003')) |
92 | | - assert.deepStrictEqual(gamma(bigUtil.e(math.precision)), bignumber('1.56746825577405')) |
| 111 | + const pi = math.acos(math.bignumber(-1)) |
| 112 | + assert.deepStrictEqual(gamma(pi), bignumber('2.2880377953400')) |
| 113 | + const bige = math.exp(math.bignumber(1)) |
| 114 | + assert.deepStrictEqual(gamma(bige), bignumber('1.5674682557740')) |
93 | 115 |
|
94 | 116 | const bigmath = math.create({ number: 'BigNumber' }) |
95 | | - assert.deepStrictEqual(gamma(bigmath.SQRT2), bignumber('0.886581428719259')) |
96 | | - assert.deepStrictEqual(gamma(bigmath.SQRT2.neg()), bignumber('2.59945990753')) |
| 117 | + assert.deepStrictEqual(gamma(bigmath.SQRT2), bignumber('0.886581428719')) |
| 118 | + assert.deepStrictEqual(gamma(bigmath.SQRT2.neg()), bignumber('2.599459907525')) |
97 | 119 | }) |
98 | | -*/ |
| 120 | + |
99 | 121 | it('should calculate the gamma of an imaginary unit', function () { |
100 | 122 | approxDeepEqual(gamma(math.i), math.complex(-0.154949828301810685124955130, |
101 | 123 | -0.498015668118356042713691117)) |
|
0 commit comments