Number.st
author Claus Gittinger <cg@exept.de>
Mon, 16 Jun 2003 11:17:33 +0200
changeset 7356 fe8fb0a571f2
parent 7261 f35fc9cee675
child 7388 bb89a53e2682
permissions -rw-r--r--
double dispatching fixed; many refactorings
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
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
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
5360
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
    13
"{ Package: 'stx:libbasic' }"
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
ArithmeticValue subclass:#Number
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
    16
	instanceVariableNames:''
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
    17
	classVariableNames:''
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
    18
	poolDictionaries:''
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
    19
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    22
!Number class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    23
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    26
 COPYRIGHT (c) 1988 by Claus Gittinger
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
    27
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    28
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    36
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    37
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    38
documentation
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    40
    abstract superclass for all kinds of numbers
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    41
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    42
    [author:]
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
    43
	Claus Gittinger
1628
da30f2f41db7 comment
Claus Gittinger <cg@exept.de>
parents: 1557
diff changeset
    44
da30f2f41db7 comment
Claus Gittinger <cg@exept.de>
parents: 1557
diff changeset
    45
    [see also:]
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
    46
	Integer LargeInteger SmallInteger
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
    47
	LimitedPrecisionReal Float ShortFloat
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
    48
	Fraction FixedPoint
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    49
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    50
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    51
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    52
!Number class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    53
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    54
fromString:aString
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    55
    "for compatibility with other smalltalks - same as #readFrom:"
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    56
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    57
    |s num|
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    58
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    59
    s := aString readStream.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    60
    num := self readFrom:s onError:[^ self error:'invalid number'].
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    61
    s atEnd ifFalse:[^ self error:'garbage at end of number'].
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    62
    ^ num.
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    63
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    64
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    65
     Number fromString:'12345'
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    66
     Number fromString:'abc'
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    67
     Number fromString:'1abc'
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    68
     '12345' asNumber
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    69
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    70
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    71
    "Modified: / 3.8.1998 / 20:05:11 / cg"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    72
!
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    73
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    74
fromString:aString onError:exceptionBlock
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    75
    "for compatibility with other smalltalks - same as #readFrom:"
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    76
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    77
    ^ self readFrom:aString onError:exceptionBlock
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    78
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    79
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    80
     Number fromString:'12345' onError:0
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    81
     Number fromString:'fooBarBaz' onError:0
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    82
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    83
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    84
    "Modified: / 3.8.1998 / 20:05:34 / cg"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    85
!
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    86
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    87
readFrom:aStringOrStream onError:exceptionBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    88
    "return the next Number from the (character-)stream aStream;
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    89
     skipping all whitespace first; return the value of exceptionBlock,
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
    90
     if no number can be read.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
    91
     This method is less strict than the smalltalk number reader; it
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
    92
     allows for prefixed + and also allows missing fractional part after eE"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    93
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
    94
    ^ [
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    95
        |value intValue mantissaAndScale scale decimalMantissa str 
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
    96
         nextChar radix negative signExp exp denom|
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
    97
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
    98
        str := aStringOrStream readStream.
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
    99
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   100
        nextChar := str skipSeparators.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   101
        nextChar isNil ifTrue:[^ exceptionBlock value].
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   102
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   103
        (nextChar == $-) ifTrue:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   104
            negative := true.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   105
            str next.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   106
            nextChar := str peekOrNil
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   107
        ] ifFalse:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   108
            negative := false.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   109
            (nextChar == $+) ifTrue:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   110
                str next.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   111
                nextChar := str peekOrNil
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   112
            ]
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   113
        ].
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   114
        (nextChar isDigit or:[nextChar == $.]) ifFalse:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   115
            ^ exceptionBlock value.
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   116
"/          value := super readFrom:str.
339
claus
parents: 329
diff changeset
   117
"/          negative ifTrue:[value := value negated].
claus
parents: 329
diff changeset
   118
"/          ^ value
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   119
        ].
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   120
        nextChar == $. ifTrue:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   121
            radix := 10.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   122
            value := 0.0.
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   123
            intValue := 0.
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   124
        ] ifFalse:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   125
            value := Integer readFrom:str radix:10.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   126
            nextChar := str peekOrNil.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   127
            ((nextChar == $r) or:[ nextChar == $R]) ifTrue:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   128
                str next.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   129
                radix := value.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   130
                value := Integer readFrom:str radix:radix.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   131
            ] ifFalse:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   132
                radix := 10
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   133
            ].
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   134
            intValue := value.
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   135
        ].
