quaeratin
Version:
An extended precision floating point library (as per Shewchuk) - precision only limited by overflow / underflow
101 lines (86 loc) • 2.7 kB
text/typescript
import { expect, assert } from 'chai';
import { describe } from 'mocha';
import { fastExpansionSum } from '../../src/index.js';
import { isNonOverlappingAll } from '../../src/index.js';;
import { isValid } from '../helpers/is-valid.js';
/**
*
* @param e
* @param f
* @param res
*/
function check(e: number[], f: number[], res: number[]) {
assert(
isNonOverlappingAll(e),
'The first summand should not be an overlapping expansion.'
);
assert(
isNonOverlappingAll(f),
'The second summand should not be an overlapping expansion.'
);
let result = fastExpansionSum(e,f);
assert(
isValid(result),
'The result of expansionSum should be a non-overlapping, non-adjacent expansion'
);
}
describe('fast expansion sum', function() {
it('should calculate some expansion sums correctly',
function() {
check(
[-2.7755575615628914e-17, 0.30000000000000004], // 0.3
[-2.7755575615628914e-17, 0.30000000000000004], // + 0.3
[-5.551115123125783e-17, 0.6000000000000001] // = 0.6
);
check(
[], // 1
[], // + 2
[] // = 3
);
check(
[], // 0.1
[], // + 0.2
[-2.7755575615628914e-17, 0.30000000000000004] // = 0.3
);
check(
[],
[],
[
6.812735744013041e-107,
3.1e-90,
-2.1716258580568247e-85,
4.02e-69
]
);
check(
[],
[],
[
-3.678877301767042e-106,
3.01e-89,
-2.1716258580568247e-85,
4.02e-69
]
);
check(
[],
[],
[]
);
check(
[],
[],
[
-6.034492101807179e-108,
-1.3875858987879488e-97,
-1.1184029171647343e-87,
1.772767559313363e-77,
2.848982182572856e-67,
5.08454808684856e-57,
-3.8509382198042257e-47,
-1.2276606139947577e-37,
-2.428690697334946e-27,
9.990000000999e-11]
);
});
});