ArithmeticValue.st
changeset 17223 db522b3aff6f
parent 17222 9ff268844b9c
child 17336 3cfe5fb7201c
equal deleted inserted replaced
17222:9ff268844b9c 17223:db522b3aff6f
   189 zero
   189 zero
   190     "return something which represents the zero element (for my instances).
   190     "return something which represents the zero element (for my instances).
   191      That is the neutral element for addition."
   191      That is the neutral element for addition."
   192 
   192 
   193     self subclassResponsibility
   193     self subclassResponsibility
       
   194 ! !
       
   195 
       
   196 !ArithmeticValue class methodsFor:'error reporting'!
       
   197 
       
   198 raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel arguments:argArray errorString:text 
       
   199     "ST-80 compatible signal raising. Provided for PD numeric classes.
       
   200      aSignalSymbolOrErrorClass is either an Error-subclass, or
       
   201      the selector which is sent to myself, to retrieve the Exception class / Signal."
       
   202 
       
   203     <context: #return>
       
   204 
       
   205     |msg signalOrException|
       
   206 
       
   207     msg := MessageSend
       
   208                 receiver:someNumber
       
   209                 selector:sel
       
   210                 arguments:argArray.
       
   211 
       
   212     aSignalSymbolOrErrorClass isSymbol ifTrue:[
       
   213         signalOrException := self perform:aSignalSymbolOrErrorClass.
       
   214     ] ifFalse:[
       
   215         signalOrException := aSignalSymbolOrErrorClass.    "/ assume its an Error-Subclass
       
   216     ].
       
   217 
       
   218     ^ signalOrException
       
   219          raiseRequestWith:msg 
       
   220          errorString:text 
       
   221          in:thisContext sender
       
   222 
       
   223     "
       
   224      Number 
       
   225         raise:#domainErrorSignal
       
   226         receiver:1.0
       
   227         selector:#foo 
       
   228         errorString:'foo bar test'
       
   229     "
       
   230 
       
   231     "Modified: / 16.11.2001 / 14:12:09 / cg"
   194 ! !
   232 ! !
   195 
   233 
   196 !ArithmeticValue class methodsFor:'queries'!
   234 !ArithmeticValue class methodsFor:'queries'!
   197 
   235 
   198 isAbstract
   236 isAbstract
  1233 
  1271 
  1234     ^ 1
  1272     ^ 1
  1235 !
  1273 !
  1236 
  1274 
  1237 even
  1275 even
  1238     "return true if the receiver is divisible by 2"
  1276     "return true if the receiver is divisible by 2.
  1239 
  1277      Only defined for whole-numbers."
  1240     ^ self error:'non integer receiver'
  1278 
  1241     "/ ^ self truncated asInteger even
  1279     ^ self class
       
  1280         raise:DomainError
       
  1281         receiver:self
       
  1282         selector:#even
       
  1283         arguments:#()
       
  1284         errorString:'Receiver must be a whole-number'
       
  1285 
       
  1286     "/ No, this is bad: ^ self truncated asInteger even
       
  1287 
       
  1288     "
       
  1289         2.4 even
       
  1290         2.0 even
       
  1291     "
  1242 !
  1292 !
  1243 
  1293 
  1244 isComplex
  1294 isComplex
  1245     "Answer whether the receiver has an imaginary part
  1295     "Answer whether the receiver has an imaginary part
  1246      (i.e. if it is a complex number). Always false here."
  1296      (i.e. if it is a complex number). Always false here."
  1424 ! !
  1474 ! !
  1425 
  1475 
  1426 !ArithmeticValue class methodsFor:'documentation'!
  1476 !ArithmeticValue class methodsFor:'documentation'!
  1427 
  1477 
  1428 version
  1478 version
  1429     ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.97 2014-12-16 12:21:57 stefan Exp $'
  1479     ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.98 2014-12-17 08:08:47 stefan Exp $'
  1430 !
  1480 !
  1431 
  1481 
  1432 version_CVS
  1482 version_CVS
  1433     ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.97 2014-12-16 12:21:57 stefan Exp $'
  1483     ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.98 2014-12-17 08:08:47 stefan Exp $'
  1434 ! !
  1484 ! !
  1435 
  1485 
  1436 
  1486 
  1437 ArithmeticValue initialize!
  1487 ArithmeticValue initialize!