4637
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4558
diff changeset
   136
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   137
        (nextChar == $.) ifTrue:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   138
            str next.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   139
            nextChar := str peekOrNil.
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   140
            scale := 0.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   141
            decimalMantissa := 0.
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   142
            (nextChar notNil and:[nextChar isDigitRadix:radix]) ifTrue:[
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   143
                mantissaAndScale := Number readMantissaAndScaleFrom:str radix:radix.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   144
                value := value asFloat + (mantissaAndScale first).
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   145
                nextChar := str peekOrNil
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   146
            ]
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   147
        ].
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   148
        ('eEdDqQ' includes:nextChar) ifTrue:[
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   149
            str next.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   150
            nextChar := str peekOrNil.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   151
            signExp := 1.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   152
            (nextChar == $+) ifTrue:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   153
                str next.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   154
                nextChar := str peekOrNil.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   155
            ] ifFalse:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   156
                (nextChar == $-) ifTrue:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   157
                    str next.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   158
                    nextChar := str peekOrNil.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   159
                    signExp := -1
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   160
                ]
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   161
            ].
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   162
            ('qQ' includes:nextChar) ifTrue:[
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   163
                value := value asLongFloat.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   164
            ] ifFalse:[
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   165
                value := value asFloat.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   166
"/ future: (for now, always create Doubles for Dolphin,Squeak etc. compatibility
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   167
"/                ('eE' includes:nextChar) ifTrue:[
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   168
"/                    value := value asShortFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   169
"/                ]
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   170
            ].
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   171
            (nextChar notNil and:[(nextChar isDigitRadix:radix)]) ifTrue:[
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   172
                exp := (Integer readFrom:str radix:radix) * signExp.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   173
                value := value * ((value class unity * 10.0) raisedToInteger:exp)
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   174
            ]
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   175
        ] ifFalse:[
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   176
            ('s' includes:nextChar) ifTrue:[
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   177
                mantissaAndScale isNil ifTrue:[
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   178
                    value := intValue asFixedPoint:0.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   179
                ] ifFalse:[
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   180
                    denom := 10 raisedTo:mantissaAndScale last.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   181
                    value := FixedPoint 
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   182
                                numerator:(intValue * denom) + (mantissaAndScale second)
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   183
                                denominator:denom
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   184
                                scale:mantissaAndScale last.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   185
                ].
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   186
            ]
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   187
        ].
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   188
        negative ifTrue:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   189
            value := value negated
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   190
        ].
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   191
        value.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   192
    ] on:Error do:exceptionBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   193
329
claus
parents: 325
diff changeset
   194
    "
claus
parents: 325
diff changeset
   195
     Number readFrom:(ReadStream on:'54.32e-01')      
claus
parents: 325
diff changeset
   196
     Number readFrom:(ReadStream on:'12345678901234567890') 
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   197
     Number readFrom:(ReadStream on:'12345678901234567890.0') 
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   198
     Number readFrom:(ReadStream on:'12345678901234567890.012345678901234567890') 
329
claus
parents: 325
diff changeset
   199
     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
   200
     Number readFrom:'16rAAAAFFFFAAAAFFFF' 
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   201
     Number readFrom:'0.000001'  
329
claus
parents: 325
diff changeset
   202
     '+00000123.45' asNumber  
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   203
     Number readFrom:'99s'      
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   204
     Number readFrom:'99.00s'      
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   205
     Number readFrom:'99.0000000s'      
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   206
     Number readFrom:'.0000000s'      
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   207
     Number readFrom:'.0000000q'      
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   208
     Number readFrom:'.0000000f'      
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   209
     Number readFrom:'.0000000e'      
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   210
     Number readFrom:'.0000000s1'      
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   211
     Number readFrom:'.0000000q1'      
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   212
     Number readFrom:'.0000000f1'      
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   213
     Number readFrom:'.0000000e1'      
