Skip to content

Commit

Permalink
Improve the root and cbrt API's
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Howard committed Oct 30, 2019
1 parent ec42996 commit 8c01a79
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions gen/lib2.bc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ define l2(x){return log(x,2)}
define l10(x){return log(x,A)}
define root(x,n){
auto s,m,r,q,p
if(n<0)sqrt(n)
n=abs(n)$
if(n==0)x/n
if(n==1)return x
Expand Down
4 changes: 2 additions & 2 deletions manuals/bc.1
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,10 @@ Returns the cube root of \fBx\fR\.
.
.TP
\fBroot(x, n)\fR
Calculates the truncated absolute value of \fBn\fR, \fBr\fR, and returns the \fBr\fRth root of \fBx\fR to the current \fBscale\fR\.
Calculates the truncated value of \fBn\fR, \fBr\fR, and returns the \fBr\fRth root of \fBx\fR to the current \fBscale\fR\.
.
.IP
If \fBn\fR is \fB0\fR, this raises an error and causes bc(1) to reset (see the RESET section)\. It also raises an error and causes bc(1) to reset if \fBn\fR is even and \fBx\fR is negative\.
If \fBr\fR is \fB0\fR or negative, this raises an error and causes bc(1) to reset (see the RESET section)\. It also raises an error and causes bc(1) to reset if \fBr\fR is even and \fBx\fR is negative\.
.
.TP
\fBpi(p)\fR
Expand Down
10 changes: 5 additions & 5 deletions manuals/bc.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -848,12 +848,12 @@ The extended library is a **non-portable extension**.
Returns the cube root of `x`.

* `root(x, n)`:
Calculates the truncated absolute value of `n`, `r`, and returns the `r`th
root of `x` to the current `scale`.
Calculates the truncated value of `n`, `r`, and returns the `r`th root of
`x` to the current `scale`.

If `n` is `0`, this raises an error and causes bc(1) to reset (see the RESET
section). It also raises an error and causes bc(1) to reset if `n` is even
and `x` is negative.
If `r` is `0` or negative, this raises an error and causes bc(1) to reset
(see the RESET section). It also raises an error and causes bc(1) to reset
if `r` is even and `x` is negative.

* `pi(p)`:
Returns `pi` to `p` decimal places.
Expand Down
2 changes: 2 additions & 0 deletions tests/bc/errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ sqrt(-1)
0.000000%0.00000000
root(-15, 4)
root(5, 0)
root(13, -5)
root(1548, 0)
scale = 10000000000000000000000000000000000
obase += 999999999999999999999999999999999999999999999999999999999999999999999999
ibase *= 9999999999999999999999999999999999999999999999999999999999999.9
Expand Down

0 comments on commit 8c01a79

Please sign in to comment.