From 631aae8d8807b9ce04ec7693bb1d2ba531d215f8 Mon Sep 17 00:00:00 2001 From: Paulo Moura Date: Fri, 10 Sep 2021 22:36:05 +0100 Subject: [PATCH] Add de facto standard hyperbolic arithmetic functions --- docs/index_status.html | 6 ++++++ src/docs/content.index_status.template | 6 ++++++ src/engine/foreign.js | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/docs/index_status.html b/docs/index_status.html index 8e7bbbf..02d2a01 100644 --- a/docs/index_status.html +++ b/docs/index_status.html @@ -695,6 +695,12 @@

9.3 Other arithmetic functors

  • acos/1.
  • atan2/2.
  • tan/1.
  • +
  • acosh/1.
  • +
  • asinh/1.
  • +
  • atanh/1.
  • +
  • cosh/1.
  • +
  • sinh/1.
  • +
  • tanh/1.
  • pi/0.
  • diff --git a/src/docs/content.index_status.template b/src/docs/content.index_status.template index 17ed954..58dac20 100644 --- a/src/docs/content.index_status.template +++ b/src/docs/content.index_status.template @@ -334,6 +334,12 @@ The ProscriptLS aspiration includes implementing most of ISO Prolog and some add
  • acos/1.
  • atan2/2.
  • tan/1.
  • +
  • acosh/1.
  • +
  • asinh/1.
  • +
  • atanh/1.
  • +
  • cosh/1.
  • +
  • sinh/1.
  • +
  • tanh/1.
  • pi/0.
  • diff --git a/src/engine/foreign.js b/src/engine/foreign.js index 5b206c2..b4d5091 100644 --- a/src/engine/foreign.js +++ b/src/engine/foreign.js @@ -164,6 +164,28 @@ function evaluate_expression(expression, evaluated) return evaluation_error("zero_divisor"); evaluated.value = round(v[0] /v[1]); } + // De facto standard + else if (name === "acosh" && arity === 1) + { + if (v[0] < 1) + return evaluation_error("undefined"); + evaluated.value = Math.acosh(v[0]); + } + else if (name === "asinh" && arity === 1) + evaluated.value = Math.asinh(v[0]); + else if (name === "atanh" && arity === 1) + { + if (v[0] >= 1) + return evaluation_error("undefined"); + evaluated.value = Math.atanh(v[0]); + } + else if (name === "cosh" && arity === 1) + evaluated.value = Math.cosh(v[0]); + else if (name === "sinh" && arity === 1) + evaluated.value = Math.sinh(v[0]); + else if (name === "tanh" && arity === 1) + evaluated.value = Math.tanh(v[0]); + // Others else if (name === "random" && arity === 1) { // random(L) returns integer X in range 0 =< X < L. let max = Math.floor(v[0]);