NotANumber.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 21892 1fea613ccf95
child 24703 3cd1ec269512
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7436
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2003 by eXept Software AG
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
21887
71fd88b46048 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
    12
"{ Package: 'stx:libbasic' }"
7436
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
21887
71fd88b46048 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
    14
"{ NameSpace: Smalltalk }"
7436
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
MetaNumber subclass:#NotANumber
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:''
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:'NaN'
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	category:'Magnitude-Numbers'
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!NotANumber class methodsFor:'documentation'!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 2003 by eXept Software AG
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
documentation
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
21887
71fd88b46048 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
    41
    Represents the NaN metaNumber for non-float classes.
7436
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    [author:]
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
        Claus Gittinger
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    [see also:]
21887
71fd88b46048 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
    47
        Number Infinity
71fd88b46048 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
    48
        Float ShortFloat LongFloat QDouble Fraction FixedPoint Integer Complex
7436
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
        FloatArray DoubleArray                                                                         
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
"
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
! !
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
!NotANumber class methodsFor:'instance creation'!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
21892
1fea613ccf95 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21887
diff changeset
    55
NaN
1fea613ccf95 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21887
diff changeset
    56
    ^ NaN
1fea613ccf95 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21887
diff changeset
    57
1fea613ccf95 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21887
diff changeset
    58
    "Created: / 21-06-2017 / 20:36:00 / cg"
1fea613ccf95 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21887
diff changeset
    59
!
1fea613ccf95 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21887
diff changeset
    60
7436
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
new
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
    ^ NaN
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
! !
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
!NotANumber class methodsFor:'class initialization'!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
initialize
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    NaN := self basicNew
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    "
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
     self initialize
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    "
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
! !
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
!NotANumber methodsFor:'arithmetic'!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
* aNumber
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
    "Multiply the receiver and the argument and answer with the result."
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
    ^ self
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
+ aNumber
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    "Add the receiver and the argument and answer with the result."
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    ^ self
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
- aNumber
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    "Subtract the argument from the receiver and answer with the result."
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    ^ self
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
/ aNumber
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    "Divide the receiver by the argument and answer with the result."
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    ^ self
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
! !
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
!NotANumber methodsFor:'comparing'!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
= something
7471
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7436
diff changeset
   104
    "return true, if the argument represents the same numeric value
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7436
diff changeset
   105
     as the receiver, false otherwise."
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7436
diff changeset
   106
7436
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    something respondsToArithmetic ifTrue:[ ^ something isNaN ].
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
    ^ false.
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
! !
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
!NotANumber methodsFor:'double dispatching'!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
differenceFromSomeNumber:aNumber
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    "sent from aNumber-self, if aNumber does not know how to handle this"
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
    ^ self
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
lessFromSomeNumber:aNumber
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
    "sent from aNumber < self, if aNumber does not know how to handle this"
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
    ^ Number
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
        raise: #undefinedResultSignal
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
        receiver: self
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
        selector: #lessFromSomeNumber:
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
        errorString: 'Cannot compare against NaN'
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
productFromSomeNumber:aNumber
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
    "sent from aNumber*self, if aNumber does not know how to handle this"
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    ^ self
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
quotientFromSomeNumber:aNumber
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
    "Return the quotient of the argument, aNumber and the receiver.
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
     Sent when aNumber does not know how to divide by the receiver."
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
    ^ self
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
sumFromSomeNumber:aNumber
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
    "sent from aNumber+self, if aNumber does not know how to handle this"
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
    ^ self
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
! !
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
!NotANumber methodsFor:'printing'!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
printOn:aStream
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
    aStream nextPutAll:'NAN'
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
! !
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
!NotANumber methodsFor:'testing'!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
isFinite
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    ^ false
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
isNaN
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
    ^ true
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
! !
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
!NotANumber class methodsFor:'documentation'!
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
version
21887
71fd88b46048 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
   167
    ^ '$Header$'
21892
1fea613ccf95 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21887
diff changeset
   168
!
1fea613ccf95 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21887
diff changeset
   169
1fea613ccf95 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21887
diff changeset
   170
version_CVS
1fea613ccf95 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21887
diff changeset
   171
    ^ '$Header$'
7436
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
! !
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
21887
71fd88b46048 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
   174
7436
077eb3b8f2c0 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
NotANumber initialize!