|
@@ -6,6 +6,7 @@ import { MultiType } from '../../typeSystem/multiType';
|
|
|
import { ArrayType } from '../../typeSystem/array_type';
|
|
|
import { Modes } from '../modes';
|
|
|
import { StoreValue } from '../store/value/store_value';
|
|
|
+import { ProcessorErrorFactory } from '../error/processorErrorFactory';
|
|
|
|
|
|
/**
|
|
|
* sin
|
|
@@ -79,12 +80,11 @@ export function createCosFun () {
|
|
|
}
|
|
|
|
|
|
export function createTanFun () {
|
|
|
- const tanFun = (sto, _) => {
|
|
|
+ const tanFun = function (sto, _) {
|
|
|
const x = sto.applyStore('x');
|
|
|
const angle = x.get().mod(360);
|
|
|
if(angle.eq(90) || angle.eq(270)) {
|
|
|
- // TODO better error message
|
|
|
- return Promise.reject("Tangent of "+x.get().toNumber()+"° is undefined.");
|
|
|
+ return Promise.reject(ProcessorErrorFactory.undefined_tanget_value(x.get().toNumber(), this.function_call_stack.pop()));
|
|
|
}
|
|
|
const result = Decimal.tan(convertToRadians(angle));
|
|
|
const temp = new StoreValue(Types.REAL, result);
|
|
@@ -101,8 +101,11 @@ export function createTanFun () {
|
|
|
}
|
|
|
|
|
|
export function createSqrtFun () {
|
|
|
- const sqrtFun = (sto, _) => {
|
|
|
+ const sqrtFun = function (sto, _) {
|
|
|
const x = sto.applyStore('x');
|
|
|
+ if(x.get().isNeg()) {
|
|
|
+ return Promise.reject(ProcessorErrorFactory.negative_sqrt_value(this.function_call_stack.pop()));
|
|
|
+ }
|
|
|
const result = x.get().sqrt();
|
|
|
const temp = new StoreValue(Types.REAL, result);
|
|
|
sto.insertStore("$", temp);
|
|
@@ -137,11 +140,10 @@ export function createPowFun () {
|
|
|
}
|
|
|
|
|
|
export function createLogFun () {
|
|
|
- const logFun = (sto, _) => {
|
|
|
+ const logFun = function (sto, _) {
|
|
|
const x = sto.applyStore('x');
|
|
|
if (x.get().isNegative()) {
|
|
|
- // TODO better error message
|
|
|
- return Promise.reject(new Error("the value passed to log function cannot be negative"));
|
|
|
+ return Promise.reject(ProcessorErrorFactory.negative_log_value(this.function_call_stack.pop()));
|
|
|
}
|
|
|
const result = Decimal.log10(x.get());
|
|
|
const temp = new StoreValue(Types.REAL, result);
|