mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
convert ASCII TABs to ASCII SPACEs
Converted all ASCII tabs to ASCII spaces using a 8 character tab stop, for all files, except for all Makefiles (plus rpm.mk). The `git diff -w` reports no changes.
This commit is contained in:
198
cal/mod.cal
198
cal/mod.cal
@@ -9,7 +9,7 @@
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
@@ -17,192 +17,192 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Under source code control: 1990/02/15 01:50:34
|
||||
* File existed as early as: before 1990
|
||||
* 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/
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
|
||||
obj mod {a}; /* definition of the object */
|
||||
obj mod {a}; /* definition of the object */
|
||||
|
||||
global mod_value = 100; /* modulus value (value of N) */
|
||||
global mod_value = 100; /* modulus value (value of N) */
|
||||
|
||||
|
||||
define lmod(a)
|
||||
{
|
||||
local obj mod x;
|
||||
local obj mod x;
|
||||
|
||||
if (!isreal(a) || !isint(a))
|
||||
quit "Bad argument for lmod function";
|
||||
x.a = a % mod_value;
|
||||
return 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)" :;
|
||||
if (digits(mod_value) <= 20)
|
||||
print a.a, "(mod", mod_value : ")" :;
|
||||
else
|
||||
print a.a, "(mod N)" :;
|
||||
}
|
||||
|
||||
|
||||
define mod_one()
|
||||
{
|
||||
return lmod(1);
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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);
|
||||
return a + (-b);
|
||||
}
|
||||
|
||||
|
||||
define mod_neg(a)
|
||||
{
|
||||
local obj mod x;
|
||||
local obj mod x;
|
||||
|
||||
x.a = mod_value - a.a;
|
||||
return x;
|
||||
x.a = mod_value - a.a;
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
define mod_mul(a, b)
|
||||
{
|
||||
local obj mod x;
|
||||
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;
|
||||
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;
|
||||
local obj mod x;
|
||||
|
||||
x.a = a.a^2 % mod_value;
|
||||
return x;
|
||||
x.a = a.a^2 % mod_value;
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
define mod_inc(a)
|
||||
{
|
||||
local x;
|
||||
local x;
|
||||
|
||||
x = a;
|
||||
if (++x.a == mod_value)
|
||||
x.a = 0;
|
||||
return x;
|
||||
x = a;
|
||||
if (++x.a == mod_value)
|
||||
x.a = 0;
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
define mod_dec(a)
|
||||
{
|
||||
local x;
|
||||
local x;
|
||||
|
||||
x = a;
|
||||
if (--x.a < 0)
|
||||
x.a = mod_value - 1;
|
||||
return x;
|
||||
x = a;
|
||||
if (--x.a < 0)
|
||||
x.a = mod_value - 1;
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
define mod_inv(a)
|
||||
{
|
||||
local obj mod x;
|
||||
local obj mod x;
|
||||
|
||||
x.a = minv(a.a, mod_value);
|
||||
return 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);
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user