Number.st
author Claus Gittinger <cg@exept.de>
Fri, 07 Apr 2000 10:10:40 +0200
changeset 5360 1aef297d3cbe
parent 5322 411b6c0f7250
child 5552 31b5cc144476
permissions -rw-r--r--
added #isDivisibleBy:
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
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    57
    ^ self readFrom:aString
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    58
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    59
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    60
     Number fromString:'12345'
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    61
     '12345' asNumber
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    62
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    63
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    64
    "Modified: / 3.8.1998 / 20:05:11 / cg"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    65
!
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    66
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    67
fromString:aString onError:exceptionBlock
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    68
    "for compatibility with other smalltalks - same as #readFrom:"
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    69
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    70
    ^ self readFrom:aString onError:exceptionBlock
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    71
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    72
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    73
     Number fromString:'12345' onError:0
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    74
     Number fromString:'fooBarBaz' onError:0
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    75
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    76
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    77
    "Modified: / 3.8.1998 / 20:05:34 / cg"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    78
!
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    79
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    80
readFrom:aStringOrStream onError:exceptionBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    81
    "return the next Number from the (character-)stream aStream;
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    82
     skipping all whitespace first; return the value of exceptionBlock,
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    83
     if no number can be read."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    84
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
    85
    |value|
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
    86
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
    87
    ErrorSignal handle:[:ex |
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
    88
	^ exceptionBlock value
339
claus
parents: 329
diff changeset
    89
    ] do:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
    90
	|str nextChar radix negative signExp|
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
    91
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
    92
	str := aStringOrStream readStream.
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
    93
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
    94
	nextChar := str skipSeparators.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
    95
	nextChar isNil ifTrue:[^ exceptionBlock value].
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
    96
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
    97
	(nextChar == $-) ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
    98
	    negative := true.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
    99
	    str next.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   100
	    nextChar := str peekOrNil
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   101
	] ifFalse:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   102
	    negative := false.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   103
	    (nextChar == $+) ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   104
		str next.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   105
		nextChar := str peekOrNil
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   106
	    ]
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   107
	].
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   108
	(nextChar isDigit or:[nextChar == $.]) ifFalse:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   109
	    ^ exceptionBlock value.
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   110
"/          value := super readFrom:str.
339
claus
parents: 329
diff changeset
   111
"/          negative ifTrue:[value := value negated].
claus
parents: 329
diff changeset
   112
"/          ^ value
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   113
	].
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   114
	nextChar == $. ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   115
	    radix := 10.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   116
	    value := 0.0.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   117
	] ifFalse:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   118
	    value := Integer readFrom:str radix:10.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   119
	    nextChar := str peekOrNil.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   120
	    ((nextChar == $r) or:[ nextChar == $R]) ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   121
		str next.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   122
		radix := value.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   123
		value := Integer readFrom:str radix:radix.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   124
	    ] ifFalse:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   125
		radix := 10
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   126
	    ].
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   127
	].
4637
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4558
diff changeset
   128
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   129
	(nextChar == $.) ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   130
	    str next.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   131
	    nextChar := str peekOrNil.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   132
	    (nextChar notNil and:[nextChar isDigitRadix:radix]) ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   133
		value := value asFloat 
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   134
			 + (Number readMantissaFrom:str radix:radix).
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   135
		nextChar := str peekOrNil
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   136
	    ]
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   137
	].
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   138
	((nextChar == $e) or:[nextChar == $E]) ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   139
	    str next.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   140
	    nextChar := str peekOrNil.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   141
	    signExp := 1.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   142
	    (nextChar == $+) ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   143
		str next.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   144
		nextChar := str peekOrNil.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   145
	    ] ifFalse:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   146
		(nextChar == $-) ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   147
		    str next.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   148
		    nextChar := str peekOrNil.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   149
		    signExp := -1
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   150
		]
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   151
	    ].
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   152
	    (nextChar notNil and:[(nextChar isDigitRadix:radix)]) ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   153
		value := value asFloat 
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   154
			 * (10.0 raisedToInteger:
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   155
				    ((Integer readFrom:str radix:radix) * signExp))
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   156
	    ]
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   157
	].
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   158
	negative ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   159
	    value := value negated
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   160
	].
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
   161
    ].
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
   162
    ^ value.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   163
