Fix a divide by 0 bug in `root()` (lib2.bc)

This commit is contained in:
Gavin Howard 2021-03-02 11:42:24 -07:00
parent 1818b894e0
commit 0c1abbe6df
Signed by: gavin
GPG Key ID: C08038BDF280D33E
3 changed files with 13 additions and 1 deletions

View File

@ -110,7 +110,7 @@ define root(x,n){
if(n<0)sqrt(n)
n=n$
if(n==0)x/n
if(n==1)return x
if(x==0||n==1)return x
if(n==2)return sqrt(x)
s=scale
scale=0

View File

@ -84,6 +84,12 @@ cbrt(27)
cbrt(-27)
cbrt(4096)
cbrt(-4096)
root(0, 3)
root(0, 4)
root(0, 5)
root(0.0000000000000, 3)
root(0.0000000000000, 4)
root(0.0000000000000, 5)
root(16, 4)
root(3125, 5)
root(-3125, 5)

View File

@ -84,6 +84,12 @@
-3.00000000000000000000
16.00000000000000000000
-16.00000000000000000000
0
0
0
0
0
0
2.00000000000000000000
5.00000000000000000000
-5.00000000000000000000