Integer.st
branchjv
changeset 20398 8cb53f870d39
parent 20345 68e5382ae472
parent 20378 d0b2afa829d4
child 20727 fb8c5591428b
equal deleted inserted replaced
20397:59b59d09f64e 20398:8cb53f870d39
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "
     1 "
     4  COPYRIGHT (c) 1988 by Claus Gittinger
     2  COPYRIGHT (c) 1988 by Claus Gittinger
     5               All Rights Reserved
     3               All Rights Reserved
     6 
     4 
     7  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
   423     "convert a string or stream containing a roman representation into an integer.
   421     "convert a string or stream containing a roman representation into an integer.
   424      Raises a RomanNumberFormatError, if the inputs format is completely wrong.
   422      Raises a RomanNumberFormatError, if the inputs format is completely wrong.
   425      Raises BadRomanNumberFormatError if its wrong, but could be parsed.
   423      Raises BadRomanNumberFormatError if its wrong, but could be parsed.
   426      Notifies via NaiveRomanNumberFormatNotification, if its a bit wrong (naive format).
   424      Notifies via NaiveRomanNumberFormatNotification, if its a bit wrong (naive format).
   427      Will read both real and naive roman numbers (see printRomanOn: vs. printRomanOn:naive:),
   425      Will read both real and naive roman numbers (see printRomanOn: vs. printRomanOn:naive:),
   428      however, a notification is raised for for naive numbers (catch it if you are interested in it)."
   426      however, a notification is raised for naive numbers (catch it if you are interested in it)."
   429 
   427 
   430     |romanValues s c val digitVal prevDigitVal countSame delta
   428     |romanValues s c val digitVal prevDigitVal countSame delta
   431      stopOnSeparator finish|
   429      stopOnSeparator finish|
   432 
   430 
   433     romanValues := Dictionary
   431     romanValues := Dictionary
   773     ^ BCDConversionErrorSignal
   771     ^ BCDConversionErrorSignal
   774 
   772 
   775     "Modified: / 15.11.1999 / 20:35:20 / cg"
   773     "Modified: / 15.11.1999 / 20:35:20 / cg"
   776 ! !
   774 ! !
   777 
   775 
       
   776 
       
   777 
   778 !Integer class methodsFor:'class initialization'!
   778 !Integer class methodsFor:'class initialization'!
   779 
   779 
   780 initialize
   780 initialize
   781     BCDConversionErrorSignal isNil ifTrue:[
   781     BCDConversionErrorSignal isNil ifTrue:[
   782         BCDConversionErrorSignal := ConversionError newSignal.
   782         BCDConversionErrorSignal := ConversionError newSignal.
   817 
   817 
   818     ^ 0
   818     ^ 0
   819 
   819 
   820     "Modified: 18.7.1996 / 12:26:38 / cg"
   820     "Modified: 18.7.1996 / 12:26:38 / cg"
   821 ! !
   821 ! !
       
   822 
   822 
   823 
   823 !Integer class methodsFor:'prime numbers'!
   824 !Integer class methodsFor:'prime numbers'!
   824 
   825 
   825 flushPrimeCache
   826 flushPrimeCache
   826     "cleanup after using a primeCache.
   827     "cleanup after using a primeCache.
  1193      Abstract subclasses must redefine this again."
  1194      Abstract subclasses must redefine this again."
  1194 
  1195 
  1195     ^ self == Integer
  1196     ^ self == Integer
  1196 ! !
  1197 ! !
  1197 
  1198 
       
  1199 
  1198 !Integer methodsFor:'Compatibility-Dolphin'!
  1200 !Integer methodsFor:'Compatibility-Dolphin'!
  1199 
  1201 
  1200 & aNumber
  1202 & aNumber
  1201     "return the bitwise-and of the receiver and the argument, anInteger.
  1203     "return the bitwise-and of the receiver and the argument, anInteger.
  1202      Same as bitAnd: - added for compatibility with Dolphin Smalltalk.
  1204      Same as bitAnd: - added for compatibility with Dolphin Smalltalk.
  1456     "
  1458     "
  1457      1 >> -5
  1459      1 >> -5
  1458      64 >> 5
  1460      64 >> 5
  1459     "
  1461     "
  1460 ! !
  1462 ! !
       
  1463 
  1461 
  1464 
  1462 !Integer methodsFor:'bcd conversion'!
  1465 !Integer methodsFor:'bcd conversion'!
  1463 
  1466 
  1464 decodeFromBCD
  1467 decodeFromBCD
  1465     "return a number representing the value of the BCD encoded receiver."
  1468     "return a number representing the value of the BCD encoded receiver."
  3490     ].
  3493     ].
  3491 
  3494 
  3492     ^ fibUsingDict value:self
  3495     ^ fibUsingDict value:self
  3493 
  3496 
  3494     "the running time is mostly dictated by the LargeInteger multiplication performance...
  3497     "the running time is mostly dictated by the LargeInteger multiplication performance...
  3495      (therefore, we get O(n²) execution times, even for a linear number of multiplications)
  3498      (therefore, we get O(n) execution times, even for a linear number of multiplications)
  3496 
  3499 
  3497      Time millisecondsToRun:[50000 fib_iterative]  312    (DUO 1.7Ghz CPU)
  3500      Time millisecondsToRun:[50000 fib_iterative]  312    (DUO 1.7Ghz CPU)
  3498      Time millisecondsToRun:[50000 fib_helper]     109
  3501      Time millisecondsToRun:[50000 fib_helper]     109
  3499 
  3502 
  3500      Time millisecondsToRun:[100000 fib_iterative] 1248
  3503      Time millisecondsToRun:[100000 fib_iterative] 1248
  4851     "
  4854     "
  4852 
  4855 
  4853     "Created: / 09-01-2012 / 17:18:06 / cg"
  4856     "Created: / 09-01-2012 / 17:18:06 / cg"
  4854 ! !
  4857 ! !
  4855 
  4858 
       
  4859 
  4856 !Integer methodsFor:'special modulo arithmetic'!
  4860 !Integer methodsFor:'special modulo arithmetic'!
  4857 
  4861 
  4858 add_32:anInteger
  4862 add_32:anInteger
  4859     "return a C-semantic 32bit sum of the receiver and the argument.
  4863     "return a C-semantic 32bit sum of the receiver and the argument.
  4860      Both must be either Small- or LargeIntegers.
  4864      Both must be either Small- or LargeIntegers.