329
claus
parents: 325
diff changeset
   164
    "
claus
parents: 325
diff changeset
   165
     Number readFrom:(ReadStream on:'54.32e-01')      
claus
parents: 325
diff changeset
   166
     Number readFrom:(ReadStream on:'12345678901234567890') 
claus
parents: 325
diff changeset
   167
     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
   168
     Number readFrom:'16rAAAAFFFFAAAAFFFF' 
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   169
     Number readFrom:'0.000001'  
329
claus
parents: 325
diff changeset
   170
     '+00000123.45' asNumber  
claus
parents: 325
diff changeset
   171
    "
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   172
3375
7c64da3964e4 faster conversion from string (due to slow #pastEnd)
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
   173
    "Modified: / 14.4.1998 / 19:22:50 / cg"
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   174
!
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   175
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   176
readSmalltalkSyntaxFrom:aStream
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   177
    "ST-80 compatibility (thanks to a note from alpha testers)
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   178
     read and return the next Number in smalltalk syntax from the 
329
claus
parents: 325
diff changeset
   179
     (character-)stream aStream."
claus
parents: 325
diff changeset
   180
3613
75629df7f224 fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents: 3394
diff changeset
   181
    ^ Scanner scanNumberFrom:aStream
75629df7f224 fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents: 3394
diff changeset
   182
"/    ^ Compiler evaluate:aStream compile:false "/ self readFrom:aStream.
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   183
329
claus
parents: 325
diff changeset
   184
    "
claus
parents: 325
diff changeset
   185
     Number readSmalltalkSyntaxFrom:(ReadStream on:'54.32e-01')    
claus
parents: 325
diff changeset
   186
     Number readSmalltalkSyntaxFrom:(ReadStream on:'12345678901234567890')
claus
parents: 325
diff changeset
   187
     Number readSmalltalkSyntaxFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
claus
parents: 325
diff changeset
   188
     Number readSmalltalkSyntaxFrom:(ReadStream on:'(1/10)') 
claus
parents: 325
diff changeset
   189
     Number readFrom:(ReadStream on:'(1/10)') 
claus
parents: 325
diff changeset
   190
     Number readSmalltalkSyntaxFrom:(ReadStream on:'+00000123.45')  
claus
parents: 325
diff changeset
   191
     Number readFrom:(ReadStream on:'+00000123.45')  
5013
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   192
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   193
     |s|
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   194
     s := ReadStream on:'2.'.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   195
     Number readSmalltalkSyntaxFrom:s.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   196
     s next    
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   197
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   198
     |s|
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   199
     s := ReadStream on:'2.0.'.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   200
     Number readSmalltalkSyntaxFrom:s.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   201
     s next    
329
claus
parents: 325
diff changeset
   202
    "
3613
75629df7f224 fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents: 3394
diff changeset
   203
5013
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   204
    "Modified: / 19.11.1999 / 18:26:47 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   205
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   206
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   207
!Number class methodsFor:'error reporting'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   208
3613
75629df7f224 fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents: 3394
diff changeset
   209
raise:aSignalSymbol receiver:someNumber selector:sel arg:arg errorString:text 
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   210
    "ST-80 compatible signal raising. Provided for PD numeric classes"
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   211
4558
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   212
    <context: #return>
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   213
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   214
    |msg|
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   215
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   216
    msg := MessageSend
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   217
		receiver:someNumber
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   218
		selector:sel
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   219
		arguments:(Array with:arg).
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   220
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   221
    ^ (self perform:aSignalSymbol)
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   222
	 raiseRequestWith:msg 
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   223
	 errorString:text 
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   224
	 in:thisContext sender
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   225
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   226
    "
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   227
     Number 
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   228
	raise:#domainErrorSignal
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   229
	receiver:1.0
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   230
	selector:#sin
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   231
	arg:nil
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   232
	errorString:'foo bar test'
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   233
    "
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   234
!
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   235
3613
75629df7f224 fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents: 3394
diff changeset
   236
raise:aSignalSymbol receiver:someNumber selector:sel arguments:argArray errorString:text 
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   237
    "ST-80 compatible signal raising. Provided for PD numeric classes"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   238
4558
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   239
    <context: #return>
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   240
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   241
    |msg|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   242
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   243
    msg := MessageSend
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   244
		receiver:someNumber
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   245
		selector:sel
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   246
		arguments:argArray.
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   247
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   248
    ^ (self perform:aSignalSymbol)
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   249
	 raiseRequestWith:msg 
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   250
	 errorString:text 
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   251
	 in:thisContext sender
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   252
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   253
    "
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   254
     Number 
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   255
	raise:#domainErrorSignal
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   256
	receiver:1.0
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   257
	selector:#sin
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   258
	arg:nil
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   259
	errorString:'foo bar test'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   260
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   261
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   262
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   263
raise:aSignalSymbol receiver:someNumber selector:sel errorString:text 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   264
    "ST-80 compatible signal raising. Provided for PD numeric classes"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   265
4558
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   266
    <context: #return>
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   267
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   268
    |msg|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   269
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   270
    msg := MessageSend
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   271
		receiver:someNumber
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   272
		selector:sel
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   273
		arguments:#().
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   274
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   275
    ^ (self perform:aSignalSymbol)
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   276
	 raiseRequestWith:msg 
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   277
	 errorString:text 
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   278
	 in:thisContext sender
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   279
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   280
    "
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   281
     Number 
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   282
	raise:#domainErrorSignal
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   283
	receiver:1.0
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   284
	selector:#foo 
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   285
	errorString:'foo bar test'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   286
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   287
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   288
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   289
!Number class methodsFor:'private'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   290
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   291
readMantissaFrom:aStream radix:radix
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   292
    "helper for readFrom: -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   293
     return the mantissa from the (character-)stream aStream;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   294
     no whitespace-skipping; error if no number available"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   295
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   296
    |nextChar value factor|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   297
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   298
    value := 0.0.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   299
    factor := 1.0 / radix.
3375
7c64da3964e4 faster conversion from string (due to slow #pastEnd)
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
   300
    nextChar := aStream peekOrNil.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   301
    [nextChar notNil and:[nextChar isDigitRadix:radix]] whileTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   302
	value := value + (nextChar digitValue * factor).
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   303
	factor := factor / radix.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   304
	aStream next.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   305
	nextChar := aStream peekOrNil
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   306
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   307
    ^ value
3375
7c64da3964e4 faster conversion from string (due to slow #pastEnd)
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
   308
7c64da3964e4 faster conversion from string (due to slow #pastEnd)
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
   309
    "Modified: / 14.4.1998 / 18:47:47 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   310
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   311
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   312
!Number methodsFor:'Compatibility - Squeak'!
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   313
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   314
asSmallAngleDegrees
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   315
	"Return the receiver normalized to lie within the range (-180, 180)"
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   316
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   317
	| pos |
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   318
	pos _ self \\ 360.
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   319
	pos > 180 ifTrue: [pos _ pos - 360].
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   320
	^ pos
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   321
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   322
"#(-500 -300 -150 -5 0 5 150 300 500 1200) collect: [:n | n asSmallAngleDegrees]"!
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   323
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   324
newTileMorphRepresentative
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   325
	^ TileMorph new addArrows; setLiteral: self; addSuffixIfCan
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   326
!
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   327
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   328
stringForReadout
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   329
    ^ self rounded printString
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   330
! !
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   331
5238
f7a816a660a3 categories
Claus Gittinger <cg@exept.de>
parents: 5013
diff changeset
   332
!Number methodsFor:'coercing & converting'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   333
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   334
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   335
    "return aNumber converted into receivers type"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   336
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   337
    ^ self subclassResponsibility
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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   340
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   341
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   342
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   343
    ^ 40
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   344
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   345
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   346
!Number methodsFor:'converting'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   347
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   348
% aNumber 
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   349
    "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
   350
     aNumber as the imaginary part"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   351
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   352
    ^ Complex real:self imaginary:aNumber
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   353
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   354
    "Modified: / 9.7.1998 / 10:18:12 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   355
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   356
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   357
@ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   358
    "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
   359
     as y-coordinate"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   360
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   361
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   362
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   363
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   364
     * I cannot tell if this special code is worth anything
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   365
     */
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   366
    if (__CanDoQuickNew(sizeof(struct __Point))) {      /* OBJECT ALLOCATION */
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   367
	OBJ newPoint;
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   368
	int spc;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   369
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   370
	__qCheckedAlignedNew(newPoint, sizeof(struct __Point));
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   371
	__InstPtr(newPoint)->o_class = @global(Point);
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   372
	__PointInstPtr(newPoint)->p_x = self;
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   373
	__PointInstPtr(newPoint)->p_y = aNumber;
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   374
	if (! __bothSmallInteger(self, aNumber)) {
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   375
	    spc = __qSpace(newPoint);
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   376
	    __STORE_SPC(newPoint, aNumber, spc);
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   377
	    __STORE_SPC(newPoint, self, spc);
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   378
	}
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   379
	RETURN ( newPoint );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   380
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   381
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   382
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   383
    ^ Point x:self y:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   384
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   385
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   386
asComplex
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   387
    "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
   388
     zero as the imaginary part"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   389
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   390
    ^ Complex fromReal:self
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   391
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   392
    "Modified: / 9.7.1998 / 10:18:16 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   393
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   394
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   395
asPoint
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   396
    "return a new Point with the receiver as all coordinates;  
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   397
     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
   398
     symmetrical gridding or scaling."
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
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   401
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   402
    if (__CanDoQuickNew(sizeof(struct __Point))) {      /* OBJECT ALLOCATION */
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   403
	OBJ newPoint;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   404
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   405
	__qCheckedAlignedNew(newPoint, sizeof(struct __Point));
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   406
	__InstPtr(newPoint)->o_class = @global(Point);
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   407
	__PointInstPtr(newPoint)->p_x = self;
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   408
	__PointInstPtr(newPoint)->p_y = self;
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   409
	__STORE(newPoint, self);
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   410
	RETURN ( newPoint );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   411
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   412
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   413
    ^ Point x:self y:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   414
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   415
2416
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   416
decodeAsLiteralArray
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   417
    "given a literalEncoding in the receiver,
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   418
     create & return the corresponding object.
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   419
     The inverse operation to #literalArrayEncoding."
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   420
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   421
    ^ self
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   422
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   423
    "Created: 25.2.1997 / 19:17:06 / cg"
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   424
    "Modified: 25.2.1997 / 19:17:42 / cg"
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   425
!
588d5d510c10 literal encodings
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   426
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   427
degreesToRadians
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   428
    "interpreting the receiver as radians, return the degrees"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   429
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   430
    ^ (self * (Float pi)) / 180.0
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   431
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   432
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   433
literalArrayEncoding
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   434
    "encode myself as an array literal, from which a copy of the receiver
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   435
     can be reconstructed with #decodeAsLiteralArray."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   436
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   437
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   438
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   439
    "Modified: 1.9.1995 / 02:25:26 / claus"
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   440
    "Modified: 22.4.1996 / 13:00:27 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   441
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   442
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   443
radiansToDegrees
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   444
    "interpreting the receiver as degrees, return the radians"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   445
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   446
    ^ (self * 180.0) / (Float pi)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   447
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   448
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   449
!Number methodsFor:'intervals'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   450
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   451
to:stop
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   452
    "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
   453
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   454
    ^ Interval from:self to:stop
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   455
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   456
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   457
to:stop by:step
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   458
    "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
   459
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   460
    ^ Interval from:self to:stop by:step
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   461
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   462
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   463
!Number methodsFor:'iteration'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   464
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   465
timesRepeat:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   466
    "evaluate the argument, aBlock self times"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   467
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   468
    |count|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   469
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   470
    count := self.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   471
    [count > 0] whileTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   472
	aBlock value.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   473
	count := count - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   474
    ]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   475
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   476
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   477
to:stop by:incr do:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   478
    "For each element of the interval from the receiver up to the argument stop, incrementing
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   479
     by step, evaluate aBlock passing the element as argument."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   480
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   481
    |tmp|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   482
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   483
    tmp := self.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   484
    (incr > 0) ifTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   485
	[tmp <= stop] whileTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   486
	    aBlock value:tmp.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   487
	    tmp := tmp+incr
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   488
	]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   489
    ] ifFalse:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   490
	[tmp >= stop] whileTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   491
	    aBlock value:tmp.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   492
	    tmp := tmp+incr
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   493
	]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   494
    ]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   495
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   496
919
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   497
to:stop by:incr doWithBreak:aBlock
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   498
    "For each element of the interval from the receiver up to the argument stop, incrementing
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   499
     by step, evaluate aBlock passing the element as argument.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   500
     Pass a break argument, to allow for premature exit of the loop."
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   501
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   502
    |tmp break|
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   503
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   504
    break := [^ self].
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   505
    tmp := self.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   506
    (incr > 0) ifTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   507
	[tmp <= stop] whileTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   508
	    aBlock value:tmp value:break.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   509
	    tmp := tmp+incr
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   510
	]
