1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2026-09-23 12:24:47 +00:00

Fix asin losing precision near x = 1

This commit is contained in:
apoorva-01
2026-07-10 00:17:54 +05:30
parent 1a6e845004
commit 02f1e51c3b
3 changed files with 10 additions and 2 deletions

View File

@@ -936,7 +936,8 @@
Ctor.precision = pr + 6; Ctor.precision = pr + 6;
Ctor.rounding = 1; Ctor.rounding = 1;
x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan(); // See https://github.com/MikeMcl/decimal.js/issues/249
x = x.div(new Ctor(1).minus(x).times(new Ctor(1).plus(x)).sqrt().plus(1)).atan();
Ctor.precision = pr; Ctor.precision = pr;
Ctor.rounding = rm; Ctor.rounding = rm;

View File

@@ -932,7 +932,8 @@ P.inverseSine = P.asin = function () {
Ctor.precision = pr + 6; Ctor.precision = pr + 6;
Ctor.rounding = 1; Ctor.rounding = 1;
x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan(); // See https://github.com/MikeMcl/decimal.js/issues/249
x = x.div(new Ctor(1).minus(x).times(new Ctor(1).plus(x)).sqrt().plus(1)).atan();
Ctor.precision = pr; Ctor.precision = pr;
Ctor.rounding = rm; Ctor.rounding = rm;

View File

@@ -69,6 +69,12 @@ T('asin', function () {
t('-0.5110799', 65, 2, '-0.53644070128325494453237503822033662227949443391067147724566337039'); t('-0.5110799', 65, 2, '-0.53644070128325494453237503822033662227949443391067147724566337039');
t('-0.579334355419195148', 31, 3, '-0.617911801796609232511609252874'); t('-0.579334355419195148', 31, 3, '-0.617911801796609232511609252874');
// Arguments very close to 1. See https://github.com/MikeMcl/decimal.js/issues/249
t('0.9999999999999999995', 31, 1, '1.570796325794896619231321691598');
t('0.99999999999999999999995', 36, 6, '1.5707963267848966192313216916397514');
t('-0.9999999999999999999', 30, 4, '-1.57079632634768302373136375235');
t('0.99999999999999999999999999999', 45, 0, '1.57079632679489214709536669206035862375124724');
/* /*
t('0.63', 1, 5, '0.7'); t('0.63', 1, 5, '0.7');
t('-0.42', 4, 0, '-0.4335'); t('-0.42', 4, 0, '-0.4335');