Number.st
author Claus Gittinger <cg@exept.de>
Thu, 25 Apr 1996 19:02:53 +0200
changeset 1295 83f594f05c52
parent 1245 c8afea3d5af0
child 1422 9a0b792f2953
permissions -rw-r--r--
documentation
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
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    39
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    40
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    41
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    42
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    43
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    44
a27a279701f8 Initial revision
claus
parents:
diff changeset
    45
!Number class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    46
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    47
readFrom:aStringOrStream onError:exceptionBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    48
    "return the next Number from the (character-)stream aStream;
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    49
     skipping all whitespace first; return the value of exceptionBlock,
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    50
     if no number can be read."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    51
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    52
    |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
    53
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    54
    str := aStringOrStream readStream.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    55
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    56
    ErrorSignal handle:[:ex |
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    57
        ^ exceptionBlock value
339
claus
parents: 329
diff changeset
    58
    ] do:[
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    59
        nextChar := str skipSeparators.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    60
        nextChar isNil ifTrue:[^ exceptionBlock value].
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
    61
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    62
        freakOut := [^ exceptionBlock value].
339
claus
parents: 329
diff changeset
    63
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    64
        (nextChar == $-) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    65
            negative := true.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    66
            nextChar := str nextPeek
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    67
        ] ifFalse:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    68
            negative := false.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    69
            (nextChar == $+) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    70
                nextChar := str nextPeek
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    71
            ]
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    72
        ].
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    73
        nextChar isDigit ifFalse:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    74
            ^ exceptionBlock value.
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    75
"/          value := super readFrom:str.
339
claus
parents: 329
diff changeset
    76
"/          negative ifTrue:[value := value negated].
claus
parents: 329
diff changeset
    77
"/          ^ value
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    78
        ].
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    79
        value := Integer readFrom:str radix:10 onError:freakOut.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    80
        nextChar := str peek.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    81
        ((nextChar == $r) or:[ nextChar == $R]) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    82
            str next.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    83
            radix := value.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    84
            value := Integer readFrom:str radix:radix onError:freakOut.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    85
        ] ifFalse:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    86
            radix := 10
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    87
        ].
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    88
        (nextChar == $.) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    89
            nextChar := str nextPeek.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    90
            (nextChar notNil and:[nextChar isDigitRadix:radix]) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    91
                value := value asFloat 
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    92
                         + (Number readMantissaFrom:str radix:radix).
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    93
                nextChar := str peek
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    94
            ]
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    95
        ].
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    96
        ((nextChar == $e) or:[nextChar == $E]) 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
            signExp := 1.
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
            ] ifFalse:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   102
                (nextChar == $-) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   103
                    nextChar := str nextPeek.
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   104
                    signExp := -1
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   105
                ]
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   106
            ].
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   107
            (nextChar notNil and:[(nextChar isDigitRadix:radix)]) ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   108
                value := value asFloat 
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   109
                         * (10.0 raisedToInteger:
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   110
                                    ((Integer readFrom:str radix:radix onError:freakOut) * signExp))
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   111
            ]
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
        negative ifTrue:[
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   114
            ^ value negated
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   115
        ].
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   116
        ^ value
339
claus
parents: 329
diff changeset
   117
    ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   118
329
claus
parents: 325
diff changeset
   119
    "
claus
parents: 325
diff changeset
   120
     Number readFrom:(ReadStream on:'54.32e-01')      
claus
parents: 325
diff changeset
   121
     Number readFrom:(ReadStream on:'12345678901234567890') 
claus
parents: 325
diff changeset
   122
     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
   123
     Number readFrom:'16rAAAAFFFFAAAAFFFF' 
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   124
     Number readFrom:'0.000001'  
329
claus
parents: 325
diff changeset
   125
     '+00000123.45' asNumber  
claus
parents: 325
diff changeset
   126
    "
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   127
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
   128
    "Modified: 20.2.1996 / 20:24:19 / cg"
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   129
!
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   130
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   131
readSmalltalkSyntaxFrom:aStream
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   132
    "ST-80 compatibility (thanks to a note from alpha testers)
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   133
     read and return the next Number in smalltalk syntax from the 
329
claus
parents: 325
diff changeset
   134
     (character-)stream aStream."
claus
parents: 325
diff changeset
   135
claus
parents: 325
diff changeset
   136
    ^ Compiler evaluate:aStream compile:false "/ self readFrom:aStream.
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   137
329
claus
parents: 325
diff changeset
   138
    "
claus
parents: 325
diff changeset
   139
     Number readSmalltalkSyntaxFrom:(ReadStream on:'54.32e-01')    
claus
parents: 325
diff changeset
   140
     Number readSmalltalkSyntaxFrom:(ReadStream on:'12345678901234567890')