329
claus
parents: 325
diff changeset
   214
    "
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   215
3375
7c64da3964e4 faster conversion from string (due to slow #pastEnd)
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
   216
    "Modified: / 14.4.1998 / 19:22:50 / cg"
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   217
!
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   218
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   219
readSmalltalkSyntaxFrom:aStream
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   220
    "ST-80 compatibility (thanks to a note from alpha testers)
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   221
     read and return the next Number in smalltalk syntax from the 
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   222
     (character-) aStream.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   223
     Returns nil if aStream contains no valid number."
329
claus
parents: 325
diff changeset
   224
3613
75629df7f224 fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents: 3394
diff changeset
   225
    ^ Scanner scanNumberFrom:aStream
75629df7f224 fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents: 3394
diff changeset
   226
"/    ^ Compiler evaluate:aStream compile:false "/ self readFrom:aStream.
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   227
329
claus
parents: 325
diff changeset
   228
    "
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   229
     Number readSmalltalkSyntaxFrom:'99d'    
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   230
     Number readSmalltalkSyntaxFrom:'99.00d'    
329
claus
parents: 325
diff changeset
   231
     Number readSmalltalkSyntaxFrom:(ReadStream on:'54.32e-01')    
claus
parents: 325
diff changeset
   232
     Number readSmalltalkSyntaxFrom:(ReadStream on:'12345678901234567890')
claus
parents: 325
diff changeset
   233
     Number readSmalltalkSyntaxFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
claus
parents: 325
diff changeset
   234
     Number readSmalltalkSyntaxFrom:(ReadStream on:'(1/10)') 
claus
parents: 325
diff changeset
   235
     Number readFrom:(ReadStream on:'(1/10)') 
claus
parents: 325
diff changeset
   236
     Number readSmalltalkSyntaxFrom:(ReadStream on:'+00000123.45')  
claus
parents: 325
diff changeset
   237
     Number readFrom:(ReadStream on:'+00000123.45')  
5013
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   238
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   239
     |s|
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   240
     s := ReadStream on:'2.'.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   241
     Number readSmalltalkSyntaxFrom:s.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   242
     s next    
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   243
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   244
     |s|
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   245
     s := ReadStream on:'2.0.'.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   246
     Number readSmalltalkSyntaxFrom:s.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   247
     s next    
329
claus
parents: 325
diff changeset
   248
    "
3613
75629df7f224 fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents: 3394
diff changeset
   249
5013
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   250
    "Modified: / 19.11.1999 / 18:26:47 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   251
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   252
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   253
!Number class methodsFor:'error reporting'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   254
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   255
raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel arg:arg errorString:text 
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   256
    "ST-80 compatible signal raising. Provided for PD numeric classes"
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   257
4558
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   258
    <context: #return>
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   259
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   260
    ^ self
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   261
        raise:aSignalSymbolOrErrorClass 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   262
        receiver:someNumber 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   263
        selector:sel 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   264
        arguments:(Array with:arg)
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   265
        errorString:text 
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   266
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   267
    "
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   268
     Number 
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   269
        raise:#domainErrorSignal
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   270
        receiver:1.0
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   271
        selector:#sin
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   272
        arg:nil
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   273
        errorString:'foo bar test'
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   274
    "
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   275
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   276
    "Modified: / 16.11.2001 / 14:12:50 / cg"
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   277
!
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   278
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   279
raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel arguments:argArray errorString:text 
6194
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   280
    "ST-80 compatible signal raising. Provided for PD numeric classes.
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   281
     aSignalSymbolOrErrorClass is either an Error-subclass, or
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   282
     the selector which is sent to myself, to retrieve the Exception class / Signal."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   283
4558
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   284
    <context: #return>
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   285
6194
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   286
    |msg signalOrException|
701
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
    msg := MessageSend
6194
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   289
                receiver:someNumber
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   290
                selector:sel
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   291
                arguments:argArray.
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   292
6194
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   293
    aSignalSymbolOrErrorClass isSymbol ifTrue:[
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   294
        signalOrException := self perform:aSignalSymbolOrErrorClass.
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   295
    ] ifFalse:[
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   296
        signalOrException := aSignalSymbolOrErrorClass.    "/ assume its an Error-Subclass
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   297
    ].
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   298
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   299
    ^ signalOrException
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   300
         raiseRequestWith:msg 
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   301
         errorString:text 
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   302
         in:thisContext sender
701
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
    "
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   305
     Number 
6194
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   306
        raise:#domainErrorSignal
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   307
        receiver:1.0
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   308
        selector:#foo 
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   309
        errorString:'foo bar test'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   310
    "
6194
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   311
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   312
    "Modified: / 16.11.2001 / 14:12:09 / cg"
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   313
!
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   314
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   315
raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel errorString:text 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   316
    "ST-80 compatible signal raising. Provided for PD numeric classes.
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   317
     aSignalSymbolOrErrorClass is either an Error-subclass, or
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   318
     the selector which is sent to myself, to retrieve the Exception class / Signal."
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   319
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   320
    <context: #return>
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   321
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   322
    ^ self
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   323
        raise:aSignalSymbolOrErrorClass 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   324
        receiver:someNumber 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   325
        selector:sel 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   326
        arguments:#()
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   327
        errorString:text 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   328
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   329
    "
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   330
     Number 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   331
        raise:#domainErrorSignal
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   332
        receiver:1.0
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   333
        selector:#foo 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   334
        errorString:'foo bar test'
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   335
    "
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   336
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   337
    "Modified: / 16.11.2001 / 14:13:16 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   338
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   339
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   340
!Number class methodsFor:'private'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   341
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   342
readMantissaAndScaleFrom:aStream radix:radix
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   343
    "helper for readFrom: -
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   344
     return the mantissa (post-decimal-point digits) from the (character-)stream aStream;
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   345
     In addition, the scale (number of postDecimalPoint digits) is returned 
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   346
     (to support reading fixedPoint numbers).
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   347
     No whitespace is skipped.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   348
     Errs if no number is available on aStream."
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   349
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   350
    |nextChar value factor intMantissa scale|
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   351
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   352
    value := 0.0.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   353
    factor := 1.0 / radix.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   354
    scale := 0.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   355
    intMantissa := 0.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   356
    nextChar := aStream peekOrNil.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   357
    [nextChar notNil and:[nextChar isDigitRadix:radix]] whileTrue:[
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   358
        value := value + (nextChar digitValue * factor).
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   359
        intMantissa := (intMantissa * radix) + nextChar digitValue.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   360
        factor := factor / radix.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   361
        scale := scale + 1.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   362
        factor < (Float epsilon * 2) ifTrue:[
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   363
            value := value asLongFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   364
        ].
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   365
        aStream next.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   366
        nextChar := aStream peekOrNil
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   367
    ].
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   368
    ^ (Array with:value with:intMantissa with:scale).
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   369
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   370
    "
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   371
     Number readMantissaAndScaleFrom:'234'    readStream radix:10. 
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   372
     Number readMantissaAndScaleFrom:'2'      readStream radix:10. 
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   373
     Number readMantissaAndScaleFrom:'234567' readStream radix:10. 
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   374
     Number readMantissaAndScaleFrom:'234000' readStream radix:10. 
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   375
     Number readMantissaAndScaleFrom:'234'    readStream radix:10. 
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   376
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   377
     Number readMantissaAndScaleFrom:'12345678901234567890' readStream radix:10. 
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   378
    "
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   379
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   380
    "Modified: / 14.4.1998 / 18:47:47 / cg"
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   381
!
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   382
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   383
readMantissaFrom:aStream radix:radix
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   384
    "helper for readFrom: -
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   385
     return the mantissa (post-decimal-point digits)
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   386
     from the (character-)stream aStream;
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   387
     No whitespace is skipped.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   388
     Errs if no number available."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   389
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   390
    ^ (self readMantissaAndScaleFrom:aStream radix:radix) first
3375
7c64da3964e4 faster conversion from string (due to slow #pastEnd)
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
   391
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   392
    "
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   393
     Number readMantissaFrom:'234'    readStream radix:10.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   394
     Number readMantissaFrom:'2'      readStream radix:10.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   395
     Number readMantissaFrom:'234567' readStream radix:10.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   396
    "
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   397
3375
7c64da3964e4 faster conversion from string (due to slow #pastEnd)
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
   398
    "Modified: / 14.4.1998 / 18:47:47 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   399
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   400
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7214
diff changeset
   401
!Number methodsFor:'Compatibility-Squeak'!
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   402
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   403
asSmallAngleDegrees
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   404
	"Return the receiver normalized to lie within the range (-180, 180)"
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   405
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   406
	| pos |
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   407
	pos _ self \\ 360.
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   408
	pos > 180 ifTrue: [pos _ pos - 360].
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   409
	^ pos
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   410
6072
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   411
"#(-500 -300 -150 -5 0 5 150 300 500 1200) collect: [:n | n asSmallAngleDegrees]"
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   412
!
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   413
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   414
closeFrom:aNumber
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   415
    "are these two numbers close?"
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   416
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   417
    | fuzz |
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   418
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   419
    self isNaN == aNumber isNaN ifFalse: [^ false]. 
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   420
    self isInfinite == aNumber isInfinite ifFalse: [^ false].
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   421
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   422
    fuzz := (self abs max:aNumber abs) * 0.0001. 
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   423
    ^ (self - aNumber) abs <= fuzz
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   424
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   425
    "
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   426
     9.0 closeTo: 8.9999     
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   427
     9.9 closeTo: 9          
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   428
     (9/3) closeTo: 2.9999      
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   429
     1 closeTo: 0.9999      
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   430
     1 closeTo: 1.0001      
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   431
     1 closeTo: 1.001       
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   432
     1 closeTo: 0.999       
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   433
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   434
     0.9999 closeTo: 1      
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   435
     1.0001 closeTo: 1      
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   436
     1.001 closeTo: 1     
6345
cfe5db4fe391 Only comments
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
   437
     0.999 closeTo: 1
cfe5db4fe391 Only comments
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
   438
     Float NaN closeTo:Float NaN
cfe5db4fe391 Only comments
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
   439
     Float infinity closeTo:Float infinity
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   440
    "
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   441
!
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   442
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   443
closeTo:num
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   444
    "are these two numbers close?"
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   445
6374
fad888313ce3 closeTo: fix
Claus Gittinger <cg@exept.de>
parents: 6345
diff changeset
   446
    num isNumber ifFalse:[^false].
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   447
    ^ num closeFrom:self
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   448
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   449
    "
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   450
     1 closeTo:1.0000000001
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   451
     1 closeTo:1.001
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   452
    "
6155
00eaf2fa55bc isReal comment
Claus Gittinger <cg@exept.de>
parents: 6154
diff changeset
   453
00eaf2fa55bc isReal comment
Claus Gittinger <cg@exept.de>
parents: 6154
diff changeset
   454
    "Created: / 5.11.2001 / 18:07:26 / cg"
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   455
!
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   456
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   457
newTileMorphRepresentative
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   458
	^ TileMorph new addArrows; setLiteral: self; addSuffixIfCan
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   459
!
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   460
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   461
stringForReadout
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   462
    ^ self rounded printString
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   463
! !
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   464
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7214
diff changeset
   465
!Number methodsFor:'Compatibility-VW'!
6584
4aa036c5fdcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6374
diff changeset
   466
4aa036c5fdcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6374
diff changeset
   467
** aNumber
4aa036c5fdcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6374
diff changeset
   468
    ^ self raisedTo:aNumber
4aa036c5fdcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6374
diff changeset
   469
! !
4aa036c5fdcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6374
diff changeset
   470
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   471
!Number methodsFor:'coercing'!
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   472
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   473
retry: aSymbol coercing: aNumber
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   474
    "Arithmetic represented by the symbol, aSymbol,
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   475
    could not be performed with the receiver and the argument,
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   476
    aNumber, because of the differences in representation.  Coerce either
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   477
    the receiver or the argument, depending on which has higher generality, and
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   478
    try again.  If the symbol is the equals sign, answer false if the argument
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   479
    is not a Number.  If the generalities are the same, create an error message."
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   480
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   481
    |myGenerality otherGenerality|
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   482
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   483
    (aSymbol == #=) ifTrue:[
6702
545b50725894 infinitz query fix (int * point)
Claus Gittinger <cg@exept.de>
parents: 6692
diff changeset
   484
        (aNumber respondsTo:#generality) ifFalse:[^ false]
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   485
    ] ifFalse:[
6702
545b50725894 infinitz query fix (int * point)
Claus Gittinger <cg@exept.de>
parents: 6692
diff changeset
   486
        (aNumber respondsTo:#generality) ifFalse:[
545b50725894 infinitz query fix (int * point)
Claus Gittinger <cg@exept.de>
parents: 6692
diff changeset
   487
            self error:'retry:coercing: argument is not a number'.
545b50725894 infinitz query fix (int * point)
Claus Gittinger <cg@exept.de>
parents: 6692
diff changeset
   488
            ^ self
545b50725894 infinitz query fix (int * point)
Claus Gittinger <cg@exept.de>
parents: 6692
diff changeset
   489
        ]
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   490
    ].
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   491
    myGenerality := self generality.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   492
    otherGenerality := aNumber generality.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   493
    (myGenerality > otherGenerality) ifTrue:[
6702
545b50725894 infinitz query fix (int * point)
Claus Gittinger <cg@exept.de>
parents: 6692
diff changeset
   494
        ^ self perform:aSymbol with:(self coerce:aNumber)
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   495
    ].
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   496
    (myGenerality < otherGenerality) ifTrue:[
6702
545b50725894 infinitz query fix (int * point)
Claus Gittinger <cg@exept.de>
parents: 6692
diff changeset
   497
        (aNumber isNumber and:[aNumber isInfinite]) ifTrue: [
545b50725894 infinitz query fix (int * point)
Claus Gittinger <cg@exept.de>
parents: 6692
diff changeset
   498
            ^ aNumber retryReverseOf:aSymbol with:self
545b50725894 infinitz query fix (int * point)
Claus Gittinger <cg@exept.de>
parents: 6692
diff changeset
   499
        ].
545b50725894 infinitz query fix (int * point)
Claus Gittinger <cg@exept.de>
parents: 6692
diff changeset
   500
        ^ (aNumber coerce:self) perform:aSymbol with:aNumber
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   501
    ].
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   502
    self error:'retry:coercing: oops - same generality'
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   503
! !
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   504
5238
f7a816a660a3 categories
Claus Gittinger <cg@exept.de>
parents: 5013
diff changeset
   505
!Number methodsFor:'coercing & converting'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   506
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   507
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   508
    "return aNumber converted into receivers type"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   509
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   510
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   511
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   512
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   513
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   514
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   515
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   516
    ^ 40
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   517
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   518
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   519
!Number methodsFor:'converting'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   520
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   521
% aNumber 
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   522
    "Return a complex number with the receiver as the real part and 
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   523
     aNumber as the imaginary part"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   524
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   525
    ^ Complex real:self imaginary:aNumber
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   526
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   527
    "Modified: / 9.7.1998 / 10:18:12 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   528
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   529
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   530
@ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   531
    "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
   532
     as y-coordinate"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   533
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   534
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   535
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   536
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   537
     * I cannot tell if this special code is worth anything
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   538
     */
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   539
    if (__CanDoQuickNew(sizeof(struct __Point))) {      /* OBJECT ALLOCATION */
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   540
	OBJ newPoint;
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   541
	int spc;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   542
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   543
	__qCheckedAlignedNew(newPoint, sizeof(struct __Point));
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   544
	__InstPtr(newPoint)->o_class = @global(Point);
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   545
	__PointInstPtr(newPoint)->p_x = self;
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   546
	__PointInstPtr(newPoint)->p_y = aNumber;
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   547
	if (! __bothSmallInteger(self, aNumber)) {
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   548
	    spc = __qSpace(newPoint);
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   549
	    __STORE_SPC(newPoint, aNumber, spc);
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   550
	    __STORE_SPC(newPoint, self, spc);
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   551
	}
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   552
	RETURN ( newPoint );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   553
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   554
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   555
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   556
    ^ Point x:self y:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   557
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   558
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   559
asComplex
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   560
    "Return a complex number with the receiver as the real part and 
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   561
     zero as the imaginary part"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   562
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   563
    ^ Complex real:self
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   564
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   565
    "Modified: / 9.7.1998 / 10:18:16 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   566
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   567
7214
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
   568
asNumber
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
   569
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
   570
    ^ self.
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
   571
!
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
   572
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   573
asPoint
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   574
    "return a new Point with the receiver as all coordinates;  
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   575
     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
   576
     symmetrical gridding or scaling."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   577
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   578
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   579
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   580
    if (__CanDoQuickNew(sizeof(struct __Point))) {      /* OBJECT ALLOCATION */
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   581
	OBJ newPoint;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   582
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   583
	__qCheckedAlignedNew(newPoint, sizeof(struct __Point));
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   584
	__InstPtr(newPoint)->o_class = @global(Point);
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   585
	__PointInstPtr(newPoint)->p_x = self;
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   586
	__PointInstPtr(newPoint)->p_y = self;
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   587
	__STORE(newPoint, self);
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   588
	RETURN ( newPoint );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   589
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   590
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   591
    ^ Point x:self y:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   592
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   593
2416
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   594
decodeAsLiteralArray
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   595
    "given a literalEncoding in the receiver,
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   596
     create & return the corresponding object.
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   597
     The inverse operation to #literalArrayEncoding."
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   598
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   599
    ^ self
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   600
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   601
    "Created: 25.2.1997 / 19:17:06 / cg"
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   602
    "Modified: 25.2.1997 / 19:17:42 / cg"
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   603
!
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   604
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   605
degreesToRadians
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   606
    "interpreting the receiver as radians, return the degrees"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   607
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   608
    ^ (self * (Float pi)) / 180.0
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   609
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   610
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   611
literalArrayEncoding
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   612
    "encode myself as an array literal, from which a copy of the receiver
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   613
     can be reconstructed with #decodeAsLiteralArray."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   614
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   615
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   616
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   617
    "Modified: 1.9.1995 / 02:25:26 / claus"
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   618
    "Modified: 22.4.1996 / 13:00:27 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   619
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   620
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   621
radiansToDegrees
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   622
    "interpreting the receiver as degrees, return the radians"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   623
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   624
    ^ (self * 180.0) / (Float pi)
6637
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   625
!
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   626
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   627
withScale:newScale
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   628
    "return a fixedPoint number representing the same valie as the receiver, 
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   629
     with newScale number of post-decimal digits"
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   630
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   631
    ^ self asFixedPoint:newScale
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   632
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   633
    "
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   634
     1234 withScale:2 
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   635
     1234.1 withScale:2 
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   636
     1234.12 withScale:2 
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   637
     1234.123 withScale:2 
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   638
     (1/7) withScale:2
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   639
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   640
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   641
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   642
!Number methodsFor:'intervals'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   643
6072
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   644
downTo:stop
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   645
    "return an interval from receiver down to the argument, incrementing by -1"
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   646
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   647
    ^ self to:stop by:-1
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   648
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   649
    "
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   650
     (10 downTo:1) do:[:i | Transcript showCR:i].
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   651
    "
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   652
!
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   653
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   654
to:stop
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   655
    "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
   656
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   657
    ^ Interval from:self to:stop
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   658
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   659
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   660
to:stop by:step
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   661
    "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
   662
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   663
    ^ Interval from:self to:stop by:step
6154
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   664
!
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   665
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   666
to:stop byFactor:factor
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   667
    "return a geometric series from receiver up to the argument;
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   668
     elements have a constant factor in between"
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   669
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   670
    ^ GeometricSeries from:self to:stop byFactor:factor
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   671
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   672
    "
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   673
     (1 to:256 byFactor:2)
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   674
     (256 to:1 byFactor:1/2)     
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   675
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   676
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   677
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   678
!Number methodsFor:'iteration'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   679
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   680
timesRepeat:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   681
    "evaluate the argument, aBlock self times"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   682
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   683
    |count|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   684
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   685
    count := self.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   686
    [count > 0] whileTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   687
	aBlock value.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   688
	count := count - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   689
    ]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   690
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   691
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   692
!Number methodsFor:'mathematical functions'!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   693
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   694
conjugated
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   695
    "Return the complex conjugate of this Number."
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   696
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   697
    ^ self
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   698
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   699
    "Modified: / 9.7.1998 / 10:17:31 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   700
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   701
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   702
imaginary
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   703
    "Return the imaginary part of this Number."
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   704
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   705
    ^ 0
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   706
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   707
    "Modified: / 9.7.1998 / 10:17:24 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   708
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   709
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   710
real
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   711
    "Return the real part of this Number."
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   712
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   713
    ^ self
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   714
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   715
    "Modified: / 9.7.1998 / 10:17:17 / cg"
6258
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
   716
!
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
   717
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
   718
timesTwoPower:anInteger
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
   719
    "Return the receiver multiplied by 2.0 raised to the power of the argument.
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
   720
     For protocol completeness wrt. Squeak and ST80."
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
   721
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
   722
    ^ self * (2.0 raisedToInteger:anInteger)
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
   723
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
   724
    "
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
   725
     123 timesTwoPower:0  
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
   726
     123 timesTwoPower:1  
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
   727
     123 timesTwoPower:2  
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
   728
     123 timesTwoPower:3  
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
   729
    "
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   730
! !
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   731
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   732
!Number methodsFor:'printing & storing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   733
5299
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   734
printOn:aStream paddedWith:padCharacter to:size base:radix
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   735
    |s|
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   736
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   737
    s := self printStringRadix:radix.
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   738
    s printOn: aStream leftPaddedTo:size with: padCharacter
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   739
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   740
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   741
!
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   742
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   743
storeOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   744
    "append a string for storing the receiver onto the argument,
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   745
     aStream - since numbers are literals,they store as they print."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   746
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   747
    ^ self printOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   748
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   749
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   750
storeString
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   751
    "return a string for storing 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   752
     - since numbers are literals, they store as they print."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   753
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   754
    ^ self printString
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   755
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   756
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   757
!Number methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   758
5360
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   759
isDivisibleBy:aNumber
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   760
    "return true, if the receiver can be divided by the argument, aNumber without a remainder.
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   761
     Notice, that the result is only worth trusting, if the receiver is an integer."
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   762
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   763
    aNumber = 0 ifTrue: [^ false].
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   764
    aNumber isInteger ifFalse: [^ false].
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   765
    ^ (self \\ aNumber) = 0
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   766
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   767
    "
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   768
     3 isDivisibleBy:2     
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   769
     4 isDivisibleBy:2
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   770
     4.0 isDivisibleBy:2   
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   771
     4.5 isDivisibleBy:4.5 
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   772
     4.5 isDivisibleBy:1.0 
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   773
    "
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   774
!
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   775
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   776
isFinite
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   777
	^true
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   778
!
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   779
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   780
isInfinite
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   781
	^false
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   782
!
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   783
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   784
isNaN
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   785
    "return true, if the receiver is an invalid float (NaN - not a number)."
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   786
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   787
    ^ false
6155
00eaf2fa55bc isReal comment
Claus Gittinger <cg@exept.de>
parents: 6154
diff changeset
   788
00eaf2fa55bc isReal comment
Claus Gittinger <cg@exept.de>
parents: 6154
diff changeset
   789
    "Created: / 5.11.2001 / 18:07:26 / cg"
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   790
!
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   791
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   792
isNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   793
    "return true, if the receiver is a kind of number"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   794
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   795
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   796
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   797
6087
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
   798
isReal
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
   799
    "return true, if the receiver is some kind of real number (as opposed to a complex);
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
   800
     true is returned here - the method is redefined from Object."
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
   801
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
   802
    ^ true
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
   803
!
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
   804
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   805
isZero
1557
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   806
    "return true, if the receiver is zero"
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   807
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   808
    ^ self = 0
1557
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   809
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   810
    "Modified: 18.7.1996 / 12:40:49 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   811
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   812
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   813
!Number methodsFor:'tracing'!
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   814
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4659
diff changeset
   815
traceInto:aRequestor level:level from:referrer
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   816
    "double dispatch into tracer, passing my type implicitely in the selector"
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   817
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4659
diff changeset
   818
    ^ aRequestor traceNumber:self level:level from:referrer
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   819
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   820
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   821
! !
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   822
5552
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5360
diff changeset
   823
!Number methodsFor:'truncation & rounding'!
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   824
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   825
detentBy: detent atMultiplesOf: grid snap: snap
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   826
    "Map all values that are within detent/2 of any multiple of grid 
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   827
     to that multiple.  
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   828
     Otherwise, if snap is true, return self, meaning that the values 
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   829
     in the dead zone will never be returned.  
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   830
     If snap is false, then expand the range between dead zones
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   831
     so that it covers the range between multiples of the grid, 
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   832
     and scale the value by that factor."
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   833
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   834
    | r1 r2 |
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   835
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   836
    r1 := self roundTo: grid.                    "Nearest multiple of grid"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   837
    (self roundTo: detent) = r1 ifTrue: [^ r1].  "Snap to that multiple..."
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   838
    snap ifTrue: [^ self].                       "...or return self"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   839
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   840
    r2 := self < r1                               "Nearest end of dead zone"
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   841
	    ifTrue: [r1 - (detent asFloat/2)]
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   842
	    ifFalse: [r1 + (detent asFloat/2)].
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   843
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   844
    "Scale values between dead zones to fill range between multiples"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   845
    ^ r1 + ((self - r2) * grid asFloat / (grid - detent))
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   846
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   847
    "
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   848
     (170 to: 190 by: 2) collect: [:a | a detentBy: 10 atMultiplesOf: 90 snap: true]         
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   849
     (170 to: 190 by: 2) collect: [:a | a detentBy: 10 atMultiplesOf: 90 snap: false]
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   850
     (3.9 to: 4.1 by: 0.02) collect: [:a | a detentBy: 0.1 atMultiplesOf: 1.0 snap: true]    
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   851
     (-3.9 to: -4.1 by: -0.02) collect: [:a | a detentBy: 0.1 atMultiplesOf: 1.0 snap: false]
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   852
    "
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   853
!
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   854
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   855
fractionPart
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   856
    "return a float with value from digits after the decimal point.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   857
     i.e. the receiver minus its truncated value,
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   858
     such that (self truncated + self fractionPart) = self"
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   859
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   860
    ^ self - self truncated
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   861
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   862
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   863
     1234.56789 fractionPart
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   864
     1.2345e6 fractionPart  
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   865
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   866
     1.6 asLongFloat fractionPart + 1.6 asLongFloat truncated    
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   867
     -1.6 asLongFloat fractionPart + -1.6 asLongFloat truncated    
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   868
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   869
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   870
    "Modified: / 4.11.1996 / 20:26:54 / cg"
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   871
    "Created: / 28.10.1998 / 17:14:40 / cg"
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   872
!
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   873
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   874
integerPart
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   875
    "return a float with value from digits before the decimal point
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   876
     (i.e. the truncated value)"
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   877
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   878
    ^ self truncated asFloat
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   879
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   880
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   881
     1234.56789 integerPart 
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   882
     1.2345e6 integerPart   
6154
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   883
     12.5 integerPart 
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   884
     -12.5 integerPart 
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   885
     (5/3) integerPart  
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   886
     (-5/3) integerPart 
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   887
     (5/3) truncated  
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   888
     (-5/3) truncated  
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   889
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   890
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   891
    "Created: / 28.10.1998 / 17:14:56 / cg"
6154
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
   892
    "Modified: / 5.11.2001 / 17:54:22 / cg"
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   893
! !
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   894
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   895
!Number class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   896
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   897
version
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   898
    ^ '$Header: /cvs/stx/stx/libbasic/Number.st,v 1.82 2003-06-16 09:17:12 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   899
! !