Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add de facto standard hyperbolic arithmetic functions #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/index_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,12 @@ <h2>9.3 Other arithmetic functors</h2>
<li>acos/1.</li>
<li>atan2/2.</li>
<li>tan/1.</li>
<li>acosh/1.</li>
<li>asinh/1.</li>
<li>atanh/1.</li>
<li>cosh/1.</li>
<li>sinh/1.</li>
<li>tanh/1.</li>
<li>pi/0.</li>
</ol>
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/docs/content.index_status.template
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ The ProscriptLS aspiration includes implementing most of ISO Prolog and some add
<li>acos/1.</li>
<li>atan2/2.</li>
<li>tan/1.</li>
<li>acosh/1.</li>
<li>asinh/1.</li>
<li>atanh/1.</li>
<li>cosh/1.</li>
<li>sinh/1.</li>
<li>tanh/1.</li>
<li>pi/0.</li>
</ol>
</div>
Expand Down
22 changes: 22 additions & 0 deletions src/engine/foreign.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down