919
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   511
    ] ifFalse:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   512
	[tmp >= stop] whileTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   513
	    aBlock value:tmp value:break.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   514
	    tmp := tmp+incr
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   515
	]
919
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   516
    ]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   517
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   518
    "
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   519
     1 to:100 by:5 doWithBreak:[:index :break |
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   520
	Transcript showCR:index printString.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   521
	index > 50 ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   522
	    break value
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   523
	].
919
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   524
     ]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   525
    "
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   526
!
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   527
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   528
to:stop do:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   529
    "For each element of the interval from the receiver up to the argument stop,
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   530
     evaluate aBlock, passing the number as argument."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   531
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   532
    |tmp|
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
    tmp := self.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   535
    [tmp <= stop] whileTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   536
	aBlock value:tmp.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   537
	tmp := tmp+1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   538
    ]
919
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   539
!
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   540
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   541
to:stop doWithBreak:aBlock
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   542
    "For each element of the interval from the receiver up to the argument stop,
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   543
     evaluate aBlock, passing the number as argument.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   544
     Pass a break argument, to allow for premature exit of the loop."
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   545
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   546
    |tmp break|
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   547
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   548
    break := [^ self].
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   549
    tmp := self.
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   550
    [tmp <= stop] whileTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   551
	aBlock value:tmp value:break.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   552
	tmp := tmp+1
