Closed AlienKevin closed 3 years ago
test.js
const Decimal = require('decimal.js');
const c = new Decimal(1).cos();
console.log(c.toString());
$ node test
0.5403023058681397174
For me to be able to help you, you need to provide more details about the JavaScript environment and code context. This library does not make precision
a read-only property of Decimal
.
It seems that the issue "Exception-safety of methods that temporarily mutate settings" is still not addressed and the cosine function is still modifying the global Decimal constructor which throws a TypeError under strict mode.
No, it doesn't normally throw an error.
If you want to try an amended version of the library that does not temporarily mutate settings, but is not as well tested, try
I just found out why the error happens. My project is compiled from TypeScript so all export properties are wrapped in Object.defineProperty
which automatically sets the writable
attribute of objects defined inside to false
. Hence the TypeError when decimal.js tries to reassign precision.
Here's the line that causes the problem:
Object.defineProperty(exports, "__esModule", { value: true });
This is not a decimal.js problem. However, do you know any workaround for people using TypeScript?
Issue
When I call
new Decima(1).cos()
, node outputs the following error message:Error Location
The error happens in the line below in
P.cosine
function when I run the debugger:Temporary Solution
After I removed the
'use strict';
at the top ofdecimal.js
, the error goes away.Related issue
It seems that the issue "Exception-safety of methods that temporarily mutate settings" is still not addressed and the
cosine
function is still modifying the globalDecimal
constructor which throws a TypeError under strict mode. Also, by extension all trig functions includingsin
,cos
,tan
,asin
,acos
,atan
throws TypeError for assigning to readonly 'precision' property.