diff options
Diffstat (limited to 'gen')
| -rw-r--r-- | gen/bc_help.txt | 4 | ||||
| -rw-r--r-- | gen/dc_help.txt | 4 | ||||
| -rw-r--r-- | gen/lib.bc | 2 | ||||
| -rw-r--r-- | gen/lib2.bc | 115 | ||||
| -rw-r--r-- | gen/strgen.c | 4 | ||||
| -rwxr-xr-x | gen/strgen.sh | 4 |
6 files changed, 54 insertions, 79 deletions
diff --git a/gen/bc_help.txt b/gen/bc_help.txt index 489b54a185f1..ce82d2677737 100644 --- a/gen/bc_help.txt +++ b/gen/bc_help.txt @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -37,7 +37,7 @@ usage: %s [options] [file...] bc is a command-line, arbitrary-precision calculator with a Turing-complete language. For details, use `man %s` or see the online documentation at -https://git.gavinhoward.com/gavin/bc/src/tag/%s/manuals/bc/%s.1.md. +https://github.com/gavinhoward/bc/tree/%s/manuals/bc/%s.1.md . This bc is compatible with both the GNU bc and the POSIX bc spec. See the GNU bc manual (https://www.gnu.org/software/bc/manual/bc.html) and bc spec diff --git a/gen/dc_help.txt b/gen/dc_help.txt index df4ede1583a2..897ab31a8820 100644 --- a/gen/dc_help.txt +++ b/gen/dc_help.txt @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -37,7 +37,7 @@ usage: %s [options] [file...] dc is a reverse-polish notation command-line calculator which supports unlimited precision arithmetic. For details, use `man %s` or see the online documentation -at https://git.gavinhoward.com/gavin/bc/src/tag/%s/manuals/bc/%s.1.md. +at https://github.com/gavinhoward/bc/tree/%s/manuals/dc/%s.1.md . This dc is (mostly) compatible with the OpenBSD dc and the GNU dc. See the OpenBSD man page (http://man.openbsd.org/OpenBSD-current/man1/dc.1) and the GNU diff --git a/gen/lib.bc b/gen/lib.bc index 0c9389b8510d..95ba2765ddfa 100644 --- a/gen/lib.bc +++ b/gen/lib.bc @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: diff --git a/gen/lib2.bc b/gen/lib2.bc index d6d9f70fe063..cc959db73ceb 100644 --- a/gen/lib2.bc +++ b/gen/lib2.bc @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -444,108 +444,77 @@ define void uint64(x){uintn(x,8)} define void int64(x){intn(x,8)} define void uint(x){uintn(x,ubytes(x))} define void int(x){intn(x,sbytes(x))} -define bunrev(t){ - auto a,s,m[] - s=scale - scale=0 - t=abs(t)$ - while(t!=1){ - t=divmod(t,2,m[]) - a*=2 - a+=m[0] - } - scale=s - return a -} define band(a,b){ - auto s,t,m[],n[] + auto r,p,s,m[] a=abs(a)$ b=abs(b)$ - if(b>a){ - t=b - b=a - a=t - } + r=0 + p=1 s=scale scale=0 - t=1 - while(b){ + while(a&&b) { a=divmod(a,2,m[]) - b=divmod(b,2,n[]) - t*=2 - t+=(m[0]&&n[0]) + if(m[0]){ + b=divmod(b,2,m[]) + if(m[0])r+=p + }else b/=2 + p*=2 } scale=s - return bunrev(t) + return r } define bor(a,b){ - auto s,t,m[],n[] + auto r,p,s,m[] a=abs(a)$ b=abs(b)$ - if(b>a){ - t=b - b=a - a=t - } + r=0 + p=1 s=scale scale=0 - t=1 - while(b){ - a=divmod(a,2,m[]) - b=divmod(b,2,n[]) - t*=2 - t+=(m[0]||n[0]) - } - while(a){ + while(a||b){ a=divmod(a,2,m[]) - t*=2 - t+=m[0] + if(!m[0])b=divmod(b,2,m[]) + else b/=2 + if(m[0])r+=p + p*=2 } scale=s - return bunrev(t) + return r } define bxor(a,b){ - auto s,t,m[],n[] + auto r,p,s,m[],n[] a=abs(a)$ b=abs(b)$ - if(b>a){ - t=b - b=a - a=t - } + r=0 + p=1 s=scale scale=0 - t=1 - while(b){ + while(a||b){ a=divmod(a,2,m[]) b=divmod(b,2,n[]) - t*=2 - t+=(m[0]+n[0]==1) - } - while(a){ - a=divmod(a,2,m[]) - t*=2 - t+=m[0] + if(m[0]+n[0]==1)r+=p + p*=2 } scale=s - return bunrev(t) + return r } define bshl(a,b){return abs(a)$*2^abs(b)$} define bshr(a,b){return(abs(a)$/2^abs(b)$)$} define bnotn(x,n){ - auto s,t,m[] + auto r,p,s,t,m[] s=scale scale=0 - t=2^(abs(n)$*8) - x=abs(x)$%t+t - t=1 + r=2^(abs(n)$*8) + x=abs(x)$%r+r + r=0 + p=1 while(x!=1){ x=divmod(x,2,m[]) - t*=2 - t+=!m[0] + if(!m[0])r+=p + p*=2 } scale=s - return bunrev(t) + return r } define bnot8(x){return bnotn(x,1)} define bnot16(x){return bnotn(x,2)} @@ -553,13 +522,19 @@ define bnot32(x){return bnotn(x,4)} define bnot64(x){return bnotn(x,8)} define bnot(x){return bnotn(x,ubytes(x))} define brevn(x,n){ - auto s,t,m[] + auto a,s,m[] s=scale scale=0 - t=2^(abs(n)$*8) - x=abs(x)$%t+t + a=2^(abs(n)$*8) + x=abs(x)$%a+a + a=0 + while(x!=1){ + x=divmod(x,2,m[]) + a*=2 + a+=m[0] + } scale=s - return bunrev(x) + return a } define brev8(x){return brevn(x,1)} define brev16(x){return brevn(x,2)} diff --git a/gen/strgen.c b/gen/strgen.c index 1394a05c4a76..996ea9b3c83a 100644 --- a/gen/strgen.c +++ b/gen/strgen.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2018-2024 Gavin D. Howard and contributors. + * Copyright (c) 2018-2025 Gavin D. Howard and contributors. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -68,7 +68,7 @@ static const char* const bc_gen_ex_end = "{{ end }}"; // This is exactly what it looks like. It just slaps a simple license header on // the generated C source file. static const char* const bc_gen_header = - "// Copyright (c) 2018-2024 Gavin D. Howard and contributors.\n" + "// Copyright (c) 2018-2025 Gavin D. Howard and contributors.\n" "// Licensed under the 2-clause BSD license.\n" "// *** AUTOMATICALLY GENERATED FROM %s. DO NOT MODIFY. ***\n\n"; // clang-format on diff --git a/gen/strgen.sh b/gen/strgen.sh index 8542bd40ee83..683307d4fa80 100755 --- a/gen/strgen.sh +++ b/gen/strgen.sh @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: BSD-2-Clause # -# Copyright (c) 2018-2024 Gavin D. Howard and contributors. +# Copyright (c) 2018-2025 Gavin D. Howard and contributors. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -96,7 +96,7 @@ if [ -n "$remove_tabs" ]; then fi cat<<EOF -// Copyright (c) 2018-2024 Gavin D. Howard and contributors. +// Copyright (c) 2018-2025 Gavin D. Howard and contributors. // Licensed under the 2-clause BSD license. // *** AUTOMATICALLY GENERATED FROM ${input}. DO NOT MODIFY. *** |
