Number.st
author Claus Gittinger <cg@exept.de>
Wed, 03 Apr 1996 00:06:56 +0200
changeset 1133 961f2b095c22
parent 973 5bb2473bf1ef
child 1210 b2fbf119dbbd
permissions -rw-r--r--
underline cleanup
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
ArithmeticValue subclass:#Number
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    14
	instanceVariableNames:''
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    15
	classVariableNames:''
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    16
	poolDictionaries:''
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    17
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
213
3b56a17534fd *** empty log message ***
claus
parents: 202
diff changeset
    20
!Number class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    21
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    24
 COPYRIGHT (c) 1988 by Claus Gittinger
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    25
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    26
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    34
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    35
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    36
documentation
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    37
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    38
    abstract superclass for all kinds of numbers
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    40
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    41
a27a279701f8 Initial revision
claus
parents:
diff changeset
    42
!Number class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    43
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    44
readFrom:aStringOrStream onError:exceptionBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    45
    "return the next Number from the (character-)stream aStream;
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    46
     skipping all whitespace first; return the value of exceptionBlock,
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    47
     if no number can be read."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    48
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    49
    |str nextChar radix value negative signExp freakOut|
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    50
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    51
    str := aStringOrStream readStream.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    52
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    53
    ErrorSignal handle:[:ex |
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    54
        ^ exceptionBlock value
339
claus
parents: 329
diff changeset
    55
    ] do:[
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    56
        nextChar := str skipSeparators.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    57
        nextChar isNil ifTrue:[^ exceptionBlock value].
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
    58
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    59
        freakOut := [^ exceptionBlock value].
339
claus
parents: 329
diff changeset
    60
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    61
        (nextChar == $-) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    62
            negative := true.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    63
            nextChar := str nextPeek
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    64
        ] ifFalse:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    65
            negative := false.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    66
            (nextChar == $+) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    67
                nextChar := str nextPeek
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    68
            ]
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    69
        ].
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    70
        nextChar isDigit ifFalse:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    71
            ^ exceptionBlock value.
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    72
"/          value := super readFrom:str.
339
claus
parents: 329
diff changeset
    73
"/          negative ifTrue:[value := value negated].
claus
parents: 329
diff changeset
    74
"/          ^ value
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    75
        ].
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    76
        value := Integer readFrom:str radix:10 onError:freakOut.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    77
        nextChar := str peek.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    78
        ((nextChar == $r) or:[ nextChar == $R]) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    79
            str next.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    80
            radix := value.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    81
            value := Integer readFrom:str radix:radix onError:freakOut.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    82
        ] ifFalse:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    83
            radix := 10
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    84
        ].
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    85
        (nextChar == $.) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    86
            nextChar := str nextPeek.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    87
            (nextChar notNil and:[nextChar isDigitRadix:radix]) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    88
                value := value asFloat 
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    89
                         + (Number readMantissaFrom:str radix:radix).
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    90
                nextChar := str peek
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    91
            ]
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    92
        ].
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    93
        ((nextChar == $e) or:[nextChar == $E]) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    94
            nextChar := str nextPeek.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    95
            signExp := 1.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    96
            (nextChar == $+) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    97
                nextChar := str nextPeek
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    98
            ] ifFalse:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    99
                (nextChar == $-) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   100
                    nextChar := str nextPeek.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   101
                    signExp := -1
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   102
                ]
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   103
            ].
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   104
            (nextChar notNil and:[(nextChar isDigitRadix:radix)]) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   105
                value := value asFloat 
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   106
                         * (10.0 raisedToInteger:
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   107
                                    ((Integer readFrom:str radix:radix onError:freakOut) * signExp))
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   108
            ]
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   109
        ].
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   110
        negative ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   111
            ^ value negated
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   112
        ].
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   113
        ^ value
339
claus
parents: 329
diff changeset
   114
    ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   115
329
claus
parents: 325
diff changeset
   116
    "
claus
parents: 325
diff changeset
   117
     Number readFrom:(ReadStream on:'54.32e-01')      
claus
parents: 325
diff changeset
   118
     Number readFrom:(ReadStream on:'12345678901234567890') 