919
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   553
    ]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   554
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   555
    "
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   556
     1 to:10 doWithBreak:[:index :break |
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   557
	Transcript showCR:index printString.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   558
	index > 5 ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   559
	    break value
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   560
	].
919
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   561
     ]
d285a0816e54 added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   562
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   563
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   564
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   565
!Number methodsFor:'mathematical functions'!
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
conjugated
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   568
    "Return the complex conjugate of this Number."
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   569
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   570
    ^ self
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   571
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   572
    "Modified: / 9.7.1998 / 10:17:31 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   573
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   574
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   575
imaginary
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   576
    "Return the imaginary part of this Number."
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   577
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   578
    ^ 0
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   579
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   580
    "Modified: / 9.7.1998 / 10:17:24 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   581
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   582
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   583
real
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   584
    "Return the real part of this Number."
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   585
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   586
    ^ self
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   587
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   588
    "Modified: / 9.7.1998 / 10:17:17 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   589
! !
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   590
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   591
!Number methodsFor:'printing & storing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   592
5299
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   593
printOn:aStream paddedWith:padCharacter to:size base:radix
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   594
    |s|
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   595
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   596
    s := self printStringRadix:radix.
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   597
    s printOn: aStream leftPaddedTo:size with: padCharacter
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   598
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   599
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   600
!
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
   601
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   602
storeOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   603
    "append a string for storing the receiver onto the argument,
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   604
     aStream - since numbers are literals,they store as they print."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   605
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   606
    ^ self printOn:aStream
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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   609
storeString
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   610
    "return a string for storing 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   611
     - since numbers are literals, they store as they print."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   612
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   613
    ^ self printString
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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   616
!Number methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   617
5360
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   618
isDivisibleBy:aNumber
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   619
    "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
   620
     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
   621
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   622
    aNumber = 0 ifTrue: [^ false].
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   623
    aNumber isInteger ifFalse: [^ false].
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   624
    ^ (self \\ aNumber) = 0
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   625
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   626
    "
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   627
     3 isDivisibleBy:2     
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   628
     4 isDivisibleBy:2
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   629
     4.0 isDivisibleBy:2   
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   630
     4.5 isDivisibleBy:4.5 
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   631
     4.5 isDivisibleBy:1.0 
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   632
    "
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   633
!
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   634
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   635
isNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   636
    "return true, if the receiver is a kind of number"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   637
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   638
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   639
!
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
isZero
1557
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   642
    "return true, if the receiver is zero"
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   643
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   644
    ^ self = 0
