/usr/share/calc/mod.cal is in apcalc-common 2.12.4.4-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | /*
* mod - routines to handle numbers modulo a specified number
*
* Copyright (C) 1999 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* Calc is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* A copy of version 2.1 of the GNU Lesser General Public License is
* distributed with calc under the filename COPYING-LGPL. You should have
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @(#) $Revision: 30.1 $
* @(#) $Id: mod.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/mod.cal,v $
*
* Under source code control: 1990/02/15 01:50:34
* File existed as early as: before 1990
*
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
obj mod {a}; /* definition of the object */
global mod_value = 100; /* modulus value (value of N) */
define lmod(a)
{
local obj mod x;
if (!isreal(a) || !isint(a))
quit "Bad argument for lmod function";
x.a = a % mod_value;
return x;
}
define mod_print(a)
{
if (digits(mod_value) <= 20)
print a.a, "(mod", mod_value : ")" :;
else
print a.a, "(mod N)" :;
}
define mod_one()
{
return lmod(1);
}
define mod_cmp(a, b)
{
if (isnum(a))
return (a % mod_value) != b.a;
if (isnum(b))
return (b % mod_value) != a.a;
return a.a != b.a;
}
define mod_rel(a, b)
{
if (isnum(a))
a = lmod(a);
if (isnum(b))
b = lmod(b);
if (a.a < b.a)
return -1;
return a.a != b.a;
}
define mod_add(a, b)
{
local obj mod x;
if (isnum(b)) {
if (!isint(b))
quit "Adding non-integer";
x.a = (a.a + b) % mod_value;
return x;
}
if (isnum(a)) {
if (!isint(a))
quit "Adding non-integer";
x.a = (a + b.a) % mod_value;
return x;
}
x.a = (a.a + b.a) % mod_value;
return x;
}
define mod_sub(a, b)
{
return a + (-b);
}
define mod_neg(a)
{
local obj mod x;
x.a = mod_value - a.a;
return x;
}
define mod_mul(a, b)
{
local obj mod x;
if (isnum(b)) {
if (!isint(b))
quit "Multiplying by non-integer";
x.a = (a.a * b) % mod_value;
return x;
}
if (isnum(a)) {
if (!isint(a))
quit "Multiplying by non-integer";
x.a = (a * b.a) % mod_value;
return x;
}
x.a = (a.a * b.a) % mod_value;
return x;
}
define mod_square(a)
{
local obj mod x;
x.a = a.a^2 % mod_value;
return x;
}
define mod_inc(a)
{
local x;
x = a;
if (++x.a == mod_value)
x.a = 0;
return x;
}
define mod_dec(a)
{
local x;
x = a;
if (--x.a < 0)
x.a = mod_value - 1;
return x;
}
define mod_inv(a)
{
local obj mod x;
x.a = minv(a.a, mod_value);
return x;
}
define mod_div(a, b)
{
local c;
local obj mod x;
local obj mod y;
if (isnum(a))
a = lmod(a);
if (isnum(b))
b = lmod(b);
c = gcd(a.a, b.a);
x.a = a.a / c;
y.a = b.a / c;
return x * inverse(y);
}
define mod_pow(a, b)
{
local x, y, z;
obj mod x;
y = a;
z = b;
if (b < 0) {
y = inverse(a);
z = -b;
}
x.a = pmod(y.a, z, mod_value);
return x;
}
if (config("resource_debug") & 3) {
print "obj mod {a} defined";
print "mod_value defined";
print "set mod_value as needed";
}
|