claus
parents: 325
diff changeset
   119
     Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF') 
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   120
     Number readFrom:'16rAAAAFFFFAAAAFFFF' 
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   121
     Number readFrom:'0.000001'  
329
claus
parents: 325
diff changeset
   122
     '+00000123.45' asNumber  
claus
parents: 325
diff changeset
   123
    "
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   124
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   125
    "Modified: 20.2.1996 / 20:24:19 / cg"
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   126
!
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   127
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   128
readSmalltalkSyntaxFrom:aStream
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   129
    "ST-80 compatibility (thanks to a note from alpha testers)
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   130
     read and return the next Number in smalltalk syntax from the 
329
claus
parents: 325
diff changeset
   131
     (character-)stream aStream."
claus
parents: 325
diff changeset
   132
claus
parents: 325
diff changeset
   133
    ^ Compiler evaluate:aStream compile:false "/ self readFrom:aStream.
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   134
329
claus
parents: 325
diff changeset
   135
    "
claus
parents: 325
diff changeset
   136
     Number readSmalltalkSyntaxFrom:(ReadStream on:'54.32e-01')    
claus
parents: 325
diff changeset
   137
     Number readSmalltalkSyntaxFrom:(ReadStream on:'12345678901234567890')
claus
parents: 325
diff changeset
   138
     Number readSmalltalkSyntaxFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
claus
parents: 325
diff changeset
   139
     Number readSmalltalkSyntaxFrom:(ReadStream on:'(1/10)') 
claus
parents: 325
diff changeset
   140
     Number readFrom:(ReadStream on:'(1/10)') 
claus
parents: 325
diff changeset
   141
     Number readSmalltalkSyntaxFrom:(ReadStream on:'+00000123.45')  
claus
parents: 325
diff changeset
   142
     Number readFrom:(ReadStream on:'+00000123.45')  
