eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Integer::ModuloNumber':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: ModuloNumber (private in Integer

This class is only visible from within Integer.

Inheritance:

   Object
   |
   +--Integer::ModuloNumber

Package:
stx:libbasic
Category:
Magnitude-Numbers
Owner:
Integer

Description:


This is a helper class to perform fast computation of the modulus.
(with big numbers, this does make a difference)

WARNING: this does only work with numbers which have no common
         divisor (which is true for cryptographic applications).
         So, use this only if you know what you are doing ...



[instance variables:]
    modulus       the modulus
    reciprocal    reciprocal of the modulus
    shift         shift count to cut off some bits

copyright

COPYRIGHT (c) 1999 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

instance creation
o  modulus: anInteger


Instance protocol:

accessing
o  modulus
return the modulus

o  modulus: n
set the modulus

arithmetic
o  modulusOf: dividend
compute the aNumber modulo myself.
The shortcut works only, if dividend is < modulo * modulo
(When doing arithmethic modulo something).
Otherwise do it the long way

Usage example(s):

     |m|

     m := self new modulus:7.
     m modulusOf:55.

Usage example(s):

fast (using moduloNumber with almost same-sized dividend and divisor):
     |m|

     m := self new modulus:123456789901398721398721931729371293712943794254034548369328469438562948623498659238469234659823469823658423659823658.
     Time millisecondsToRun:[
	100000 timesRepeat:[
	    m modulusOf:874928459437598375937451931729371293712943794254034548369328469438562948623498659238469234659823469823658423659823658.
	]
    ].

10730930127807326146398409623772237722337234475792709784029183368622308259008044569184592041059181058049458041058052

converting
o  asInteger
return the modulus

o  asModuloNumber


Examples:


        17 asModuloNumber modulusOf:38
        38 \\ 17


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 15:43:59 GMT