claus
parents: 325
diff changeset
   141
     Number readSmalltalkSyntaxFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
claus
parents: 325
diff changeset
   142
     Number readSmalltalkSyntaxFrom:(ReadStream on:'(1/10)') 
claus
parents: 325
diff changeset
   143
     Number readFrom:(ReadStream on:'(1/10)') 
claus
parents: 325
diff changeset
   144
     Number readSmalltalkSyntaxFrom:(ReadStream on:'+00000123.45')  
claus
parents: 325
diff changeset
   145
     Number readFrom:(ReadStream on:'+00000123.45')  
claus
parents: 325
diff changeset
   146
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   147
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   148
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   149
!Number class methodsFor:'error reporting'!
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
raise:aSignalSymbol receiver:someNumber selector:sel arg:arg errorString:text 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   152
    "ST-80 compatible signal raising. Provided for PD numeric classes"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   153
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   154
    |msg|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   155
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   156
    msg := MessageSend
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   157
		receiver:someNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   158
		selector:sel
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   159
		arguments:(Array with:arg).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   160
    ^ (self perform:aSignalSymbol)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   161
	 raiseRequestWith:msg 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   162
	 errorString:text 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   163
	 in:thisContext sender
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   164
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   165
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   166
     Number raise:#domainErrorSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   167
	    receiver:1.0
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   168
	    selector:#sin
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   169
	    arg:nil
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   170
	    errorString:'foo bar test'
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   171
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   172
!
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
raise:aSignalSymbol receiver:someNumber selector:sel errorString:text 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   175
    "ST-80 compatible signal raising. Provided for PD numeric classes"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   176
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   177
    |msg|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   178
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   179
    msg := MessageSend
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   180
		receiver:someNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   181
		selector:sel
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   182
		arguments:#().
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   183
    ^ (self perform:aSignalSymbol)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   184
	 raiseRequestWith:msg 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   185
	 errorString:text 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   186
	 in:thisContext sender
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   187
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   188
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   189
     Number raise:#domainErrorSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   190
	    receiver:1.0
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   191
	    selector:#foo 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   192
	    errorString:'foo bar test'
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   193
    "
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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   196
!Number class methodsFor:'private'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   197
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   198
readMantissaFrom:aStream radix:radix
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   199
    "helper for readFrom: -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   200
     return the mantissa from the (character-)stream aStream;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   201
     no whitespace-skipping; error if no number available"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   202
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   203
    |nextChar value factor|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   204
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   205
    value := 0.0.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   206
    factor := 1.0 / radix.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   207
    nextChar := aStream peek.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   208
    [nextChar notNil and:[nextChar isDigitRadix:radix]] whileTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   209
	value := value + (nextChar digitValue * factor).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   210
	factor := factor / radix.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   211
	nextChar := aStream nextPeek
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
    ^ value
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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   216
!Number methodsFor:'coercing'!
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
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   219
    "return aNumber converted into receivers type"
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
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   222
!
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
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   225
    "return the generality value - see ArithmeticValue>>retry:coercing:"
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
    ^ 40
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   228
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   229
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   230
!Number methodsFor:'converting'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   231
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   232
@ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   233
    "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
   234
     as y-coordinate"
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
%{  /* NOCONTEXT */
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
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   239
     * I cannot tell if this special code is worth anything
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   240
     */
835
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   241
    if (__CanDoQuickNew(sizeof(struct __point))) {
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   242
	OBJ newPoint;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   243
	int spc;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   244
835
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   245
	__qCheckedAlignedNew(newPoint, sizeof(struct __point));
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
   246
	__InstPtr(newPoint)->o_class = @global(Point);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
   247
	__PointInstPtr(newPoint)->p_x = self;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
   248
	__PointInstPtr(newPoint)->p_y = aNumber;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   249
	if (! __bothSmallInteger(self, aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   250
	    spc = __qSpace(newPoint);
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   251
	    __STORE_SPC(newPoint, aNumber, spc);
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   252
	    __STORE_SPC(newPoint, self, spc);
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
	RETURN ( newPoint );
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
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   258
    ^ Point x:self y:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   259
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   260
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   261
asPoint
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   262
    "return a new Point with the receiver as all coordinates;  
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   263
     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
   264
     symmetrical gridding or scaling."
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
%{  /* NOCONTEXT */
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
835
8bd6f4aa8130 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   271
	__qCheckedAlignedNew(newPoint, sizeof(struct __point));
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
   272
	__InstPtr(newPoint)->o_class = @global(Point);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
   273
	__PointInstPtr(newPoint)->p_x = self;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
   274
	__PointInstPtr(newPoint)->p_y = self;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   275
	__STORE(newPoint, self);
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   276
	RETURN ( newPoint );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   277
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   278
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   279
    ^ Point x:self y:self
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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   282
degreesToRadians
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   283
    "interpreting the receiver as radians, return the degrees"
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
    ^ (self * (Float pi)) / 180.0
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
literalArrayEncoding
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   289
    "encode myself as an array literal, from which a copy of the receiver
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   290
     can be reconstructed with #decodeAsLiteralArray."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   291
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   292
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   293
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   294
    "Modified: 1.9.1995 / 02:25:26 / claus"
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   295
    "Modified: 22.4.1996 / 13:00:27 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   296
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   297
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   298
radiansToDegrees
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   299
    "interpreting the receiver as degrees, return the radians"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   300
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   301
    ^ (self * 180.0) / (Float pi)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   302
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   303
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   304
!Number methodsFor:'intervals'!
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
to:stop
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   307
    "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
   308
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   309
    ^ Interval from:self to:stop
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   310
!
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
to:stop by:step
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   313
    "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
   314
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   315
    ^ Interval from:self to:stop by:step
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   316
! !
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
!Number methodsFor:'iteration'!
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
timesRepeat:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   321
    "evaluate the argument, aBlock self times"
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
    |count|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   324
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   325
    count := self.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   326
    [count > 0] whileTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   327
	aBlock value.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   328
	count := count - 1
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   329
    ]
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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   332
to:stop by:incr do:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   333
    "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
   334
     by step, evaluate aBlock passing the element as argument."
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
    |tmp|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   337
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   338
    tmp := self.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   339
    (incr > 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   340
	[tmp <= stop] whileTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   341
	    aBlock value:tmp.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   342
	    tmp := tmp+incr
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   343
	]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   344
    ] ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   345
	[tmp >= stop] whileTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   346
	    aBlock value:tmp.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   347
	    tmp := tmp+incr
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   348
	]
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
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   351
919
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   352
to:stop by:incr doWithBreak:aBlock
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   353
    "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
   354
     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
   355
     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
   356
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   357
    |tmp break|
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   358
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   359
    break := [^ self].
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   360
    tmp := self.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   361
    (incr > 0) ifTrue:[
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   362
	[tmp <= stop] whileTrue:[
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   363
	    aBlock value:tmp value:break.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   364
	    tmp := tmp+incr
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   365
	]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   366
    ] ifFalse:[
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   367
	[tmp >= stop] whileTrue:[
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   368
	    aBlock value:tmp value:break.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   369
	    tmp := tmp+incr
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   370
	]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   371
    ]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   372
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   373
    "
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   374
     1 to:100 by:5 doWithBreak:[:index :break |
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   375
	Transcript showCr:index printString.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   376
	index > 50 ifTrue:[
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   377
	    break value
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   378
	].
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   379
     ]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   380
    "
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
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   383
to:stop do:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   384
    "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
   385
     evaluate aBlock, passing the number as argument."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   386
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   387
    |tmp|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   388
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   389
    tmp := self.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   390
    [tmp <= stop] whileTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   391
	aBlock value:tmp.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   392
	tmp := tmp+1
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   393
    ]
919
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   394
!
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
to:stop doWithBreak:aBlock
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   397
    "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
   398
     evaluate aBlock, passing the number as argument.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   399
     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
   400
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   401
    |tmp break|
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   402
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   403
    break := [^ self].
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   404
    tmp := self.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   405
    [tmp <= stop] whileTrue:[
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   406
	aBlock value:tmp value:break.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   407
	tmp := tmp+1
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   408
    ]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   409
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   410
    "
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   411
     1 to:10 doWithBreak:[:index :break |
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   412
	Transcript showCr:index printString.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   413
	index > 5 ifTrue:[
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   414
	    break value
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   415
	].
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   416
     ]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   417
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   418
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   419
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   420
!Number methodsFor:'printing & storing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   421
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   422
storeOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   423
    "append a string for storing the receiver onto the argument,
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   424
     aStream - since numbers are literals,they store as they print."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   425
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   426
    ^ self printOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   427
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   428
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   429
storeString
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   430
    "return a string for storing 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   431
     - since numbers are literals, they store as they print."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   432
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   433
    ^ self printString
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   434
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   435
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   436
!Number methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   437
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   438
isLiteral
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   439
    "return true, if the receiver can be used as a literal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   440
     (i.e. can be used in constant arrays)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   441
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   442
    ^ true
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
isNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   446
    "return true, if the receiver is a kind of number"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   447
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   448
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   449
!
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
isZero
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   452
    ^ self = 0
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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   455
!Number class methodsFor:'documentation'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   456
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   457
version
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
   458
    ^ '$Header: /cvs/stx/stx/libbasic/Number.st,v 1.31 1996-04-25 16:59:17 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   459
! !