claus
parents: 325
diff changeset
   143
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   144
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   145
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   146
!Number class methodsFor:'error reporting'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   147
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   148
raise:aSignalSymbol receiver:someNumber selector:sel arg:arg errorString:text 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   149
    "ST-80 compatible signal raising. Provided for PD numeric classes"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   150
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   151
    |msg|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   152
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   153
    msg := MessageSend
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   154
		receiver:someNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   155
		selector:sel
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   156
		arguments:(Array with:arg).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   157
    ^ (self perform:aSignalSymbol)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   158
	 raiseRequestWith:msg 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   159
	 errorString:text 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   160
	 in:thisContext sender
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   161
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   162
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   163
     Number raise:#domainErrorSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   164
	    receiver:1.0
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   165
	    selector:#sin
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   166
	    arg:nil
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   167
	    errorString:'foo bar test'
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   168
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   169
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   170
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   171
raise:aSignalSymbol receiver:someNumber selector:sel errorString:text 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   172
    "ST-80 compatible signal raising. Provided for PD numeric classes"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   173
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   174
    |msg|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   175
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   176
    msg := MessageSend
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   177
		receiver:someNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   178
		selector:sel
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   179
		arguments:#().
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   180
    ^ (self perform:aSignalSymbol)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   181
	 raiseRequestWith:msg 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   182
	 errorString:text 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   183
	 in:thisContext sender
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   184
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   185
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   186
     Number raise:#domainErrorSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   187
	    receiver:1.0
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   188
	    selector:#foo 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   189
	    errorString:'foo bar test'
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   190
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   191
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   192
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   193
!Number class methodsFor:'private'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   194
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   195
readMantissaFrom:aStream radix:radix
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   196
    "helper for readFrom: -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   197
     return the mantissa from the (character-)stream aStream;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   198
     no whitespace-skipping; error if no number available"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   199
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   200
    |nextChar value factor|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   201
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   202
    value := 0.0.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   203
    factor := 1.0 / radix.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   204
    nextChar := aStream peek.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   205
    [nextChar notNil and:[nextChar isDigitRadix:radix]] whileTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   206
	value := value + (nextChar digitValue * factor).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   207
	factor := factor / radix.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   208
	nextChar := aStream nextPeek
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   209
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   210
    ^ value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   211
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   212
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   213
!Number methodsFor:'coercing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   214
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   215
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   216
    "return aNumber converted into receivers type"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   217
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   218
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   219
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   220
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   221
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   222
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   223
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   224
    ^ 40
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   225
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   226
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   227
retry:aSymbol coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   228
    "Arithmetic represented by the binary operator, aSymbol,
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   229
    could not be performed with the receiver and the argument,
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   230
    aNumber, because of the differences in representation.  Coerce either
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   231
    the receiver or the argument, depending on which has higher generality, and
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   232
    try again.  If the operation is comapre for same value (=), return false if
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   233
    the argument is not a Number. 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   234
    If the generalities are the same, create an error message."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   235
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   236
    |myGenerality otherGenerality|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   237
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   238
    (aSymbol == #=) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   239
	(aNumber respondsTo:#generality) ifFalse:[^ false]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   240
    ] ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   241
	(aNumber respondsTo:#generality) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   242
	    self error:'retry:coercing: argument is not a number'.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   243
	    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   244
	]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   245
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   246
    myGenerality := self generality.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   247
    otherGenerality := aNumber generality.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   248
    (myGenerality > otherGenerality) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   249
	^ self perform:aSymbol with:(self coerce:aNumber)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   250
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   251
    (myGenerality < otherGenerality) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   252
	^ (aNumber coerce:self) perform:aSymbol with:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   253
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   254
    self error:'retry:coercing: oops - same generality'
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   255
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   256
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   257
!Number methodsFor:'converting'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   258
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   259
@ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   260
    "return a Point with the receiver as x-coordinate and the argument
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   261
     as y-coordinate"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   262
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   263
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   264
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   265
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   266
     * I cannot tell if this special code is worth anything
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   267
     */
835
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   268
    if (__CanDoQuickNew(sizeof(struct __point))) {
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   269
	OBJ newPoint;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   270
	int spc;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   271
835
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   272
	__qCheckedAlignedNew(newPoint, sizeof(struct __point));
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
   273
	__InstPtr(newPoint)->o_class = @global(Point);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
   274
	__PointInstPtr(newPoint)->p_x = self;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
   275
	__PointInstPtr(newPoint)->p_y = aNumber;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   276
	if (! __bothSmallInteger(self, aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   277
	    spc = __qSpace(newPoint);
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   278
	    __STORE_SPC(newPoint, aNumber, spc);
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   279
	    __STORE_SPC(newPoint, self, spc);
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   280
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   281
	RETURN ( newPoint );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   282
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   283
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   284
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   285
    ^ Point x:self y:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   286
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   287
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   288
asPoint
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   289
    "return a new Point with the receiver as all coordinates;  
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   290
     often used to supply the same value in two dimensions, as with 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   291
     symmetrical gridding or scaling."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   292
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   293
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   294
835
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   295
    if (__CanDoQuickNew(sizeof(struct __point))) {
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   296
	OBJ newPoint;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   297
835
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   298
	__qCheckedAlignedNew(newPoint, sizeof(struct __point));
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
   299
	__InstPtr(newPoint)->o_class = @global(Point);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
   300
	__PointInstPtr(newPoint)->p_x = self;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
   301
	__PointInstPtr(newPoint)->p_y = self;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   302
	__STORE(newPoint, self);
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   303
	RETURN ( newPoint );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   304
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   305
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   306
    ^ Point x:self y:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   307
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   308
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   309
degreesToRadians
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   310
    "interpreting the receiver as radians, return the degrees"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   311
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   312
    ^ (self * (Float pi)) / 180.0
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   313
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   314
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   315
literalArrayEncoding
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   316
    "encode myself as an array literal."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   317
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   318
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   319
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   320
    "Modified: 1.9.1995 / 02:25:26 / claus"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   321
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   322
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   323
radiansToDegrees
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   324
    "interpreting the receiver as degrees, return the radians"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   325
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   326
    ^ (self * 180.0) / (Float pi)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   327
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   328
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   329
!Number methodsFor:'intervals'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   330
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   331
to:stop
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   332
    "return an interval from receiver up to the argument, incrementing by 1"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   333
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   334
    ^ Interval from:self to:stop
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   335
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   336
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   337
to:stop by:step
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   338
    "return an interval from receiver up to the argument, incrementing by step"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   339
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   340
    ^ Interval from:self to:stop by:step
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   341
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   342
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   343
!Number methodsFor:'iteration'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   344
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   345
timesRepeat:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   346
    "evaluate the argument, aBlock self times"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   347
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   348
    |count|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   349
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   350
    count := self.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   351
    [count > 0] whileTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   352
	aBlock value.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   353
	count := count - 1
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   354
    ]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   355
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   356
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   357
to:stop by:incr do:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   358
    "For each element of the interval from the receiver up to the argument stop, incrementing
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   359
     by step, evaluate aBlock passing the element as argument."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   360
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   361
    |tmp|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   362
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   363
    tmp := self.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   364
    (incr > 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   365
	[tmp <= stop] whileTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   366
	    aBlock value:tmp.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   367
	    tmp := tmp+incr
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   368
	]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   369
    ] ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   370
	[tmp >= stop] whileTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   371
	    aBlock value:tmp.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   372
	    tmp := tmp+incr
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   373
	]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   374
    ]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   375
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   376
919
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   377
to:stop by:incr doWithBreak:aBlock
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   378
    "For each element of the interval from the receiver up to the argument stop, incrementing
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   379
     by step, evaluate aBlock passing the element as argument.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   380
     Pass a break argument, to allow for premature exit of the loop."
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   381
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   382
    |tmp break|
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   383
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   384
    break := [^ self].
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   385
    tmp := self.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   386
    (incr > 0) ifTrue:[
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   387
	[tmp <= stop] whileTrue:[
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   388
	    aBlock value:tmp value:break.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   389
	    tmp := tmp+incr
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   390
	]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   391
    ] ifFalse:[
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   392
	[tmp >= stop] whileTrue:[
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   393
	    aBlock value:tmp value:break.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   394
	    tmp := tmp+incr
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   395
	]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   396
    ]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   397
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   398
    "
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   399
     1 to:100 by:5 doWithBreak:[:index :break |
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   400
	Transcript showCr:index printString.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   401
	index > 50 ifTrue:[
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   402
	    break value
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   403
	].
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   404
     ]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   405
    "
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   406
!
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   407
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   408
to:stop do:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   409
    "For each element of the interval from the receiver up to the argument stop,
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   410
     evaluate aBlock, passing the number as argument."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   411
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   412
    |tmp|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   413
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   414
    tmp := self.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   415
    [tmp <= stop] whileTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   416
	aBlock value:tmp.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   417
	tmp := tmp+1
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   418
    ]
