diff options
| author | Stefan Eßer <se@FreeBSD.org> | 2023-10-30 09:10:24 +0000 |
|---|---|---|
| committer | Stefan Eßer <se@FreeBSD.org> | 2023-10-30 09:10:24 +0000 |
| commit | 0b4a06ab29a0da80f6cb5c99189054cb8e2f756c (patch) | |
| tree | 1b2285ec8b8b0405fb1937401045027f303ef5b7 /gen/lib2.bc | |
| parent | 8b83ef067441f6d3a4a55e92d1738724954a057c (diff) | |
vendor/bc: upgrade to version 6.7.2vendor/bc/6.7.2
This update improves the implementation of the power function p() and
adds 3 new functions to the extended math library: min(), max(), and
i2rand().
Diffstat (limited to 'gen/lib2.bc')
| -rw-r--r-- | gen/lib2.bc | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/gen/lib2.bc b/gen/lib2.bc index ba3f76b1803a..df51d0c07a8d 100644 --- a/gen/lib2.bc +++ b/gen/lib2.bc @@ -34,10 +34,34 @@ */ define p(x,y){ - auto a + auto a,i,s,z + if(y==0)return 1@scale + if(x==0){ + if(y>0)return 0 + return 1/0 + } a=y$ if(y==a)return(x^a)@scale - return e(y*l(x)) + z=0 + if(x<1){ + y=-y + a=-a + z=x + x=1/x + } + if(y<0){ + return e(y*l(x)) + } + i=x^a + s=scale + scale+=length(i)+5 + if(z){ + x=1/z + i=x^a + } + i*=e((y-a)*l(x)) + scale=s + return i@scale } define r(x,p){ auto t,n @@ -66,6 +90,14 @@ define f(n){ for(r=1;n>1;--n)r*=n return r } +define max(a,b){ + if(a>b)return a + return b +} +define min(a,b){ + if(a<b)return a + return b +} define perm(n,k){ auto f,g,s if(k>n)return 0 @@ -242,6 +274,15 @@ define frand(p){ return irand(A^p)>>p } define ifrand(i,p){return irand(abs(i)$)+frand(p)} +define i2rand(a,b){ + auto n,x + a=a$ + b=b$ + if(a==b)return a + n=min(a,b) + x=max(a,b) + return irand(x-n+1)+n +} define srand(x){ if(irand(2))return -x return x |
