2 minv - inverse of an integer modulo a specified integer
14 If x and md are not relatively prime, zero is returned.
15 Otherwise v = minv(x, md) is the canonical residue v modulo md
16 for which v * x is congruent to 1 modulo md. The canonical
17 residues modulo md are determined as follows by md and bits 0, 2
18 and 4 of config("mod") (other bits are ignored).
20 config("mod") md > 0 md < 0
22 0 0 < v < md md < v < 0
23 1 -md < v < 0 0 < v < -md
24 4 0 < v < md 0 < v < -md
25 5 -md < v < 0 md < v < 0
26 16 -md/2 < v <= md/2 md/2 <= v < -md/2
27 17 -md/2 <= v < md/2 md/2 < v <= -md/2
28 20 -md/2 < v <= md/2 md/2 < v <= -md/2
29 21 -md/2 <= v < md/2 md/2 <= v < -md/2
32 ; c = config("mod", 0)
33 ; print minv(3,10), minv(-3,10), minv(3,-10), minv(-3,-10), minv(4,10)
36 ; c = config("mod",16)
37 ; print minv(3,10), minv(-3,10), minv(3,-10), minv(-3,-10), minv(4,10)
44 NUMBER *qminv(NUMBER *x, NUMBER *md)
49 ## Copyright (C) 1999 Landon Curt Noll
51 ## Calc is open software; you can redistribute it and/or modify it under
52 ## the terms of the version 2.1 of the GNU Lesser General Public License
53 ## as published by the Free Software Foundation.
55 ## Calc is distributed in the hope that it will be useful, but WITHOUT
56 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
57 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
58 ## Public License for more details.
60 ## A copy of version 2.1 of the GNU Lesser General Public License is
61 ## distributed with calc under the filename COPYING-LGPL. You should have
62 ## received a copy with calc; if not, write to Free Software Foundation, Inc.
63 ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
65 ## @(#) $Revision: 30.1 $
66 ## @(#) $Id: minv,v 30.1 2007/03/16 11:10:42 chongo Exp $
67 ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/minv,v $
69 ## Under source code control: 1995/11/09 03:27:51
70 ## File existed as early as: 1995
72 ## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
73 ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/