919
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   419
!
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   420
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   421
to:stop doWithBreak:aBlock
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   422
    "For each element of the interval from the receiver up to the argument stop,
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   423
     evaluate aBlock, passing the number as argument.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   424
     Pass a break argument, to allow for premature exit of the loop."
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   425
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   426
    |tmp break|
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   427
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   428
    break := [^ self].
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   429
    tmp := self.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   430
    [tmp <= stop] whileTrue:[
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   431
	aBlock value:tmp value:break.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   432
	tmp := tmp+1
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   433
    ]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   434
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   435
    "
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   436
     1 to:10 doWithBreak:[:index :break |
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   437
	Transcript showCr:index printString.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   438
	index > 5 ifTrue:[
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   439
	    break value
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   440
	].
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   441
     ]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   442
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   443
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   444
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   445
!Number methodsFor:'printing & storing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   446
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   447
storeOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   448
    "append a string for storing the receiver onto the argument,
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   449
     aStream - since numbers are literals,they store as they print."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   450
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   451
    ^ self printOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   452
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   453
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   454
storeString
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   455
    "return a string for storing 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   456
     - since numbers are literals, they store as they print."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   457
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   458
    ^ self printString
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   459
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   460
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   461
!Number methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   462
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   463
isLiteral
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   464
    "return true, if the receiver can be used as a literal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   465
     (i.e. can be used in constant arrays)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   466
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   467
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   468
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   469
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   470
isNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   471
    "return true, if the receiver is a kind of number"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   472
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   473
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   474
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   475
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   476
isZero
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   477
    ^ self = 0
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   478
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   479
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   480
!Number class methodsFor:'documentation'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   481
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   482
version
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
   483
    ^ '$Header: /cvs/stx/stx/libbasic/Number.st,v 1.28 1996-04-02 22:02:50 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   484
! !