1557
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   645
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   646
    "Modified: 18.7.1996 / 12:40:49 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   647
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   648
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   649
!Number methodsFor:'tracing'!
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   650
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4659
diff changeset
   651
traceInto:aRequestor level:level from:referrer
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   652
    "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
   653
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4659
diff changeset
   654
    ^ aRequestor traceNumber:self level:level from:referrer
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   655
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   656
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   657
! !
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
   658
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   659
!Number methodsFor:'truncation and rounding'!
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   660
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   661
detentBy: detent atMultiplesOf: grid snap: snap
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   662
    "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
   663
     to that multiple.  
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   664
     Otherwise, if snap is true, return self, meaning that the values 
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   665
     in the dead zone will never be returned.  
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   666
     If snap is false, then expand the range between dead zones
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   667
     so that it covers the range between multiples of the grid, 
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   668
     and scale the value by that factor."
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   669
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   670
    | r1 r2 |
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   671
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   672
    r1 := self roundTo: grid.                    "Nearest multiple of grid"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   673
    (self roundTo: detent) = r1 ifTrue: [^ r1].  "Snap to that multiple..."
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   674
    snap ifTrue: [^ self].                       "...or return self"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   675
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   676
    r2 := self < r1                               "Nearest end of dead zone"
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   677
	    ifTrue: [r1 - (detent asFloat/2)]
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   678
	    ifFalse: [r1 + (detent asFloat/2)].
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   679
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   680
    "Scale values between dead zones to fill range between multiples"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   681
    ^ r1 + ((self - r2) * grid asFloat / (grid - detent))
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   682
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   683
    "
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   684
     (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
   685
     (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
   686
     (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
   687
     (-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
   688
    "
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   689
!
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
   690
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   691
fractionPart
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   692
    "return a float with value from digits after the decimal point.
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   693
     (i.e. the receiver minus its truncated value)"
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   694
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   695
    ^ self - self truncated asFloat
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   696
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   697
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   698
     1234.56789 fractionPart
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   699
     1.2345e6 fractionPart  
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   700
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   701
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   702
    "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
   703
    "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
   704
!
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   705
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   706
integerPart
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   707
    "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
   708
     (i.e. the truncated value)"
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   709
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   710
    ^ self truncated asFloat
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   711
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   712
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   713
     1234.56789 integerPart 
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   714
     1.2345e6 integerPart   
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   715
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   716
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   717
    "Modified: / 4.11.1996 / 20:26:21 / cg"
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   718
    "Created: / 28.10.1998 / 17:14:56 / cg"
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   719
! !
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
   720
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   721
!Number class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   722
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   723
version
5360
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   724
    ^ '$Header: /cvs/stx/stx/libbasic/Number.st,v 1.60 2000-04-07 08:10:40 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   725
! !