Number.st
author mawalch
Thu, 08 Jun 2017 14:04:49 +0200
changeset 21789 abf8de4b8720
parent 21634 312cdb36acc9
child 21812 4d60b6626208
permissions -rw-r--r--
#DOCUMENTATION by mawalch class: Number class comment/format in: #readIntegerFrom:radix:
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
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
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
"
5360
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
    12
"{ Package: 'stx:libbasic' }"
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
    13
17469
17e4b64a023b class: Number
Claus Gittinger <cg@exept.de>
parents: 17224
diff changeset
    14
"{ NameSpace: Smalltalk }"
17e4b64a023b class: Number
Claus Gittinger <cg@exept.de>
parents: 17224
diff changeset
    15
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    16
ArithmeticValue subclass:#Number
18850
172da07a4529 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18320
diff changeset
    17
	instanceVariableNames:''
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
    18
	classVariableNames:'DecimalPointCharacterForPrinting DecimalPointCharactersForReading
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
    19
		DefaultDisplayRadix'
18850
172da07a4529 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18320
diff changeset
    20
	poolDictionaries:''
172da07a4529 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18320
diff changeset
    21
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    24
!Number class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    25
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    26
copyright
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    27
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    28
 COPYRIGHT (c) 1988 by Claus Gittinger
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    29
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    30
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    31
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    32
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    33
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    34
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    35
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    36
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    37
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    38
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    39
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    40
documentation
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    41
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    42
    abstract superclass for all kinds of numbers
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    43
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
    44
    [class variables:]
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    45
	DecimalPointCharacterForPrinting          <Character>                     used when printing
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    46
	DecimalPointCharactersForReading          <Collection of Character>       accepted as decimalPointChars when reading
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    47
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    48
	DefaultDisplayRadix     the radix in which integers present their
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    49
				displayString (which is used in inspectors)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    50
				If you are to look at many hex numbers, bitmasks
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    51
				etc. you may set this to 2 or 16.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    52
				(avoids typing printStringRadix:.. all the time
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    53
				 - I know - I am lazy ;-). Default is 10.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    54
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    55
    [author:]
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    56
	Claus Gittinger
1628
da30f2f41db7 comment
Claus Gittinger <cg@exept.de>
parents: 1557
diff changeset
    57
da30f2f41db7 comment
Claus Gittinger <cg@exept.de>
parents: 1557
diff changeset
    58
    [see also:]
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    59
	Integer LargeInteger SmallInteger
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    60
	LimitedPrecisionReal Float ShortFloat
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    61
	Fraction FixedPoint
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    62
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    63
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    64
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    65
!Number class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    66
11944
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    67
fastFromString:aString
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    68
    "return the next Float, Integer or ShortFloat from the string.
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    69
     No spaces are skipped.
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    70
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    71
     This is a specially tuned entry (using a low-level C-call), which
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    72
     returns garbage if the argument string is not a valid float number.
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    73
     It has been added to allow high speed string decomposition into numbers,
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    74
     especially for mass-data."
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    75
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    76
    ^ self fastFromString:aString at:1
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    77
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    78
    "
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    79
     Float fromString:'12345.0'
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    80
     Float fastFromString:'12345.0'
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    81
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    82
     Integer fromString:'12345'
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    83
     Integer fastFromString:'12345'
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    84
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    85
     should be roughly 10times faster than the general method:
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    86
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    87
     Time millisecondsToRun:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    88
	100000 timesRepeat:[ Float fromString:'12345.0' ]
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    89
     ].
11944
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    90
     Time millisecondsToRun:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    91
	100000 timesRepeat:[ Float fastFromString:'12345.0' ]
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    92
     ].
11944
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    93
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    94
     Time millisecondsToRun:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    95
	100000 timesRepeat:[ Integer fromString:'12345' ]
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    96
     ].
11944
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    97
     Time millisecondsToRun:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    98
	100000 timesRepeat:[ Integer fastFromString:'12345' ]
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    99
     ].
11944
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
   100
    "
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
   101
!
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
   102
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   103
fromString:aString
17056
dfbf6a7fd352 class: Number
Claus Gittinger <cg@exept.de>
parents: 16656
diff changeset
   104
    "return a number by reading from aString.
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   105
     In contrast to readFrom:, no garbage is allowed after the number.
17056
dfbf6a7fd352 class: Number
Claus Gittinger <cg@exept.de>
parents: 16656
diff changeset
   106
     I.e. the string must contain exactly one valid number (with optional separators around)"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   107
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   108
    ^ self
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   109
	fromString:aString
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   110
	decimalPointCharacters:(self decimalPointCharactersForReading)
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   111
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   112
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   113
     Number fromString:'12345'
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   114
     Number fromString:'abc'
17056
dfbf6a7fd352 class: Number
Claus Gittinger <cg@exept.de>
parents: 16656
diff changeset
   115
     Number fromString:'1abc'   -> raises an error
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   116
     Number readFrom:'1abc'     -> reads a 1
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   117
     Number readFrom:'10/2'     -> reads a 10
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   118
     Number fromString:'10/2'   -> raises an error
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   119
     Number fromString:'(1/2)'  -> reads a fraction
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   120
     Number readFrom:'(1/2)'    -> reads a fraction
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   121
     Number readFrom:'(10/2)'   -> reads a 5
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   122
     '12345' asNumber
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   123
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   124
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   125
    "Modified: / 3.8.1998 / 20:05:11 / cg"
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   126
!
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   127
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   128
fromString:aString decimalPointCharacters:decimalPointCharacters
17056
dfbf6a7fd352 class: Number
Claus Gittinger <cg@exept.de>
parents: 16656
diff changeset
   129
    "return a number by reading from aString.
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   130
     In contrast to readFrom:, no garbage is allowed after the number.
17056
dfbf6a7fd352 class: Number
Claus Gittinger <cg@exept.de>
parents: 16656
diff changeset
   131
     I.e. the string must contain exactly one valid number (with optional separators around)"
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   132
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   133
    |s num|
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   134
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   135
    s := aString readStream.
18320
886e94df740b class: Number
Stefan Vogel <sv@exept.de>
parents: 17686
diff changeset
   136
    num := self readFrom:s decimalPointCharacters:decimalPointCharacters onError:[^ ConversionError raiseRequestErrorString:' - invalid number'].
17056
dfbf6a7fd352 class: Number
Claus Gittinger <cg@exept.de>
parents: 16656
diff changeset
   137
    s atEnd ifFalse:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   138
	s skipSeparators.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   139
	s atEnd ifFalse:[
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   140
	    ^ ConversionError raiseRequestErrorString:' - garbage at end of number'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   141
	].
17056
dfbf6a7fd352 class: Number
Claus Gittinger <cg@exept.de>
parents: 16656
diff changeset
   142
    ].
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   143
    ^ num.
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   144
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   145
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   146
     Number fromString:'12345'
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   147
     Number fromString:'abc'
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   148
     Number fromString:'1abc'
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   149
     '12345' asNumber
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   150
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   151
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   152
    "Modified: / 3.8.1998 / 20:05:11 / cg"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   153
!
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   154
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   155
fromString:aString decimalPointCharacters:decimalPointCharacters onError:exceptionBlock
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   156
    "return a number by reading from aString.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   157
     In contrast to readFrom:, no garbage is allowed after the number.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   158
     I.e. the string must contain exactly one valid number (with optional separators around)"
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   159
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   160
    |s num|
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   161
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   162
    s := aString readStream.
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   163
    num := self readFrom:s decimalPointCharacters:decimalPointCharacters onError:[^ exceptionBlock value].
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   164
    s atEnd ifFalse:[
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   165
        s skipSeparators.
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   166
        s atEnd ifFalse:[
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   167
            ^ exceptionBlock value "/ - garbage at end of number'
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   168
        ].
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   169
    ].
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   170
    ^ num.
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   171
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   172
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   173
     Number fromString:'12345' onError:0
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   174
     Number fromString:'12,345' decimalPointCharacters:',' onError:0
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   175
     Number fromString:'12,345' decimalPointCharacters:',' onError:0
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   176
     Number fromString:'fooBarBaz' onError:0
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   177
     Number fromString:'123fooBarBaz' onError:0
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   178
     Number fromString:'123,fooBarBaz' decimalPointCharacters:',' onError:0
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   179
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   180
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   181
    "Modified: / 3.8.1998 / 20:05:34 / cg"
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   182
!
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   183
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   184
fromString:aString onError:exceptionBlock
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   185
    "return a number by reading from aString.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   186
     In contrast to readFrom:, no garbage is allowed after the number.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   187
     I.e. the string must contain exactly one valid number (with optional separators around)"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   188
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   189
    ^ self fromString:aString decimalPointCharacters:(self decimalPointCharactersForReading) onError:exceptionBlock
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   190
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   191
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   192
     Number fromString:'12345' onError:0
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   193
     Number fromString:'fooBarBaz' onError:0
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   194
     Number fromString:'123fooBarBaz' onError:0
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   195
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   196
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   197
    "Modified: / 3.8.1998 / 20:05:34 / cg"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   198
!
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   199
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   200
readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   201
    "return the next Number from the (character-)stream aStream;
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   202
     skipping all whitespace first.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   203
     Return the value of exceptionBlock, if no number can be read.
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   204
     This method is less strict than the smalltalk number reader; it
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   205
     allows for prefixed + and also allows missing fractional part after eE.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   206
     It also allows garbage after the number - i.e. it reads what it can.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   207
     See #fromString: , which is more strict and does not allow garbage at the end."
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   208
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   209
    ^ self
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   210
	readFrom:aStringOrStream
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   211
	decimalPointCharacters:decimalPointCharacters
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   212
	onError:[self error:'conversion error for: ' , self name]
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   213
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   214
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   215
     Number readFrom:'123.456' decimalPointCharacters:'.'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   216
     Number readFrom:'123,456' decimalPointCharacters:'.,'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   217
     Number readFrom:'123,456' decimalPointCharacters:'.'
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   218
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   219
!
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   220
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   221
readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters onError:exceptionBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   222
    "return the next Number from the (character-)stream aStream;
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   223
     skipping all whitespace first.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   224
     Return the value of exceptionBlock, if no number can be read.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   225
     This method is less strict than the smalltalk number reader; it
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   226
     allows for prefixed + and also allows missing fractional part after eE.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   227
     It also allows garbage after the number - i.e. it reads what it can.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   228
     See #fromString: , which is more strict and does not allow garbage at the end."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   229
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   230
    ^ [
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   231
        |value intValue mantissaAndScale scale decimalMantissa str
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   232
         nextChar radix sign signExp exp numerator denom|
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   233
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   234
        str := aStringOrStream readStream.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   235
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   236
        nextChar := str skipSeparators.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   237
        nextChar isNil ifTrue:[^ exceptionBlock value].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   238
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   239
        (nextChar == $-) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   240
            sign := -1.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   241
            str next.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   242
            nextChar := str peekOrNil
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   243
        ] ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   244
            sign := 1.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   245
            (nextChar == $+) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   246
                str next.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   247
                nextChar := str peekOrNil
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   248
            ]
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   249
        ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   250
        nextChar == $( ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   251
            "maybe a Fraction e.g. (1/3)"
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   252
            str next.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   253
            numerator := Integer readFrom:str onError:[^ exceptionBlock value].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   254
            str skipSeparators.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   255
            nextChar := str peekOrNil.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   256
            nextChar == $/ ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   257
                str next.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   258
                denom := Integer readFrom:str onError:[^ exceptionBlock value].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   259
                str skipSeparators.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   260
                nextChar := str peekOrNil.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   261
            ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   262
            nextChar == $) ifFalse:[^ exceptionBlock value].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   263
            str next.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   264
            value := Fraction numerator:numerator denominator:denom.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   265
            ^ value * sign
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   266
        ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   267
        nextChar isNil ifTrue:[^ exceptionBlock value].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   268
        (nextChar isDigit or:[(decimalPointCharacters includes:nextChar)]) ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   269
            ^ exceptionBlock value.
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   270
"/          value := super readFrom:str.
15197
a78cec832ef3 class: Number
Claus Gittinger <cg@exept.de>
parents: 15127
diff changeset
   271
"/          sign == -1 ifTrue:[value := value negated].
339
claus
parents: 329
diff changeset
   272
"/          ^ value
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   273
        ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   274
        (decimalPointCharacters includes:nextChar) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   275
            radix := 10.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   276
            value := 0.0.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   277
            intValue := 0.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   278
        ] ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   279
            value := Integer readFrom:str radix:10.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   280
            nextChar := str peekOrNil.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   281
            ((nextChar == $r) or:[ nextChar == $R]) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   282
                str next.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   283
                radix := value.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   284
                value := Integer readFrom:str radix:radix.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   285
                nextChar := str peekOrNil.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   286
            ] ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   287
                radix := 10
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   288
            ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   289
            intValue := value.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   290
        ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   291
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   292
        (self == Integer or:[self inheritsFrom:Integer]) ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   293
            (decimalPointCharacters includes:nextChar) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   294
                str next.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   295
                nextChar := str peekOrNil.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   296
                decimalMantissa := 0.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   297
                (nextChar notNil and:[nextChar isDigitRadix:radix]) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   298
                    |mantissa|
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   299
                    mantissaAndScale := self readMantissaAndScaleFrom:str radix:radix.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   300
                    mantissa := mantissaAndScale first.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   301
                    value := (mantissa coerce:value) + mantissa.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   302
                    nextChar := str peekOrNil.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   303
                ]
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   304
            ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   305
            ('eEdDqQ' includes:nextChar) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   306
                str next.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   307
                nextChar := str peekOrNil.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   308
                signExp := 1.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   309
                (nextChar == $+) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   310
                    str next.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   311
                    nextChar := str peekOrNil.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   312
                ] ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   313
                    (nextChar == $-) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   314
                        str next.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   315
                        nextChar := str peekOrNil.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   316
                        signExp := -1
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   317
                    ]
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   318
                ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   319
                ('qQ' includes:nextChar) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   320
                    value := value asLongFloat.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   321
                ] ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   322
                    value := value asFloat.
16450
9a81e708b188 class: Number
Stefan Vogel <sv@exept.de>
parents: 16406
diff changeset
   323
"/ future: (for now, always create Doubles for Dolphin,Squeak etc. compatibility)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   324
"/                ('eE' includes:nextChar) ifTrue:[
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   325
"/                    value := value asShortFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   326
"/                ]
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   327
                ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   328
                (nextChar notNil and:[(nextChar isDigitRadix:radix)]) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   329
                    exp := (Integer readFrom:str radix:radix) * signExp.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   330
                    value := value * ((value class unity * 10.0) raisedToInteger:exp)
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   331
                ]
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   332
            ] ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   333
                ('sS' includes:nextChar) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   334
                    str next.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   335
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   336
                    nextChar := str peekOrNil.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   337
                    (nextChar notNil and:[ nextChar isDigit]) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   338
                        scale := (Integer readFrom:str).
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   339
                    ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   340
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   341
                    mantissaAndScale isNil ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   342
                        value := intValue asFixedPoint:(scale ? 0).
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   343
                    ] ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   344
                        denom := 10 raisedTo:mantissaAndScale last.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   345
                        value := FixedPoint
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   346
                                    numerator:(intValue * denom) + (mantissaAndScale second)
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   347
                                    denominator:denom
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   348
                                    scale:(scale ? mantissaAndScale third).
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   349
                    ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   350
                ] ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   351
                    (self inheritsFrom:LimitedPrecisionReal) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   352
                        "when requesting a specific Float instance, coerce it.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   353
                         otherwise return a value without loosing precision"
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   354
                        value := self coerce:value.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   355
                    ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   356
                ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   357
            ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   358
        ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   359
        sign == -1 ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   360
            value := value negated
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   361
        ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   362
        value.
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   363
    ] on:Error do:exceptionBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   364
329
claus
parents: 325
diff changeset
   365
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   366
     Number readFrom:(ReadStream on:'54.32e-01')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   367
     Number readFrom:(ReadStream on:'12345678901234567890')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   368
     Number readFrom:(ReadStream on:'12345678901234567890.0')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   369
     Number readFrom:(ReadStream on:'12345678901234567890.012345678901234567890')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   370
     Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   371
     Number readFrom:'16rAAAAFFFFAAAAFFFF'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   372
     Number readFrom:'0.000001'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   373
     '+00000123.45' asNumber
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   374
     Number readFrom:'(1/3)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   375
     Number readFrom:'(-1/3)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   376
     Number readFrom:'(1/-3)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   377
     Number readFrom:'-(1/3)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   378
     Number readFrom:'-(-1/3)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   379
     Number readFrom:'(-1/3'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   380
     Number readFrom:'99s'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   381
     Number readFrom:'99.00s'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   382
     Number readFrom:'99.0000000s'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   383
     Number readFrom:'.0000000s'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   384
     Number readFrom:'.0000000q'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   385
     Number readFrom:'.0000000f'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   386
     Number readFrom:'.0000000e'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   387
     Number readFrom:'.0000000s1'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   388
     Number readFrom:'.0000000q1'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   389
     Number readFrom:'.0000000f1'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   390
     Number readFrom:'.0000000e1'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   391
     LongFloat readFrom:'.00000001'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   392
     Number readFrom:'.00000000000001'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   393
     Number readFrom:'.001'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   394
     ShortFloat readFrom:'.001'
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   395
     Number readFrom:'123garbage'      -> returns 123
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   396
     Number fromString:'123garbage'    -> raises an error
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   397
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   398
     DecimalPointCharactersForReading := #( $. $, ).
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   399
     Number readFrom:'99,00'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   400
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   401
     DecimalPointCharactersForReading := #( $. ).
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   402
     Number readFrom:'99,00'
329
claus
parents: 325
diff changeset
   403
    "
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   404
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   405
    "Modified: / 09-03-2017 / 16:21:17 / cg"
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   406
!
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   407
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   408
readFrom:aStringOrStream onError:exceptionBlock
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   409
    "return the next Number from the (character-)stream aStream;
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   410
     skipping all whitespace first; return the value of exceptionBlock,
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   411
     if no number can be read.
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   412
     This method is less strict than the smalltalk number reader; it
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   413
     allows for prefixed + and also allows missing fractional part after eE.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   414
     It also allows garbage after the number - i.e. it reads what it can.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   415
     See #fromString: , which is more strict and does not allow garbage at the end."
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   416
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   417
    ^ self
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   418
	readFrom:aStringOrStream
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   419
	decimalPointCharacters:(self decimalPointCharactersForReading)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   420
	onError:exceptionBlock
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   421
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   422
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   423
     Number readFrom:(ReadStream on:'54.32e-01')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   424
     Number readFrom:(ReadStream on:'12345678901234567890')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   425
     Number readFrom:(ReadStream on:'12345678901234567890.0')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   426
     Number readFrom:(ReadStream on:'12345678901234567890.012345678901234567890')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   427
     Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   428
     Number readFrom:'16rAAAAFFFFAAAAFFFF'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   429
     Number readFrom:'0.000001'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   430
     '+00000123.45' asNumber
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   431
     Number readFrom:'99s'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   432
     Number readFrom:'99.00s'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   433
     Number readFrom:'99.0000000s'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   434
     Number readFrom:'.0000000s'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   435
     Number readFrom:'.0000000q'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   436
     Number readFrom:'.0000000f'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   437
     Number readFrom:'.0000000e'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   438
     Number readFrom:'.0000000s1'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   439
     Number readFrom:'.0000000q1'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   440
     Number readFrom:'.0000000f1'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   441
     Number readFrom:'.0000000e1'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   442
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   443
     DecimalPointCharactersForReading := #( $. $, ).
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   444
     Number readFrom:'99,00'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   445
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   446
     DecimalPointCharactersForReading := #( $. ).
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   447
     Number readFrom:'99,00'
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   448
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   449
!
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   450
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   451
readSmalltalkSyntaxFrom:aStream
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   452
    "ST-80 compatibility (thanks to a note from alpha testers)
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   453
     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
   454
     (character-) aStream.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   455
     Returns nil if aStream contains no valid number."
329
claus
parents: 325
diff changeset
   456
15776
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   457
    ^ self readSmalltalkSyntaxFrom:aStream onError:nil.
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   458
329
claus
parents: 325
diff changeset
   459
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   460
     Number readSmalltalkSyntaxFrom:'99d'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   461
     Number readSmalltalkSyntaxFrom:'99.00d'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   462
     Number readSmalltalkSyntaxFrom:'54.32e-01'
15078
997a122ceeb5 class: Number
Stefan Vogel <sv@exept.de>
parents: 14495
diff changeset
   463
     Number readSmalltalkSyntaxFrom:'12345678901234567890'
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   464
     Number readSmalltalkSyntaxFrom:'16rAAAAFFFFAAAAFFFF'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   465
     Number readSmalltalkSyntaxFrom:'foobar'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   466
     Number readSmalltalkSyntaxFrom:'(1/10)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   467
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   468
     Number readSmalltalkSyntaxFrom:'(1/0)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   469
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   470
     Number readFrom:'(1/3)'
15078
997a122ceeb5 class: Number
Stefan Vogel <sv@exept.de>
parents: 14495
diff changeset
   471
     Number readFrom:'(-1/3)'
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   472
     Number readFrom:'-(1/3)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   473
     Number readFrom:'(1/-3)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   474
     Number readFrom:'(-1/-3)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   475
     Number readFrom:'-(-1/-3)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   476
     Number readSmalltalkSyntaxFrom:'+00000123.45'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   477
     Number readFrom:'+00000123.45'
5013
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   478
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   479
     |s|
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   480
     s := ReadStream on:'2.'.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   481
     Number readSmalltalkSyntaxFrom:s.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   482
     s next
5013
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   483
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   484
     |s|
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   485
     s := ReadStream on:'2.0.'.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   486
     Number readSmalltalkSyntaxFrom:s.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   487
     s next
329
claus
parents: 325
diff changeset
   488
    "
3613
75629df7f224 fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents: 3394
diff changeset
   489
5013
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   490
    "Modified: / 19.11.1999 / 18:26:47 / cg"
15776
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   491
!
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   492
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   493
readSmalltalkSyntaxFrom:aStream onError:errorValue
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   494
    "ST-80 compatibility (thanks to a note from alpha testers)
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   495
     read and return the next Number in smalltalk syntax from the
15776
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   496
     (character-) aStream.
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   497
     Returns nil if aStream contains no valid number."
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   498
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   499
    |n|
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   500
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   501
    [
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   502
	n := Scanner scanNumberFrom:aStream.
15776
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   503
    ] on:Error do:[:ex|
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   504
	n := nil
15776
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   505
    ].
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   506
    n isNil ifTrue:[^ errorValue value].
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   507
    ^ n
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   508
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   509
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   510
     Number readSmalltalkSyntaxFrom:'foo' onError:123
15776
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   511
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   512
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   513
17686
f3233f56df6f class: Number
Claus Gittinger <cg@exept.de>
parents: 17469
diff changeset
   514
!Number class methodsFor:'Compatibility-VW'!
f3233f56df6f class: Number
Claus Gittinger <cg@exept.de>
parents: 17469
diff changeset
   515
f3233f56df6f class: Number
Claus Gittinger <cg@exept.de>
parents: 17469
diff changeset
   516
readIntegerFrom:aStream radix:radix
21789
abf8de4b8720 #DOCUMENTATION by mawalch
mawalch
parents: 21634
diff changeset
   517
    "for VisualWorks compatibility"
17686
f3233f56df6f class: Number
Claus Gittinger <cg@exept.de>
parents: 17469
diff changeset
   518
f3233f56df6f class: Number
Claus Gittinger <cg@exept.de>
parents: 17469
diff changeset
   519
    ^ Integer readFrom:aStream radix:radix
21789
abf8de4b8720 #DOCUMENTATION by mawalch
mawalch
parents: 21634
diff changeset
   520
abf8de4b8720 #DOCUMENTATION by mawalch
mawalch
parents: 21634
diff changeset
   521
    "Modified (comment): / 08-06-2017 / 13:58:36 / mawalch"
17686
f3233f56df6f class: Number
Claus Gittinger <cg@exept.de>
parents: 17469
diff changeset
   522
! !
f3233f56df6f class: Number
Claus Gittinger <cg@exept.de>
parents: 17469
diff changeset
   523
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   524
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
   525
!Number class methodsFor:'constants'!
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
   526
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   527
decimalPointCharacter
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   528
    "printed"
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   529
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   530
    <resource: #obsolete>
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   531
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   532
    ^ self decimalPointCharacterForPrinting
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   533
!
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   534
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   535
decimalPointCharacter:aCharacter
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   536
    "printed"
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   537
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   538
    <resource: #obsolete>
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   539
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   540
    self decimalPointCharacterForPrinting:aCharacter
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   541
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   542
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   543
     1.5 printString
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   544
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   545
     Number decimalPointCharacter:$,.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   546
     1.5 printString
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   547
     Number decimalPointCharacter:$..
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   548
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   549
!
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   550
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   551
decimalPointCharacterForPrinting
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   552
    "printed"
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   553
16267
beef1cb9c801 class: Number
Claus Gittinger <cg@exept.de>
parents: 16070
diff changeset
   554
    ^ DecimalPointCharacterForPrinting ? $.
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   555
!
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   556
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   557
decimalPointCharacterForPrinting:aCharacter
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   558
    "printed"
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   559
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   560
    DecimalPointCharacterForPrinting := aCharacter
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   561
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   562
    "
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   563
     1.5 printString
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   564
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
   565
     Number decimalPointCharacterForPrinting:$,.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   566
     1.5 printString
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
   567
     Number decimalPointCharacterForPrinting:$..
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   568
    "
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   569
!
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   570
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   571
decimalPointCharacters
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   572
    "accepted when converting from a string"
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   573
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   574
    <resource: #obsolete>
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   575
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   576
    ^ self decimalPointCharactersForReading
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   577
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   578
    "
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   579
     1.5 printString
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   580
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   581
     Number decimalPointCharacters:#( $. $,) .
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   582
     Number fromString:'1.5'.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   583
     Number fromString:'1,5'.
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   584
     Number decimalPointCharacters:#( $. ).
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   585
    "
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   586
!
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   587
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   588
decimalPointCharacters:aCollectionOfCharacters
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   589
    "accepted when converting from a string"
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   590
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   591
    <resource: #obsolete>
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   592
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   593
    self decimalPointCharactersForReading:aCollectionOfCharacters
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   594
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   595
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   596
     Number decimalPointCharacters:#( $. $,) .
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   597
     Number fromString:'1.5'.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   598
     Number fromString:'1,5'.
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   599
     Number decimalPointCharacters:#( $. ).
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   600
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   601
!
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   602
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   603
decimalPointCharactersForReading
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   604
    "default when converting from a string"
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   605
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   606
    "/ cg: changing the default leads to trouble in some
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   607
    "/ language processors (PrologScanner...)
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   608
    "/ PLEASE DO ONLY CHANGE THE DEFAULT BELOW FOR END-USER APPLICATIONS (if at all).
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   609
    "/ BETTER: pass the DecimalPointCharacterSet explicitly
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   610
    DecimalPointCharactersForReading isNil ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   611
	^ #( $. )
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   612
    ].
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   613
    ^ DecimalPointCharactersForReading
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   614
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   615
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   616
     1.5 printString
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   617
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
   618
     Number decimalPointCharactersForReading:#( $. $,) .
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   619
     Number fromString:'1.5'.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   620
     Number fromString:'1,5'.
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
   621
     Number decimalPointCharactersForReading:#( $. ).
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   622
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   623
!
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   624
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   625
decimalPointCharactersForReading:aCollectionOfCharacters
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   626
    "accepted when converting from a string"
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   627
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   628
    DecimalPointCharactersForReading := aCollectionOfCharacters
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   629
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   630
    "
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
   631
     Number decimalPointCharactersForReading:#( $. $,) .
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   632
     Number fromString:'1.5'.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   633
     Number fromString:'1,5'.
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
   634
     Number decimalPointCharactersForReading:#( $. ).
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   635
    "
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   636
!
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   637
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
   638
epsilon
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   639
    "return the maximum relative spacing of instances of mySelf
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
   640
     (i.e. the value-delta of the least significant bit)"
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
   641
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
   642
     ^ self subclassResponsibility
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
   643
!
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
   644
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   645
epsilonForCloseTo
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   646
    "return the epsilon used in the closeTo: comparison.
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   647
     (useful would be something like self epsilon or epsilon*10,
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   648
      but for Squeak compatibility.... - sigh)"
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   649
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   650
    ^ 0.0001
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   651
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   652
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   653
     Float epsilon
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   654
     ShortFloat epsilon
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   655
     Float epsilon10
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   656
     ShortFloat epsilon10
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   657
    "
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   658
!
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   659
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
   660
pi
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
   661
    "return Pi in my representation (and accuracy)."
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
   662
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
   663
     ^ self subclassResponsibility
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
   664
! !
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
   665
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   666
!Number class methodsFor:'error reporting'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   667
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   668
raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel arg:arg errorString:text
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   669
    "ST-80 compatible signal raising. Provided for PD numeric classes"
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   670
4558
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   671
    <context: #return>
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   672
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   673
    ^ self
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   674
	raise:aSignalSymbolOrErrorClass
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   675
	receiver:someNumber
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   676
	selector:sel
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   677
	arguments:(Array with:arg)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   678
	errorString:text
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   679
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   680
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   681
     Number
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   682
	raise:#domainErrorSignal
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   683
	receiver:1.0
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   684
	selector:#sin
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   685
	arg:nil
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   686
	errorString:'foo bar test'
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   687
    "
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   688
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   689
    "Modified: / 16.11.2001 / 14:12:50 / cg"
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   690
!
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   691
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   692
raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel errorString:text
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   693
    "ST-80 compatible signal raising. Provided for PD numeric classes.
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   694
     aSignalSymbolOrErrorClass is either an Error-subclass, or
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   695
     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
   696
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   697
    <context: #return>
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   698
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   699
    ^ self
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   700
	raise:aSignalSymbolOrErrorClass
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   701
	receiver:someNumber
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   702
	selector:sel
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   703
	arguments:#()
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   704
	errorString:text
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   705
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   706
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   707
     Number
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   708
	raise:#domainErrorSignal
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   709
	receiver:1.0
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   710
	selector:#foo
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   711
	errorString:'foo bar test'
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   712
    "
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   713
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   714
    "Modified: / 16.11.2001 / 14:13:16 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   715
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   716
18863
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   717
!Number class methodsFor:'misc'!
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   718
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   719
displayRadix:aNumber
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   720
    "being tired of always sending #printStringRadix: in the inspectors,
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   721
     this allows you to change the default print radix for the displayString
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   722
     method."
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   723
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   724
    DefaultDisplayRadix := aNumber
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   725
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   726
    "
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   727
     Integer displayRadix:16. 123456 inspect
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   728
     Integer displayRadix:10. 123456 inspect
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   729
    "
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   730
! !
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
   731
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   732
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   733
!Number class methodsFor:'private'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   734
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   735
readMantissaAndScaleFrom:aStream radix:radix
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   736
    "helper for readFrom: -
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   737
     return the mantissa (post-decimal-point digits) from the (character-)stream aStream;
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   738
     In addition, the scale (number of postDecimalPoint digits) is returned
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   739
     (to support reading fixedPoint numbers).
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   740
     No whitespace is skipped.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   741
     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
   742
10321
c07d199084fc avoid double-send of digitValue
Claus Gittinger <cg@exept.de>
parents: 10320
diff changeset
   743
    |nextChar value factor intMantissa scale digit|
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   744
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   745
    value := 0.0.
10320
a573647dad4f avoid longfloats if possible
Claus Gittinger <cg@exept.de>
parents: 10191
diff changeset
   746
    factor := 1.0 / radix.
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   747
    scale := 0.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   748
    intMantissa := 0.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   749
    nextChar := aStream peekOrNil.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   750
    [nextChar notNil and:[nextChar isDigitRadix:radix]] whileTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   751
	digit := nextChar digitValue.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   752
	value := value + (digit * factor).
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   753
	intMantissa := (intMantissa * radix) + digit.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   754
	factor := factor / radix.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   755
	scale := scale + 1.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   756
	scale > 6 ifTrue:[
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   757
	    factor := factor asLongFloat.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   758
	    value := value asLongFloat.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   759
	].
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   760
	aStream next.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   761
	nextChar := aStream peekOrNil
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   762
    ].
7388
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   763
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   764
    ^ (Array with:value with:intMantissa with:scale).
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   765
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   766
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   767
     Number readMantissaAndScaleFrom:'234'    readStream radix:10.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   768
     Number readMantissaAndScaleFrom:'2'      readStream radix:10.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   769
     Number readMantissaAndScaleFrom:'234567' readStream radix:10.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   770
     Number readMantissaAndScaleFrom:'234000' readStream radix:10.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   771
     Number readMantissaAndScaleFrom:'234'    readStream radix:10.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   772
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   773
     Number readMantissaAndScaleFrom:'12345678901234567890' readStream radix:10.
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   774
    "
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   775
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   776
    "Modified: / 14.4.1998 / 18:47:47 / cg"
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   777
!
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   778
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   779
readMantissaFrom:aStream radix:radix
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   780
    "helper for readFrom: -
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   781
     return the mantissa (post-decimal-point digits)
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   782
     from the (character-)stream aStream;
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   783
     No whitespace is skipped.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   784
     Errs if no number available."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   785
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   786
    ^ (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
   787
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   788
    "
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   789
     Number readMantissaFrom:'234'    readStream radix:10.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   790
     Number readMantissaFrom:'2'      readStream radix:10.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   791
     Number readMantissaFrom:'234567' readStream radix:10.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   792
    "
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   793
3375
7c64da3964e4 faster conversion from string (due to slow #pastEnd)
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
   794
    "Modified: / 14.4.1998 / 18:47:47 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   795
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   796
8892
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
   797
!Number class methodsFor:'queries'!
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
   798
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
   799
isAbstract
11224
a9a66cee404f comment
Claus Gittinger <cg@exept.de>
parents: 11136
diff changeset
   800
    "Return if this class is an abstract class.
a9a66cee404f comment
Claus Gittinger <cg@exept.de>
parents: 11136
diff changeset
   801
     True is returned for Number here; false for subclasses.
19457
8f56a5bde306 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19249
diff changeset
   802
     Abstract subclasses must redefine this again."
11224
a9a66cee404f comment
Claus Gittinger <cg@exept.de>
parents: 11136
diff changeset
   803
8892
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
   804
    ^ self == Number
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
   805
! !
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
   806
21105
f51ebd03d20b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20866
diff changeset
   807
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7214
diff changeset
   808
!Number methodsFor:'Compatibility-Squeak'!
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   809
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   810
asSmallAngleDegrees
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   811
    "Return the receiver normalized to lie within the range (-180, 180)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   812
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   813
    | pos |
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   814
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   815
    pos := self \\ 360.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   816
    pos > 180 ifTrue: [pos := pos - 360].
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   817
    ^ pos
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   818
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   819
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   820
     #(-500 -300 -150 -5 0 5 150 300 500 1200)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   821
	collect: [:n | n asSmallAngleDegrees]
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   822
    "
6072
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   823
!
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   824
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   825
closeFrom:aNumber
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   826
    "are these two numbers close?"
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   827
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   828
    ^ self closeFrom:aNumber withEpsilon:(self class epsilonForCloseTo)
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   829
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   830
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   831
     9.0 closeTo: 8.9999
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   832
     9.9 closeTo: 9
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   833
     (9/3) closeTo: 2.9999
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   834
     1 closeTo: 0.9999
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   835
     1 closeTo: 1.0001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   836
     1 closeTo: 1.001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   837
     1 closeTo: 0.999
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   838
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   839
     0.9999 closeTo: 1
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   840
     1.0001 closeTo: 1
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   841
     1.001 closeTo: 1
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   842
     0.999 closeTo: 1
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   843
     Float NaN closeTo:Float NaN
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   844
     Float infinity closeTo:Float infinity
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   845
    "
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   846
!
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   847
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   848
closeFrom:aNumber withEpsilon:eps
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   849
    "are these two numbers close?"
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   850
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   851
    | fuzz |
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   852
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   853
    self isNaN == aNumber isNaN ifFalse: [^ false].
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   854
    self isInfinite == aNumber isInfinite ifFalse: [^ false].
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   855
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   856
    fuzz := (self abs max:aNumber abs) * eps.
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   857
    ^ (self - aNumber) abs <= fuzz
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   858
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   859
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   860
     9.0 closeTo: 8.9999
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   861
     9.9 closeTo: 9
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   862
     (9/3) closeTo: 2.9999
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   863
     1 closeTo: 0.9999
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   864
     1 closeTo: 1.0001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   865
     1 closeTo: 1.001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   866
     1 closeTo: 0.999
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   867
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   868
     0.9999 closeTo: 1
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   869
     1.0001 closeTo: 1
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   870
     1.001 closeTo: 1
6345
cfe5db4fe391 Only comments
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
   871
     0.999 closeTo: 1
cfe5db4fe391 Only comments
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
   872
     Float NaN closeTo:Float NaN
cfe5db4fe391 Only comments
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
   873
     Float infinity closeTo:Float infinity
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   874
    "
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   875
!
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   876
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   877
closeTo:num
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   878
    "are these two numbers close to each other?"
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   879
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   880
    ^ self closeTo:num withEpsilon:(self class epsilonForCloseTo)
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   881
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   882
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   883
     1 closeTo:1.0000000001
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   884
     1 closeTo:1.001
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   885
     1 closeTo:1.001 withEpsilon:0.001
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   886
    "
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   887
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   888
    "Created: / 5.11.2001 / 18:07:26 / cg"
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   889
!
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   890
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   891
closeTo:num withEpsilon:eps
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   892
    "are these two numbers close to each other?"
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   893
6374
fad888313ce3 closeTo: fix
Claus Gittinger <cg@exept.de>
parents: 6345
diff changeset
   894
    num isNumber ifFalse:[^false].
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   895
    ^ num closeFrom:self withEpsilon:eps
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   896
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   897
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   898
     1 closeTo:1.0000000001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   899
     1 closeTo:1.001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   900
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   901
     1 closeTo:1.001 withEpsilon:0.1
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   902
     1 closeTo:1.201 withEpsilon:0.1
12979
917a726bf375 comment/format in: #closeTo:withEpsilon:
Claus Gittinger <cg@exept.de>
parents: 12762
diff changeset
   903
917a726bf375 comment/format in: #closeTo:withEpsilon:
Claus Gittinger <cg@exept.de>
parents: 12762
diff changeset
   904
     3.14 closeTo:(3.14 asFixedPoint:2)
917a726bf375 comment/format in: #closeTo:withEpsilon:
Claus Gittinger <cg@exept.de>
parents: 12762
diff changeset
   905
     (3.14 asFixedPoint:2) closeTo:3.14
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   906
    "
6155
00eaf2fa55bc isReal comment
Claus Gittinger <cg@exept.de>
parents: 6154
diff changeset
   907
12979
917a726bf375 comment/format in: #closeTo:withEpsilon:
Claus Gittinger <cg@exept.de>
parents: 12762
diff changeset
   908
    "Created: / 05-11-2001 / 18:07:26 / cg"
917a726bf375 comment/format in: #closeTo:withEpsilon:
Claus Gittinger <cg@exept.de>
parents: 12762
diff changeset
   909
    "Modified: / 02-08-2010 / 13:27:22 / cg"
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   910
!
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   911
9139
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   912
degreeCos
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   913
    "Return the cosine of the receiver taken as an angle in degrees."
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   914
9139
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   915
    ^ self degreesToRadians cos
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   916
!
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   917
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   918
degreeSin
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   919
    "Return the sine of the receiver taken as an angle in degrees."
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   920
9139
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   921
    ^ self degreesToRadians sin
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   922
!
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   923
11712
b83c3734b1ce added #degreeTan
sr
parents: 11660
diff changeset
   924
degreeTan
b83c3734b1ce added #degreeTan
sr
parents: 11660
diff changeset
   925
    "Return the cosine of the receiver taken as an angle in degrees."
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   926
11712
b83c3734b1ce added #degreeTan
sr
parents: 11660
diff changeset
   927
    ^ self degreesToRadians tan
b83c3734b1ce added #degreeTan
sr
parents: 11660
diff changeset
   928
!
b83c3734b1ce added #degreeTan
sr
parents: 11660
diff changeset
   929
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   930
isEqual: aNumber within: accuracy
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   931
	^(self - aNumber) abs < accuracy
17127
f2611d8d0ce0 class: Number
Claus Gittinger <cg@exept.de>
parents: 17060
diff changeset
   932
!
f2611d8d0ce0 class: Number
Claus Gittinger <cg@exept.de>
parents: 17060
diff changeset
   933
14495
d5afe5bc91f7 added: #rounded:
Claus Gittinger <cg@exept.de>
parents: 14009
diff changeset
   934
rounded:n
d5afe5bc91f7 added: #rounded:
Claus Gittinger <cg@exept.de>
parents: 14009
diff changeset
   935
    "Answer the float rounded with n digits of precision"
d5afe5bc91f7 added: #rounded:
Claus Gittinger <cg@exept.de>
parents: 14009
diff changeset
   936
d5afe5bc91f7 added: #rounded:
Claus Gittinger <cg@exept.de>
parents: 14009
diff changeset
   937
    | mult |
d5afe5bc91f7 added: #rounded:
Claus Gittinger <cg@exept.de>
parents: 14009
diff changeset
   938
d5afe5bc91f7 added: #rounded:
Claus Gittinger <cg@exept.de>
parents: 14009
diff changeset
   939
    mult := 10 raisedTo: n.
d5afe5bc91f7 added: #rounded:
Claus Gittinger <cg@exept.de>
parents: 14009
diff changeset
   940
    ^ (((self * mult) rounded) asFloat / mult).
d5afe5bc91f7 added: #rounded:
Claus Gittinger <cg@exept.de>
parents: 14009
diff changeset
   941
d5afe5bc91f7 added: #rounded:
Claus Gittinger <cg@exept.de>
parents: 14009
diff changeset
   942
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   943
     7 rounded:2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   944
     7.1 rounded:2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   945
     7.2345 rounded:2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   946
     7.2385 rounded:2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   947
     7.2341 rounded:3
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   948
     7.2345 rounded:3
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   949
     7.2348 rounded:3
14495
d5afe5bc91f7 added: #rounded:
Claus Gittinger <cg@exept.de>
parents: 14009
diff changeset
   950
    "
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   951
! !
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   952
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   953
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   954
!Number methodsFor:'coercing & converting'!
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   955
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   956
i
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   957
    "return a complex number, with the receiver as imaginary part, 0 as real part"
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   958
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   959
    ^ Complex
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   960
	real:0
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   961
	imaginary:self
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   962
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   963
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   964
     3i
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   965
     (1+1i)
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   966
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   967
! !
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   968
16656
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   969
!Number methodsFor:'comparing'!
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   970
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   971
isAlmostEqualTo:aNumber nEpsilon:nE
16656
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   972
    "return true, if the argument, aNumber represents almost the same numeric value
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   973
     as the receiver, false otherwise.
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   974
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   975
     nE is the number of minimal float distances, that the numbers may differ and
17207
75c41a799425 class: Number
Claus Gittinger <cg@exept.de>
parents: 17190
diff changeset
   976
     still be considered equal. See documentation in LimitedPrecisionReal for more detail.
16656
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   977
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   978
     For background information why floats need this
16656
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   979
     read: http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   980
    "
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   981
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   982
    |f1 f2 diff scaledEpsilon largest|
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   983
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   984
    diff := (self - aNumber) abs.
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   985
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   986
    scaledEpsilon := nE * diff class epsilon.
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   987
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   988
    diff <= scaledEpsilon ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   989
	"compare for really close values near 0"
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   990
	^ true.
16656
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   991
    ] ifFalse:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   992
	"scaled comparison for larger values"
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   993
	f1 := self abs.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   994
	f2 := aNumber abs.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   995
	largest := f1 > f2 ifTrue:[f1] ifFalse:[f2].
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   996
	^ (diff <= (scaledEpsilon * largest)).
16656
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   997
    ].
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   998
! !
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
   999
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1000
!Number methodsFor:'converting'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1001
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1002
% aNumber
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1003
    "Return a complex number with the receiver as the real part and
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1004
     aNumber as the imaginary part"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1005
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1006
    ^ Complex real:self imaginary:aNumber
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1007
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1008
    "Modified: / 9.7.1998 / 10:18:12 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1009
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1010
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1011
+/- anError
14009
a2b68a9c9719 comment
Claus Gittinger <cg@exept.de>
parents: 13898
diff changeset
  1012
    "return a MeasurementValue with a given error."
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1013
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1014
    ^ MeasurementValue value:self minValue:(self-anError) maxValue:(self+anError)
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1015
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1016
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1017
     (100 +/- 5) * 2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1018
     (100 +/- 5) * (100 +/- 10)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1019
     (100 +/- 5) + (100 +/- 10)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1020
     (100 +/- 5) - (100 +/- 10)
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1021
    "
14009
a2b68a9c9719 comment
Claus Gittinger <cg@exept.de>
parents: 13898
diff changeset
  1022
a2b68a9c9719 comment
Claus Gittinger <cg@exept.de>
parents: 13898
diff changeset
  1023
    "Modified (comment): / 14-02-2012 / 14:17:36 / cg"
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1024
!
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1025
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1026
@ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1027
    "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
  1028
     as y-coordinate"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1029
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1030
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1031
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1032
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1033
     * I cannot tell if this special code is worth anything
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1034
     */
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
  1035
    if (__CanDoQuickNew(sizeof(struct __Point))) {      /* OBJECT ALLOCATION */
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1036
	OBJ newPoint;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1037
	int spc;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1038
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1039
	__qCheckedNew(newPoint, sizeof(struct __Point));
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1040
	__InstPtr(newPoint)->o_class = @global(Point);
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1041
	__qSTORE(newPoint, @global(Point));
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1042
	__PointInstPtr(newPoint)->p_x = self;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1043
	__PointInstPtr(newPoint)->p_y = aNumber;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1044
	if (! __bothSmallInteger(self, aNumber)) {
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1045
	    spc = __qSpace(newPoint);
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1046
	    __STORE_SPC(newPoint, aNumber, spc);
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1047
	    __STORE_SPC(newPoint, self, spc);
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1048
	}
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1049
	RETURN ( newPoint );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1050
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1051
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1052
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1053
    ^ Point x:self y:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1054
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1055
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1056
asComplex
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1057
    "Return a complex number with the receiver as the real part and
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1058
     zero as the imaginary part"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1059
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  1060
    ^ Complex real:self
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1061
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1062
    "Modified: / 9.7.1998 / 10:18:16 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1063
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1064
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1065
asMetaNumber
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1066
    ^ SomeNumber new realNumber:self
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1067
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1068
7214
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
  1069
asNumber
17060
7b39761eb1ce class: Number
Claus Gittinger <cg@exept.de>
parents: 17058
diff changeset
  1070
    "I am a number, so return myself"
7214
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
  1071
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
  1072
    ^ self.
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
  1073
!
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
  1074
19702
79ea925e1f35 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19701
diff changeset
  1075
asPercentFrom:fullAmount
79ea925e1f35 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19701
diff changeset
  1076
    "what is the percentage
79ea925e1f35 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19701
diff changeset
  1077
     taking the receiver's value from the argument"
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1078
19702
79ea925e1f35 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19701
diff changeset
  1079
    ^ (self / fullAmount) * 100.
19701
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1080
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1081
    "
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1082
     20 asPercentFrom:100
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1083
     (10 asPercentFrom:156) asFixedPoint:2
19702
79ea925e1f35 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19701
diff changeset
  1084
     (15.6 asPercentFrom:156) asFixedPoint:2
19701
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1085
    "
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1086
!
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1087
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1088
asPoint
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1089
    "return a new Point with the receiver as all coordinates;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1090
     often used to supply the same value in two dimensions, as with
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1091
     symmetrical gridding or scaling."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1092
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1093
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1094
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
  1095
    if (__CanDoQuickNew(sizeof(struct __Point))) {      /* OBJECT ALLOCATION */
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1096
	OBJ newPoint;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1097
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1098
	__qCheckedNew(newPoint, sizeof(struct __Point));
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1099
	__InstPtr(newPoint)->o_class = @global(Point);
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1100
	__qSTORE(newPoint, @global(Point));
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1101
	__PointInstPtr(newPoint)->p_x = self;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1102
	__PointInstPtr(newPoint)->p_y = self;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1103
	__STORE(newPoint, self);
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1104
	RETURN ( newPoint );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1105
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1106
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1107
    ^ Point x:self y:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1108
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1109
13898
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1110
asTimeDuration
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1111
    "return an TimeDuration object from the receiver, taking the receiver
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1112
     as number of seconds"
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1113
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1114
    ^ TimeDuration seconds:self
13898
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1115
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1116
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1117
     5 asTimeDuration
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1118
     50.25 asTimeDuration
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1119
     3600 asTimeDuration
13898
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1120
    "
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1121
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1122
    "Created: / 08-01-2012 / 19:04:04 / cg"
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1123
!
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1124
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1125
degreesToRadians
21105
f51ebd03d20b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20866
diff changeset
  1126
    "interpreting the receiver as degrees, return the radians"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1127
8203
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  1128
    ^ self * (Float pi / 180.0)
7388
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1129
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1130
    "
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1131
     180 degreesToRadians
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1132
     Float pi radiansToDegrees
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1133
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1134
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1135
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1136
literalArrayEncoding
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
  1137
    "encode myself as an array literal, from which a copy of the receiver
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
  1138
     can be reconstructed with #decodeAsLiteralArray."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1139
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1140
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1141
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1142
    "Modified: 1.9.1995 / 02:25:26 / claus"
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
  1143
    "Modified: 22.4.1996 / 13:00:27 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1144
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1145
19701
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1146
percentOf:hundredPercent
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1147
    "how many is self-percent from the argument"
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1148
19701
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1149
    ^ (hundredPercent / 100 * self)
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1150
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1151
    "
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1152
     20 percentOf:100
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1153
     (10 percentOf:156) asFixedPoint:2
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1154
     (105 percentOf:156) asFixedPoint:2
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1155
    "
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1156
!
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1157
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1158
radiansToDegrees
21105
f51ebd03d20b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20866
diff changeset
  1159
    "interpreting the receiver as radians, return the degrees"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1160
8203
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  1161
    ^ self * (180.0 / Float pi)
7388
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1162
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1163
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1164
     180 degreesToRadians
7388
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1165
     Float pi radiansToDegrees
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1166
    "
6637
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1167
!
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1168
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1169
withScale:newScale
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1170
    "return a fixedPoint number representing the same value as the receiver,
6637
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1171
     with newScale number of post-decimal digits"
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1172
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1173
    ^ self asFixedPoint:newScale
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1174
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1175
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1176
     1234 withScale:2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1177
     1234.1 withScale:2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1178
     1234.12 withScale:2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1179
     1234.123 withScale:2
6637
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1180
     (1/7) withScale:2
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1181
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1182
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1183
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1184
!Number methodsFor:'converting-times'!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1185
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1186
days
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1187
    "return a TimeDuration representing this number of days"
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1188
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1189
    ^ TimeDuration days:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1190
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1191
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1192
     1000 milliseconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1193
     10 seconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1194
     10 minutes
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1195
     1 days
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1196
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1197
!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1198
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1199
hours
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1200
    "return a TimeDuration representing this number of hours"
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1201
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1202
    ^ TimeDuration hours:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1203
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1204
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1205
     1000 milliseconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1206
     10 seconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1207
     10 minutes
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1208
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1209
!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1210
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1211
milliseconds
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1212
    "return a TimeDuration representing this number of milliseconds"
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1213
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1214
    ^ TimeDuration fromMilliseconds:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1215
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1216
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1217
     1000 milliseconds
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1218
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1219
!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1220
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1221
minutes
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1222
    "return a TimeDuration representing this number of minutes"
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1223
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1224
    ^ TimeDuration minutes:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1225
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1226
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1227
     1000 milliseconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1228
     10 seconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1229
     10 minutes
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1230
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1231
!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1232
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1233
seconds
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1234
    "return a TimeDuration representing this number of seconds"
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1235
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1236
    ^ TimeDuration seconds:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1237
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1238
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1239
     1000 milliseconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1240
     10 seconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1241
     10 minutes
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1242
    "
13631
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1243
!
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1244
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1245
weeks
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1246
    "return a TimeDuration representing this number of weeks"
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1247
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1248
    ^ TimeDuration weeks:self
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1249
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1250
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1251
     1000 milliseconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1252
     10 seconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1253
     10 minutes
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1254
     1 days
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1255
     1 weeks
13631
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1256
    "
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1257
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1258
    "Created: / 05-09-2011 / 11:17:59 / cg"
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1259
! !
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1260
16406
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1261
!Number methodsFor:'double dispatching'!
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1262
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1263
differenceFromTimestamp:aTimestamp
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1264
    "I am to be interpreted as seconds, return the timestamp this number of seconds
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1265
     before aTimestamp"
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1266
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1267
    ^ aTimestamp subtractMilliseconds:(self * 1000) truncated.
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1268
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1269
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1270
     100.0 differenceFromTimestamp:Timestamp now
16406
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1271
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1272
     |t1 t2|
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1273
     t1 := Timestamp now.
16406
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1274
     t2 := 1.5 differenceFromTimestamp:t1.
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1275
     t1 inspect. t2 inspect.
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1276
    "
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1277
! !
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1278
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1279
!Number methodsFor:'intervals'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1280
6072
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1281
downTo:stop
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1282
    "return an interval from receiver down to the argument, incrementing by -1"
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1283
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1284
    ^ self to:stop by:-1
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1285
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1286
    "
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1287
     (10 downTo:1) do:[:i | Transcript showCR:i].
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1288
    "
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1289
!
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1290
15595
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1291
downTo:stop by:step
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1292
    "return an interval from receiver down to the argument, decrementing by step"
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1293
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1294
    ^ self to:stop by:step negated
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1295
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1296
    "
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1297
     (10 downTo:1 by:0.5) do:[:i | Transcript showCR:i].
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1298
    "
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1299
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1300
    "Created: / 01-08-2013 / 14:36:56 / cg"
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1301
!
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1302
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1303
to:stop
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1304
    "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
  1305
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1306
    ^ Interval from:self to:stop
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1307
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1308
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1309
to:stop by:step
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1310
    "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
  1311
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1312
    ^ Interval from:self to:stop by:step
6154
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1313
!
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1314
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1315
to:stop byFactor:factor
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1316
    "return a geometric series from receiver up to the argument;
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1317
     elements have a constant factor in between"
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1318
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1319
    ^ GeometricSeries from:self to:stop byFactor:factor
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1320
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1321
    "
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1322
     (1 to:256 byFactor:2)
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1323
     (256 to:1 byFactor:1/2)
6154
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1324
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1325
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1326
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1327
!Number methodsFor:'iteration'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1328
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1329
timesRepeat:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1330
    "evaluate the argument, aBlock self times"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1331
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1332
    |count|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1333
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1334
    count := self.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1335
    [count > 0] whileTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1336
	aBlock value.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1337
	count := count - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1338
    ]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1339
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1340
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1341
!Number methodsFor:'mathematical functions'!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1342
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1343
cbrt
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1344
    "return the cubic root of the receiver"
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1345
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  1346
    "/ if I am not a Float (or a less general lpReal),
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  1347
    "/ retry after converting to float
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1348
    (self isLimitedPrecisionReal not
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1349
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1350
	^ self asFloat cbrt.
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1351
    ].
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  1352
    "/ very slow fallback
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1353
    ^ self cbrt_withAccuracy:self epsilon
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1354
!
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1355
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1356
conjugated
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1357
    "Return the complex conjugate of this Number."
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1358
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1359
    ^ self
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1360
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1361
    "Modified: / 9.7.1998 / 10:17:31 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1362
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1363
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1364
exp
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1365
    "compute e**x of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1366
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  1367
    "/ if I am not a Float (or a less general lpReal),
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  1368
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1369
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1370
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1371
	^ self asFloat exp.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1372
    ].
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  1373
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  1374
    ^ self exp_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1375
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1376
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1377
floorLog:radix
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1378
    "return the logarithm truncated as an integer"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1379
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1380
    ^ (self log:radix) floor
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1381
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1382
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1383
imaginary
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1384
    "Return the imaginary part of this Number."
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1385
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1386
    ^ 0
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1387
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1388
    "Modified: / 9.7.1998 / 10:17:24 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1389
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1390
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1391
ln
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1392
    "return the natural logarithm of myself.
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1393
     Raises an exception, if the receiver is less or equal to zero."
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1394
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  1395
    "/ if I am not a Float (or a less general lpReal),
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  1396
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1397
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1398
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1399
	^ self asLongFloat ln.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1400
    ].
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  1401
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  1402
    ^ self ln_withAccuracy:self epsilon
19249
Stefan Vogel <sv@exept.de>
parents: 19141
diff changeset
  1403
Stefan Vogel <sv@exept.de>
parents: 19141
diff changeset
  1404
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1405
	(10 raisedTo:1000) ln
19249
Stefan Vogel <sv@exept.de>
parents: 19141
diff changeset
  1406
    "
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1407
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1408
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1409
log
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1410
    "return log base 10 of the receiver.
12584
d32f98e9b219 comment/format in: #log
Claus Gittinger <cg@exept.de>
parents: 12112
diff changeset
  1411
     Alias for log:10."
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1412
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1413
    ^ self log10
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1414
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1415
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1416
log10
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1417
    "return log base 10 of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1418
10550
0f2a07595d1c Fix bug 641: changed #log10 to be more accurate
Stefan Vogel <sv@exept.de>
parents: 10325
diff changeset
  1419
    (self isLimitedPrecisionReal not
0f2a07595d1c Fix bug 641: changed #log10 to be more accurate
Stefan Vogel <sv@exept.de>
parents: 10325
diff changeset
  1420
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1421
	^ self asLongFloat log10.
10550
0f2a07595d1c Fix bug 641: changed #log10 to be more accurate
Stefan Vogel <sv@exept.de>
parents: 10325
diff changeset
  1422
    ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1423
    ^ self log:10
19249
Stefan Vogel <sv@exept.de>
parents: 19141
diff changeset
  1424
Stefan Vogel <sv@exept.de>
parents: 19141
diff changeset
  1425
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1426
	(10 raisedTo:1000) log10
19249
Stefan Vogel <sv@exept.de>
parents: 19141
diff changeset
  1427
    "
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1428
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1429
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1430
log:aNumber
18850
172da07a4529 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18320
diff changeset
  1431
    "return log base aNumber of the receiver.
172da07a4529 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18320
diff changeset
  1432
     This will usually return a float value"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1433
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1434
    ^ self ln / aNumber ln
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1435
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1436
    "
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1437
      1000 log:10
19049
7ab1aa4ef01e #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19041
diff changeset
  1438
      9 log:3
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1439
      (1000 log:10) floor
19249
Stefan Vogel <sv@exept.de>
parents: 19141
diff changeset
  1440
      (10 raisedTo:1000) log:10
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1441
    "
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1442
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1443
7468
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1444
raisedTo:aNumber
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1445
    "return the receiver raised to aNumber"
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1446
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1447
    aNumber = 0 ifTrue:[^ 1].
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1448
    aNumber = 1 ifTrue:[^ self].
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1449
    aNumber isInteger ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1450
	^ self raisedToInteger:aNumber
7468
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1451
    ].
19018
441811c95c15 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18863
diff changeset
  1452
    aNumber isNumber ifFalse:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1453
	^ aNumber raisedFromNumber:self.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1454
    ].
7468
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1455
    ^ self asFloat raisedTo:aNumber
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1456
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1457
    "
19092
4a5b5b1e6f36 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19049
diff changeset
  1458
     2 raisedTo: 4
4a5b5b1e6f36 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19049
diff changeset
  1459
     -2 raisedTo: 4
4a5b5b1e6f36 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19049
diff changeset
  1460
     4 raisedTo: 1/2
4a5b5b1e6f36 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19049
diff changeset
  1461
     -4 raisedTo: 1/2
4a5b5b1e6f36 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19049
diff changeset
  1462
     8 raisedTo: 1/3
4a5b5b1e6f36 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19049
diff changeset
  1463
     -8 raisedTo: 1/3
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1464
     10 raisedTo: 4
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1465
     10 raisedTo: -4
7468
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1466
    "
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1467
!
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1468
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1469
real
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1470
    "Return the real part of this Number."
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1471
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1472
    ^ self
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1473
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1474
    "Modified: / 9.7.1998 / 10:17:17 / cg"
6258
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1475
!
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1476
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1477
sqrt
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1478
    "return the square root of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1479
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  1480
    "/ if I am not a Float (or a less general lpReal),
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  1481
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1482
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1483
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1484
	^ self asFloat sqrt.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1485
    ].
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  1486
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  1487
    ^ self sqrt_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1488
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1489
10191
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1490
sqrtWithErrorLessThan:epsilon
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1491
    "compute the square root, using the Newton method.
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1492
     The approximated return value has an error less than the given epsilon."
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1493
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1494
    |y yN|
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1495
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1496
    yN := self / 2.
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1497
    [
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1498
       y := yN.
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1499
       yN := ( y + (self / y) ) / 2.
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1500
    ] doUntil:[ (yN - y) abs < epsilon ].
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1501
    ^ yN.
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1502
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1503
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1504
     (2 asFixedPoint:4) sqrtWithErrorLessThan:0.001
10191
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1505
    "
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1506
!
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1507
6258
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1508
timesTwoPower:anInteger
12762
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  1509
    "Return the receiver multiplied by 2 raised to the power of the argument.
6258
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1510
     For protocol completeness wrt. Squeak and ST80."
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1511
12762
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  1512
    anInteger >= 0 ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1513
	^ self * (1 bitShift:anInteger)
12762
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  1514
    ].
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  1515
    ^ self / (1 bitShift:anInteger negated)
6258
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1516
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1517
    "
12762
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  1518
     123 timesTwoPower:0   -> 123
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  1519
     123 timesTwoPower:1   -> 246
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  1520
     123 timesTwoPower:2   -> 492
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  1521
     123 timesTwoPower:3   -> 984
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  1522
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  1523
     (2 timesTwoPower: -150) timesTwoPower: 150  -> 2
6258
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1524
    "
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1525
! !
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1526
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1527
!Number methodsFor:'measurement values'!
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1528
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1529
maxValue
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1530
    "the maximum possible value taking me as a measurement with possible error;
20421
5c1194f503ab #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20331
diff changeset
  1531
     as I am exact, that's myself"
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1532
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1533
    ^ self
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1534
!
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1535
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1536
minValue
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1537
    "the minimum possible value taking me as a measurement with possible error;
20421
5c1194f503ab #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20331
diff changeset
  1538
     as I am exact, that's myself"
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1539
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1540
    ^ self
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1541
! !
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1542
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1543
!Number methodsFor:'printing & storing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1544
18863
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1545
displayOn:aGCOrStream
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1546
    "return a string to display the receiver.
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1547
     The output radix is usually 10, but can be changed by setting
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1548
     DefaultDisplayRadix (see Integer>>displayRadix:)"
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1549
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1550
    "/ what a kludge - Dolphin and Squeak mean: printOn: a stream;
21536
c71b535bfcbb #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21142
diff changeset
  1551
    "/ old ST80 means: draw-yourself on a GC.
18863
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1552
    (aGCOrStream isStream) ifFalse:[
21536
c71b535bfcbb #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21142
diff changeset
  1553
        ^ super displayOn:aGCOrStream
18863
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1554
    ].
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1555
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1556
    (DefaultDisplayRadix isNil or:[DefaultDisplayRadix == 10]) ifTrue:[
21536
c71b535bfcbb #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21142
diff changeset
  1557
        self printOn:aGCOrStream
18863
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1558
    ] ifFalse:[
21536
c71b535bfcbb #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21142
diff changeset
  1559
        self printOn:aGCOrStream base:DefaultDisplayRadix showRadix:true.
18863
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1560
    ].
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1561
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1562
    "
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1563
     Integer displayRadix:16. 12345
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1564
     Integer displayRadix:2.  12345
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1565
     Integer displayRadix:10. 12345
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1566
    "
21536
c71b535bfcbb #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21142
diff changeset
  1567
c71b535bfcbb #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21142
diff changeset
  1568
    "Modified (comment): / 22-02-2017 / 16:52:16 / cg"
18863
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1569
!
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1570
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1571
printOn:aStream
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1572
    "append a printed description of the receiver to aStream"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1573
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1574
    self printOn:aStream base:10
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1575
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1576
    "Modified: / 20.1.1998 / 14:10:45 / stefan"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1577
!
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1578
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1579
printOn:aStream base:b
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1580
    "return a string representation of the receiver in the specified
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1581
     radix (without the initial XXr)"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1582
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1583
    ^ self printOn:aStream base:b showRadix:false
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1584
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1585
    "
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1586
     10 printOn:Transcript base:3
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1587
     31 printOn:Transcript base:3
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1588
     -20 printOn:Transcript base:16
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1589
     -20 printOn:Transcript base:10
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1590
     3000 factorial printOn:Transcript base:10
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1591
    "
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1592
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1593
    "Modified: / 20.1.1998 / 18:05:02 / stefan"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1594
    "Modified: / 7.9.2001 / 13:52:17 / cg"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1595
!
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1596
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1597
printOn:aStream base:b showRadix:showRadix
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1598
    "the central print method for integer.
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1599
     Must be defined in concrete classes"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1600
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1601
    self subclassResponsibility
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1602
!
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1603
5299
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  1604
printOn:aStream paddedWith:padCharacter to:size base:radix
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  1605
    |s|
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  1606
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1607
    radix == 10 ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1608
	s := self printString.
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1609
    ] ifFalse:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1610
	s := self printStringRadix:radix.
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1611
    ].
5299
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  1612
    s printOn: aStream leftPaddedTo:size with: padCharacter
11098
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1613
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1614
    "
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1615
     100 printOn:Transcript paddedWith:$0 to:10 base:10.     Transcript cr.
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1616
     100 printOn:Transcript paddedWith:$0 to:10 base:16.     Transcript cr.
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1617
     100 printOn:Transcript paddedWith:(Character space) to:10 base:16.     Transcript cr.
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1618
     100 printOn:Transcript paddedWith:(Character space) to:10 base:2.     Transcript cr.
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1619
    "
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1620
!
5299
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  1621
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1622
printOn:aStream thousandsSeparator:thousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1623
    "print the receiver as business number with thousands separator to aStream.
11136
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1624
     thousandsSeparator is locale specific and is usualy a single quote ('), a comma or period."
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1625
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1626
    |rest|
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1627
11594
5440d97af571 #printStringWithThousandsSeparator fix for non-integers
Stefan Vogel <sv@exept.de>
parents: 11526
diff changeset
  1628
    self >= 1000 ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1629
	(self // 1000) printOn:aStream thousandsSeparator:thousandsSeparator.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1630
	thousandsSeparator printOn:aStream.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1631
	rest := self \\ 1000.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1632
	rest < 100 ifTrue:[
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1633
	    aStream nextPut:$0.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1634
	    rest < 10 ifTrue:[
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1635
		aStream nextPut:$0.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1636
	    ].
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1637
	].
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1638
	rest printOn:aStream.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1639
	^ self.
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1640
    ].
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1641
    self printOn:aStream.
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1642
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1643
    "
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1644
     swiss style:
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1645
     1000000 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1646
     12345678 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1647
     1234567 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1648
     123456 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
11136
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1649
     123056 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1650
     12345 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1651
     1234 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1652
     123 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1653
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1654
     (12345678.12 asFixedPoint:2) printOn:Transcript thousandsSeparator:$'.     Transcript cr.
11136
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1655
     1234567.12 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1656
     123456.12 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1657
     123056.12 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1658
     12345.12 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1659
     1234.12 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1660
     123.12 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1661
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1662
     us style:
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1663
     1000000 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1664
     12345678 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1665
     1234567 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1666
     123456 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1667
     12345 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1668
     1234 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1669
     123 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1670
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1671
     german (european ?) style
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1672
     1000000 printOn:Transcript thousandsSeparator:$..     Transcript cr.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1673
     12345678 printOn:Transcript thousandsSeparator:$..     Transcript cr.
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1674
     1234567 printOn:Transcript thousandsSeparator:$..     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1675
     123456 printOn:Transcript thousandsSeparator:$..     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1676
     12345 printOn:Transcript thousandsSeparator:$..     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1677
     1234 printOn:Transcript thousandsSeparator:$..     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1678
     123 printOn:Transcript thousandsSeparator:$..     Transcript cr.
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1679
    "
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1680
!
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1681
11660
62a726d91255 new: #printStringFormat:
Stefan Vogel <sv@exept.de>
parents: 11594
diff changeset
  1682
printStringFormat:formatString
62a726d91255 new: #printStringFormat:
Stefan Vogel <sv@exept.de>
parents: 11594
diff changeset
  1683
    ^ self printfPrintString:formatString
62a726d91255 new: #printStringFormat:
Stefan Vogel <sv@exept.de>
parents: 11594
diff changeset
  1684
!
62a726d91255 new: #printStringFormat:
Stefan Vogel <sv@exept.de>
parents: 11594
diff changeset
  1685
20142
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  1686
printStringRadix:base
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  1687
    "return a string representation of the receiver in the specified
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  1688
     base; does NOT prepend XXr to the string.
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  1689
     See also: radixPrintStringRadix:
20331
f9e364521eda #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20308
diff changeset
  1690
               printOn:base:showRadix:"
20142
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  1691
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  1692
    ^ self printStringRadix:base showRadix:false
11098
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1693
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1694
    "
20331
f9e364521eda #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20308
diff changeset
  1695
     10000000000000000000000000000000000000000000 printStringRadix:16    
f9e364521eda #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20308
diff changeset
  1696
     -10000000000000000000000000000000000000000000 printStringRadix:16   
11098
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1697
    "
5299
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  1698
!
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  1699
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1700
printStringRadix:base showRadix:showRadixBoolean
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1701
    "return a string representation of the receiver in the specified
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1702
     base; does NOT prepend XXr to the string.
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1703
     See also: radixPrintStringRadix:
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1704
	       printOn:base:showRadix:"
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1705
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1706
    |s|
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1707
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1708
    s := WriteStream on:(String basicNew:20).
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1709
    self printOn:s base:base showRadix:showRadixBoolean.
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1710
    ^ s contents
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1711
20142
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  1712
    "
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  1713
     10000000000000000000000000000000000000000000 printStringRadix:16 showRadix:false
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  1714
     10000000000000000000000000000000000000000000 printStringRadix:16 showRadix:true
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  1715
    "
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  1716
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  1717
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1718
    "Created: / 23-09-2011 / 13:59:19 / cg"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1719
!
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1720
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1721
printStringWithThousandsSeparator
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1722
    "print the receiver as swiss business number with thousands separator to aStream.
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1723
     Caveat: Should use the separator from the locale here"
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1724
20866
076ab5e1f702 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20421
diff changeset
  1725
    ^ self printStringWithThousandsSeparator:(UserPreferences current thousandsSeparatorCharacter).
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1726
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1727
    "
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1728
     1000000 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1729
     12345678 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1730
     1234567 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1731
     123456 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1732
     12345 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1733
     1234 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1734
     123 printStringWithThousandsSeparator
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1735
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1736
     1000000 asFixedPoint printStringWithThousandsSeparator
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1737
     12345678 asFixedPoint printStringWithThousandsSeparator
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1738
     1234567 asFixedPoint printStringWithThousandsSeparator
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1739
     123456 asFixedPoint printStringWithThousandsSeparator
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1740
     12345 asFixedPoint printStringWithThousandsSeparator
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1741
     1234 asFixedPoint printStringWithThousandsSeparator
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1742
     123 asFixedPoint printStringWithThousandsSeparator
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1743
     ((9999999//10000) asFixedPoint:9) printStringWithThousandsSeparator
20866
076ab5e1f702 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20421
diff changeset
  1744
     ((99999999//10000) asFixedPoint:9) printStringWithThousandsSeparator
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1745
    "
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1746
!
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1747
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1748
printStringWithThousandsSeparator:thousandsSeparator
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1749
    "print the receiver as business number with a thousands separator to aStream.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1750
     Notice:
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1751
	americans use comma
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1752
	germans (europeans ?) use a dot
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1753
	swiss people (business people ?) use a single quote
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1754
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1755
     Caveat: Should use the separator from the locale here"
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1756
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1757
    ^ String streamContents:[:s | self printOn:s thousandsSeparator:thousandsSeparator].
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1758
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1759
    "
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1760
     Transcript showCR:(1000000 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1761
     Transcript showCR:(12345678 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1762
     Transcript showCR:(1234567 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1763
     Transcript showCR:(123456 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1764
     Transcript showCR:(12345 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1765
     Transcript showCR:(1234 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1766
     Transcript showCR:(123 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1767
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1768
     Transcript showCR:(1000000 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1769
     Transcript showCR:(12345678 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1770
     Transcript showCR:(1234567 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1771
     Transcript showCR:(123456 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1772
     Transcript showCR:(12345 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1773
     Transcript showCR:(1234 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1774
     Transcript showCR:(123 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1775
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1776
     Transcript showCR:((1000000 asFixedPoint:2) printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1777
     Transcript showCR:((12345678 asFixedPoint:2) printStringWithThousandsSeparator:$,).
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1778
     Transcript showCR:((1234567 asFixedPoint:2) printStringWithThousandsSeparator:$,).
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1779
     Transcript showCR:((123456 asFixedPoint:2) printStringWithThousandsSeparator:$,).
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1780
     Transcript showCR:((12345 asFixedPoint:2) printStringWithThousandsSeparator:$,).
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1781
     Transcript showCR:((1234 asFixedPoint:2) printStringWithThousandsSeparator:$,).
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1782
     Transcript showCR:((123 asFixedPoint:2) printStringWithThousandsSeparator:$,).
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1783
    "
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1784
!
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1785
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1786
radixPrintStringRadix:radix
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1787
    "return a string representation of the receiver in the specified
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1788
     base; prepend XXr to the string"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1789
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1790
    ^ self printStringRadix:radix showRadix:true
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1791
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1792
    "
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1793
     31 radixPrintStringRadix:2
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1794
     31 radixPrintStringRadix:3
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1795
     31 radixPrintStringRadix:10
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1796
     31 radixPrintStringRadix:16
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1797
     31 radixPrintStringRadix:36
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1798
    "
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1799
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1800
    "Created: / 19-01-1998 / 17:38:00 / stefan"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1801
    "Modified: / 20-01-1998 / 14:11:03 / stefan"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1802
    "Modified: / 23-09-2011 / 14:00:02 / cg"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1803
!
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  1804
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1805
storeOn:aStream
11460
146fb82b5523 comment
Claus Gittinger <cg@exept.de>
parents: 11458
diff changeset
  1806
    "append a string for storing the receiver onto the argument, aStream
146fb82b5523 comment
Claus Gittinger <cg@exept.de>
parents: 11458
diff changeset
  1807
     - since numbers are literals,they store as they print."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1808
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1809
    ^ self printOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1810
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1811
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1812
storeString
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1813
    "return a string for storing
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1814
     - since numbers are literals, they store as they print."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1815
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1816
    ^ self printString
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1817
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1818
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1819
!Number methodsFor:'taylor series'!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1820
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1821
arcSin_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1822
    "compute the arcSine of the receiver using a taylor series approx."
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1823
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1824
    "/ uses taylor series:
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1825
    "/                 1*x^3   1*3 * x^5
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1826
    "/    arcSin = x + ----- + ---------- + ...
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1827
    "/                 2* 3    2*4 *  5
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1828
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1829
    |x2 num numf den denf approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1830
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1831
    ((self < -1) or:[self > 1]) ifTrue:[
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1832
	^ self class
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1833
	    raise:#domainErrorSignal
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1834
	    receiver:self
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1835
	    selector:#arcSin
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1836
	    arguments:#()
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1837
	    errorString:'bad receiver in arcSin'
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1838
    ].
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1839
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1840
    x2 := self * self.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1841
    num := x2 * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1842
    approx := self + (num / 6).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1843
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1844
    numf := 3.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1845
    denf := 4.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1846
    den := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1847
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1848
    [
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1849
	num := (num * x2) * numf.   numf := numf + 2.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1850
	den := den * denf.          denf := denf + 2.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1851
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1852
	delta := num / (den * numf).
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1853
	approx := approx + delta.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1854
    ] doUntil:[delta abs <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1855
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1856
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1857
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1858
     0.5 arcSin                                    0.523599
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1859
     0.5q arcSin                        0.523598776
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1860
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1861
     0.5q arcSin_withAccuracy:1         0.520833333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1862
     0.5q arcSin_withAccuracy:0.1       0.520833333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1863
     0.5q arcSin_withAccuracy:0.01      0.523177083
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1864
     0.5q arcSin_withAccuracy:0.001     0.523525856
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1865
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1866
     0.5q arcSin_withAccuracy:1e-20     0.523598776
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1867
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1868
     0.5 asLargeFloat arcSin_withAccuracy:1e-30    -- not yet
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1869
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1870
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1871
     0.1 arcSin                                    0.100167
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1872
     0.1q arcSin                        0.100167421
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1873
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1874
     0.1q arcSin_withAccuracy:1         0.100166667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1875
     0.1q arcSin_withAccuracy:0.1       0.100166667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1876
     0.1q arcSin_withAccuracy:0.01      0.100166667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1877
     0.1q arcSin_withAccuracy:0.001     0.100166667
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1878
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1879
     0.1q arcSin_withAccuracy:1e-20     0.100167421
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1880
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1881
     0.1 asLargeFloat arcSin_withAccuracy:1e-30    -- not yet
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1882
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1883
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1884
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1885
arcTan_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1886
    "compute the arcTangent of the receiver using a taylor series approx."
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1887
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1888
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1889
    "/                 x^3   x^5   x^7
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1890
    "/ arcTan(x) = x - --- + --- - --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1891
    "/                  3     5    7
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1892
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1893
    |x2 num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1894
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1895
    x2 := self * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1896
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1897
    num := (x2 * self) negated.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1898
    den := 3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1899
    approx := self + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1900
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1901
    [
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1902
	den := den + 2.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1903
	num := (num * x2) negated.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1904
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1905
	delta := num / den.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1906
	approx := approx + delta.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1907
    ] doUntil:[delta abs <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1908
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1909
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1910
    "
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1911
     1.0 arcTan                       0.785398
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1912
     1q arcTan                        0.785398163
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1913
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1914
     1q arcTan_withAccuracy:1         0.666666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1915
     1q arcTan_withAccuracy:0.1       0.744011544
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1916
     1q arcTan_withAccuracy:0.01      0.790299653
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1917
     1q arcTan_withAccuracy:0.001     0.785897165
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1918
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1919
     1q arcTan_withAccuracy:1e-8      0.785398168
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1920
     1q arcTan_withAccuracy:1e-20     -- not yet, converges very slow
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1921
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1922
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1923
     0.5 arcTan                         0.463648
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1924
     0.5q arcTan                        0.463647609
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1925
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1926
     0.5q arcTan_withAccuracy:1         0.458333333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1927
     0.5q arcTan_withAccuracy:0.1       0.458333333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1928
     0.5q arcTan_withAccuracy:0.01      0.464583333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1929
     0.5q arcTan_withAccuracy:0.001     0.463684276
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1930
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1931
     0.5q arcTan_withAccuracy:1e-20     0.463647609
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1932
     0.5 asLargeFloat arcTan_withAccuracy:1e-30    -- not yet
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1933
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1934
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1935
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1936
cbrt_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1937
    "compute cubic root of the receiver using a newton approx."
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1938
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1939
    "
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1940
      Use Newton's method:
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1941
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1942
		 2*x_n + (a / x_n^2)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1943
	x_n+1 =  ---------------
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1944
		      3
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1945
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1946
	cbrt(a) = x_n
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1947
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1948
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1949
    |approx|
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1950
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1951
    self = 0 ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1952
	^ self
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1953
    ].
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1954
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1955
    approx := 1.
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1956
    [
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1957
	|lastApprox|
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1958
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1959
	lastApprox := approx.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1960
	approx := ((approx * 2) + (self / approx / approx)) / 3.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1961
	(approx - lastApprox) abs > epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1962
    ] whileTrue.
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1963
    ^ approx
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1964
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1965
    "
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1966
     8q cbrt                                 2.0
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1967
     8q cbrt_withAccuracy:0.01               2.000004911675504018
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1968
     8q cbrt_withAccuracy:0.0001             2.000000000012062239
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1969
     8q cbrt_withAccuracy:0.0000001          2.0
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1970
     8q cbrt_withAccuracy:0.0000000001       2.0
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1971
     8q cbrt_withAccuracy:0.000000000001     2.0
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1972
     8q cbrt_withAccuracy:LongFloat epsilon  2.0
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1973
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1974
     27q cbrt_withAccuracy:0.01              3.000000541064176501
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1975
     27q cbrt_withAccuracy:LongFloat epsilon  3.0
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1976
     -27q cbrt_withAccuracy:LongFloat epsilon -3.0
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1977
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1978
     MessageTally spyOn:[ |arg|
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1979
	arg := 2 asLongFloat.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1980
	1000000 timesRepeat:[
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1981
	     arg cbrt_withAccuracy:0.000000000001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1982
	]
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1983
     ]
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1984
     Time millisecondsToRun:[ |arg|
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1985
	arg := 2 asLongFloat.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1986
	1000000 timesRepeat:[
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1987
	     arg cbrt_withAccuracy:0.000000000001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1988
	]
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1989
     ]
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1990
    "
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1991
!
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1992
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1993
cos_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  1994
    "compute the cosine of the receiver using a taylor series approx."
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1995
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1996
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1997
    "/               x^2   x^4   x^6
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1998
    "/  cos(x) = 1 - --- + --- - --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1999
    "/                2!!    4!!    6!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2000
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2001
    |x2 facN num den approx lastApprox|
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2002
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2003
    x2 := self * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2004
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2005
    num := x2 negated.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2006
    den := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2007
    facN := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2008
    approx := 1 + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2009
    lastApprox := 1.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2010
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2011
    [ (lastApprox - approx) abs > epsilon ] whileTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2012
	facN := facN + 2.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2013
	den := den * (facN - 1) * facN.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2014
	num := (num * x2) negated.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2015
	lastApprox := approx.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2016
	approx := approx + (num / den).
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2017
    ].
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2018
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2019
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2020
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2021
     1.0 cos                                    0.540302
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2022
     1.0 asLongFloat cos_withAccuracy:1         0.5
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2023
     1.0 asLongFloat cos_withAccuracy:0.1       0.541666667
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2024
     1.0 asLongFloat cos_withAccuracy:0.01      0.540277778
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2025
     1.0 asLongFloat cos_withAccuracy:0.001     0.540302579
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2026
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2027
     1.0 asLongFloat cos_withAccuracy:1e-40     0.540302306
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2028
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2029
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2030
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2031
cosh_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2032
    "compute the hyperbolic cosine of the receiver using a taylor series approx."
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2033
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2034
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2035
    "/               x^2   x^4   x^6
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2036
    "/    cosh = x + --- + --- + --- ...
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2037
    "/                2!!    4!!    6!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2038
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2039
    |x2 facN num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2040
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2041
    x2 := self * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2042
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2043
    num := x2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2044
    den := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2045
    facN := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2046
    approx := self + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2047
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2048
    [
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2049
	facN := facN + 2.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2050
	den := den * (facN - 1) * facN.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2051
	num := num * x2.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2052
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2053
	delta := num / den.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2054
	approx := approx + delta.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2055
    ] doUntil:[delta <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2056
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2057
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2058
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2059
     1.0 cosh                                    1.54308
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2060
     1.0q cosh_withAccuracy:1         1.5
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2061
     1.0q cosh_withAccuracy:0.1       1.54308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2062
     1.0q cosh_withAccuracy:0.01      1.54308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2063
     1.0q cosh_withAccuracy:0.001     1.54308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2064
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2065
     1.0q cosh_withAccuracy:1e-40   -> 1.543080
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2066
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2067
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2068
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2069
epsilon
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2070
    "return the maximum relative spacing of instances of mySelf
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2071
     (i.e. the value-delta of the least significant bit)"
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2072
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2073
    ^ self class epsilon
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2074
!
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2075
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2076
exp_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2077
    "compute e**x of the receiver using a taylor series approx."
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2078
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2079
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2080
    "/             x    x^2   x^3
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2081
    "/  e^x = 1 + --- + --- + --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2082
    "/             1!!    2!!    3!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2083
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2084
    |x2 facN num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2085
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2086
    x2 := self * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2087
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2088
    num := x2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2089
    den := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2090
    facN := 2.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2091
    approx := self + 1 + (num / den).
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2092
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2093
    [
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2094
	facN := facN + 1.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2095
	den := den * facN.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2096
	num := num * self.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2097
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2098
	delta := num / den.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2099
	approx := approx + delta.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2100
    ] doUntil:[delta abs <= epsilon].
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2101
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2102
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2103
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2104
    "
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2105
     -1 exp
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2106
     1.0 exp                                    2.71828
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2107
     1q exp                                     2.71828183
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2108
     2q exp                                     7.3890561
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2109
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2110
     1q exp_withAccuracy:1                      2.66666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2111
     1q exp_withAccuracy:0.1                    2.70833333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2112
     1q exp_withAccuracy:0.01                   2.71666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2113
     1q exp_withAccuracy:0.001                  2.71825397
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2114
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2115
     2q exp_withAccuracy:LongFloat epsilon      7.3890561
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2116
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2117
     1.0 asLongFloat exp_withAccuracy:1e-40     2.71828183
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2118
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2119
     5 exp_withAccuracy:1e-40
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2120
     (1 exp_withAccuracy:1e-100) asFixedPoint:100
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2121
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2122
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2123
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2124
ln_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2125
    "compute ln of the receiver using a taylor series approx."
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2126
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2127
    "uses taylor series:
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2128
		 u^2   u^3
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2129
	ln = u - --- + --- ...
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2130
		  2    3
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2131
      where:
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2132
	     u = x - 1    and: x < 1
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2133
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2134
     Now we use modified taylor, which converges faster:
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2135
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2136
		   1+y        1   1       1
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2137
	ln(x) = ln --- = 2y ( - + - y^2 + - y^4 + ....)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2138
		   1-y        1   3       5
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2139
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2140
	where y = (x-1) / (x+1)  and x > 0
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2141
    "
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2142
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2143
    |denominator approx y y2 exp delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2144
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2145
    self <= 0 ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2146
	^ self class
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2147
	    raise:#domainErrorSignal
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2148
	    receiver:self
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2149
	    selector:#ln
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2150
	    arguments:#()
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2151
	    errorString:'bad receiver in ln'
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2152
    ].
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2153
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2154
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2155
    y := (self - 1)/(self + 1).
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2156
    exp := y2 := y * y.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2157
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2158
    approx := 1.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2159
    denominator := 3.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2160
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2161
    [
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2162
	delta := exp / denominator.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2163
	approx := approx + delta.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2164
	exp := exp * y2.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2165
	denominator := denominator + 2.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2166
    ] doUntil:[delta <= epsilon].
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2167
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2168
    ^ y * 2 * approx.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2169
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2170
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2171
    "
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2172
     2.0 ln                         0.693147
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2173
     2.0q ln                        0.693147181
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2174
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2175
     2.0q ln_withAccuracy:1         0.691358025
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2176
     2.0q ln_withAccuracy:0.1       0.691358025
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2177
     2.0q ln_withAccuracy:0.01      0.693004115
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2178
     2.0q ln_withAccuracy:0.0000001 0.69314718
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2179
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2180
     2.0q ln_withAccuracy:1e-10
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2181
     2.0q ln_withAccuracy:1e-20
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2182
     2.0q ln_withAccuracy:1e-40     0.693147181
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2183
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2184
     2 ln_withAccuracy:1e-40
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2185
     0 ln_withAccuracy:1e-40
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2186
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2187
     (2 ln_withAccuracy:1e-100) asFixedPoint:100
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2188
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2189
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2190
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2191
sin_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2192
    "compute the sine of the receiver using a taylor series approx."
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2193
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2194
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2195
    "/               x^3   x^5   x^7
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2196
    "/  sin(x) = x - --- + --- - --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2197
    "/                3!!    5!!    7!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2198
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2199
    |x2 facN num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2200
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2201
    x2 := self * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2202
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2203
    num := (x2 * self) negated.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2204
    den := 2*3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2205
    facN := 3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2206
    approx := self + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2207
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2208
    [
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2209
	facN := facN + 2.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2210
	den := den * (facN - 1) * facN.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2211
	num := (num * x2) negated.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2212
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2213
	delta := num / den.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2214
	approx := approx + delta.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2215
    ] doUntil:[delta abs <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2216
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2217
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2218
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2219
     1.0 sin                                    0.841471
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2220
     1.0q sin                        0.841470985
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2221
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2222
     1.0q sin_withAccuracy:1         0.833333333
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2223
     1.0q sin_withAccuracy:0.1       0.841666667
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2224
     1.0q sin_withAccuracy:0.01      0.841666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2225
     1.0q sin_withAccuracy:0.001     0.841468254
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2226
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2227
     1.0q sin_withAccuracy:1e-40     0.841470985
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2228
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2229
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2230
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2231
sinh_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2232
    "compute the hyperbolic sine of the receiver using a taylor series approx."
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2233
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2234
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2235
    "/               x^3   x^5   x^7
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2236
    "/ sinh(x) = x + --- + --- + --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2237
    "/                3!!    5!!    7!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2238
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2239
    |x2 facN num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2240
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2241
    x2 := self * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2242
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2243
    num := x2 * self.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2244
    den := 2*3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2245
    facN := 3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2246
    approx := self + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2247
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2248
    [
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2249
	facN := facN + 2.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2250
	den := den * (facN - 1) * facN.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2251
	num := num * x2.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2252
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2253
	delta := num / den.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2254
	approx := approx + delta.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2255
    ] doUntil:[delta abs <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2256
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2257
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2258
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2259
     1.0 sinh                                    1.1752
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2260
     1q sinh                        1.17520119
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2261
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2262
     1q sinh_withAccuracy:1         1.16666667
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2263
     1q sinh_withAccuracy:0.1       1.175
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2264
     1q sinh_withAccuracy:0.01      1.175
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2265
     1q sinh_withAccuracy:0.001     1.17519841
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2266
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2267
     1q sinh_withAccuracy:1e-40     1.17520119
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2268
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2269
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2270
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2271
sqrt_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2272
    "compute square root of the receiver using newtom/heron algorithm"
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2273
    "
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2274
      Use the Heron algorithm:
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2275
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2276
		 x_n + (a / x_n)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2277
	x_n+1 =  ---------------
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2278
		      2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2279
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2280
	sqrt(a) = x_n
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2281
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2282
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2283
    |approx|
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2284
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2285
    self <= 0 ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2286
	self = 0 ifTrue:[
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2287
	    ^ self
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2288
	].
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2289
	^ self class
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2290
	    raise:#imaginaryResultSignal
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2291
	    receiver:self
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2292
	    selector:#sqrt
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2293
	    arguments:#()
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2294
	    errorString:'bad (negative) receiver in sqrt'
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2295
    ].
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2296
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2297
    approx := 1.
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2298
    [
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2299
	|lastApprox|
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2300
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2301
	lastApprox := approx.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2302
	approx := ((self / approx) + approx) / 2.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2303
	(approx - lastApprox) abs > epsilon
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2304
    ] whileTrue.
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2305
    ^ approx
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2306
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2307
    "
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2308
     2 sqrt                                  1.4142135623731
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2309
     2q sqrt                                 1.414213562373095049
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2310
     2q sqrt_withAccuracy:0.01               1.414215686274509804
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2311
     2q sqrt_withAccuracy:0.0001             1.414213562374689911
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2312
     2q sqrt_withAccuracy:0.0000001          1.414213562373095049
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2313
     2q sqrt_withAccuracy:0.0000000001       1.414213562373095049
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2314
     2q sqrt_withAccuracy:0.000000000001     1.414213562373095049
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2315
     2q sqrt_withAccuracy:LongFloat epsilon  1.414213562373095049
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2316
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2317
     (4 sqrt_withAccuracy:Integer epsilon) asFloat
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2318
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2319
     MessageTally spyOn:[ |arg|
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2320
	arg := 2 asLongFloat.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2321
	1000000 timesRepeat:[
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2322
	     arg sqrt_withAccuracy:0.000000000001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2323
	]
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2324
     ]
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2325
     Time millisecondsToRun:[ |arg|
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2326
	arg := 2 asLongFloat.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2327
	1000000 timesRepeat:[
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2328
	     arg sqrt_withAccuracy:0.000000000001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2329
	]
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2330
     ]
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2331
    "
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2332
!
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  2333
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2334
tan_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2335
    "compute the tangens of the receiver using a taylor series approx."
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2336
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2337
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2338
    "/                x^3     x^5      x^7      x^9     2^2n * ( 2^2n - 1) * B2n * x^(2n-1)
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2339
    "/    tan = x + 1*--- + 2*--- + 17*--- + 62*----... ----------------------------------...
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2340
    "/                 3       15      315      2835                 (2n)!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2341
    "/ where Bi is the ith bernoulli number.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2342
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2343
    |factors idx x2 num t approx lastApprox delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2344
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2345
    "/    (1 to:20) collect:[:n| |num den|
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2346
    "/        num := (2 raisedTo:(2*n)) * ((2 raisedTo:(2*n))-1) * ((n*2) bernoulli).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2347
    "/        den := (2*n) factorial.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2348
    "/        num / den
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2349
    "/    ]
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2350
   factors := #(
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2351
	(1 3)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2352
	(2 15)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2353
	(17 315)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2354
	(62 2835)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2355
	(1382 155925)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2356
	(21844 6081075)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2357
	(929569 638512875)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2358
	(6404582 10854718875)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2359
	(443861162 1856156927625)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2360
	(18888466084 194896477400625)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2361
	(113927491862 2900518163668125)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2362
	(58870668456604 3698160658676859375)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2363
	(8374643517010684 1298054391195577640625)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2364
	(689005380505609448 263505041412702261046875)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2365
	(129848163681107301953 122529844256906551386796875)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2366
	(1736640792209901647222 4043484860477916195764296875)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2367
	(418781231495293038913922 2405873491984360136479756640625)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2368
	(56518638202982204522669764 801155872830791925447758961328125)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2369
	(32207686319158956594455462 1126482925555250126673224649609375)).
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2370
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2371
    x2 := self * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2372
8203
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  2373
    num := x2 * self.               "/ =  x^3
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  2374
    approx := self + (num / 3).     "/ do the first iteration
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2375
    lastApprox := self.
8203
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  2376
    idx := 2.
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  2377
    [
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2378
	t := factors at:idx ifAbsent:[].
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2379
	t isNil ifTrue:[
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2380
	    self error:'too many iterations'.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2381
"/ Not enough bernoulli numbers for now...
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2382
"/            |tempNum tempDen|
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2383
"/            tempNum := 2 raisedTo:(2*idx).
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2384
"/            tempNum := tempNum * (tempNum-1) * ((2*idx) bernoulli).
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2385
"/            tempDen := (2*idx) factorial.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2386
"/            t := Array with:tempNum with:tempDen.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2387
	].
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2388
	idx := idx + 1.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2389
	num := num * x2.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2390
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2391
	delta := num * t first / t second.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2392
	approx := approx + delta.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2393
    ] doUntil:[delta abs <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2394
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2395
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2396
    "
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2397
     0.5 tan                         0.546302
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2398
     0.5q tan                        0.54630249
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2399
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2400
     0.5q tan_withAccuracy:1         0.541666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2401
     0.5q tan_withAccuracy:0.1       0.541666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2402
     0.5q tan_withAccuracy:0.01      0.545833333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2403
     0.5q tan_withAccuracy:0.001     0.54625496
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2404
     0.5q tan_withAccuracy:1e-15     0.54630249
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2405
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2406
     0.5q tan_withAccuracy:1e-40     -- too many iterations
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2407
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2408
! !
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2409
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2410
!Number methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2411
17224
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  2412
even
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  2413
    "return true if the receiver is divisible by 2."
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  2414
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  2415
    self fractionPart = 0 ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2416
	^ (self / 2) fractionPart = 0
17224
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  2417
    ].
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  2418
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  2419
    "this will raise an error"
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  2420
    ^ super even
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  2421
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  2422
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2423
	2 even
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2424
	2.0 even
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2425
	3.0 even
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2426
	2.4 even
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2427
	(5/3) even
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2428
	2 asFraction even
17224
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  2429
    "
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  2430
!
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  2431
5360
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  2432
isDivisibleBy:aNumber
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  2433
    "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
  2434
     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
  2435
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  2436
    aNumber = 0 ifTrue: [^ false].
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  2437
    aNumber isInteger ifFalse: [^ false].
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  2438
    ^ (self \\ aNumber) = 0
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  2439
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  2440
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2441
     3 isDivisibleBy:2
5360
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  2442
     4 isDivisibleBy:2
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2443
     4.0 isDivisibleBy:2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2444
     4.5 isDivisibleBy:4.5
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2445
     4.5 isDivisibleBy:1.0
5360
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  2446
    "
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  2447
!
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  2448
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  2449
isNaN
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  2450
    "return true, if the receiver is an invalid float (NaN - not a number)."
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  2451
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  2452
    ^ false
6155
00eaf2fa55bc isReal comment
Claus Gittinger <cg@exept.de>
parents: 6154
diff changeset
  2453
00eaf2fa55bc isReal comment
Claus Gittinger <cg@exept.de>
parents: 6154
diff changeset
  2454
    "Created: / 5.11.2001 / 18:07:26 / cg"
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  2455
!
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  2456
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2457
isNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2458
    "return true, if the receiver is a kind of number"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2459
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2460
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2461
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2462
19136
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2463
isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2464
    "return true if I am a perfect square.
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2465
     That is a number for which the square root is an integer."
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2466
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2467
    self truncated = self ifFalse:[^ false].
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2468
    ^ self asInteger isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2469
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2470
    "
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2471
     0 isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2472
     0.0 isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2473
     3 isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2474
     3.0 isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2475
     4 isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2476
     4.0 isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2477
     9 isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2478
     9.0 isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2479
    "
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2480
!
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  2481
6087
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  2482
isReal
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  2483
    "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
  2484
     true is returned here - the method is redefined from Object."
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  2485
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  2486
    ^ true
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  2487
!
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  2488
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2489
isZero
1557
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  2490
    "return true, if the receiver is zero"
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  2491
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2492
    ^ self = 0
1557
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  2493
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  2494
    "Modified: 18.7.1996 / 12:40:49 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2495
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2496
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  2497
!Number methodsFor:'tracing'!
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  2498
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4659
diff changeset
  2499
traceInto:aRequestor level:level from:referrer
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  2500
    "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
  2501
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4659
diff changeset
  2502
    ^ aRequestor traceNumber:self level:level from:referrer
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  2503
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  2504
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  2505
! !
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  2506
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2507
!Number methodsFor:'trigonometric'!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2508
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2509
arcCos
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2510
    "return the arccosine of the receiver (in radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2511
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2512
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2513
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2514
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2515
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2516
	^ self asFloat arcCos.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2517
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2518
    "/ slow fallback
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2519
    ^ (self class pi / 2) - self arcSin
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2520
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2521
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2522
arcCosech
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2523
    "return the inverse hyperbolic cosecant of the receiver."
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2524
    "caveat: misnomer; should be called aCosech or arCosech"
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2525
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2526
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2527
    "/ retry after converting to float
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2528
    (self isLimitedPrecisionReal not
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2529
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2530
	^ self asFloat arcCosech.
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2531
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2532
    "/ slow fallback
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2533
    ^ ((1 + ((self*self)+1) sqrt) / self) ln
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2534
!
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2535
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2536
arcCosh
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2537
    "return the inverse hyperbolic cosine of the receiver."
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2538
    "caveat: misnomer; should be called aCosh or arCosh"
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2539
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2540
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2541
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2542
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2543
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2544
	^ self asFloat arcCosh.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2545
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2546
    "/ slow fallback
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2547
    ^ (self + (self*self-1) sqrt) ln.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2548
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2549
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2550
arcCoth
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2551
    "return the inverse hyperbolic cotangent of the receiver."
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2552
    "caveat: misnomer; should be called aCoth or arCoth"
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2553
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2554
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2555
    "/ retry after converting to float
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2556
    (self isLimitedPrecisionReal not
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2557
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2558
	^ self asFloat arcCoth.
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2559
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2560
    "/ slow fallback
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2561
    ^ ((self+1) / (self-1)) ln / 2
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2562
!
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2563
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2564
arcSech
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2565
    "return the inverse hyperbolic secant of the receiver."
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2566
    "caveat: misnomer; should be called aSech or arSech"
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2567
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2568
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2569
    "/ retry after converting to float
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2570
    (self isLimitedPrecisionReal not
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2571
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2572
	^ self asFloat arcSech.
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2573
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2574
    "/ slow fallback
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2575
    ^ ((1 + (1-(self*self)) sqrt) / self) ln
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2576
!
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2577
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2578
arcSin
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2579
    "return the arcsine of the receiver (in radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2580
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2581
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2582
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2583
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2584
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2585
	^ self asFloat arcSin.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2586
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2587
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2588
    ^ self arcSin_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2589
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2590
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2591
arcSinh
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2592
    "return the inverse hyperbolic sine of the receiver."
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2593
    "caveat: misnomer; should be called aSinh or arSinh"
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2594
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2595
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2596
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2597
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2598
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2599
	^ self asFloat arcSinh.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2600
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2601
    "/ slow fallback
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2602
    ^ ( self + (self*self+1) sqrt ) ln
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2603
"/    ^ self arcSinh_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2604
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2605
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2606
arcTan
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2607
    "return the arctangent of the receiver (as radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2608
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2609
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2610
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2611
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2612
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2613
	^ self asFloat arcTan.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2614
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2615
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2616
    ^ self arcTan_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2617
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2618
11488
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2619
arcTan2:x
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2620
    "return atan2(self,x) (as radians)"
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2621
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2622
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2623
    "/ retry after converting to float
11488
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2624
    (self isLimitedPrecisionReal not
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2625
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2626
	^ self asFloat arcTan2:x.
11488
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2627
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2628
    "/ very slow fallback
11488
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2629
    ^ self arcTan2_withAccuracy:self epsilon x:x
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2630
!
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2631
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2632
arcTanh
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2633
    "return the inverse hyperbolic tangent of the receiver."
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2634
    "caveat: misnomer; should be called aTanh or arTanh"
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2635
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2636
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2637
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2638
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2639
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2640
	^ self asFloat arcTanh.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2641
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2642
    "/ slow fallback
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2643
    ^ ((1 + self) / (1 - self)) ln / 2
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  2644
    "/ s^ ((1 + self) ln / 2) - ((1 - self) ln / 2)
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2645
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2646
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2647
cos
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2648
    "return the cosine of the receiver (interpreted as radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2649
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2650
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2651
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2652
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2653
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2654
	^ self asFloat cos.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2655
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2656
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2657
    ^ self cos_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2658
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2659
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2660
cosh
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2661
    "return the hyperbolic cosine of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2662
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2663
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2664
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2665
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2666
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2667
	^ self asFloat cosh.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2668
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2669
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2670
    ^ self cosh_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2671
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2672
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2673
cot
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2674
    "return the cotangent of the receiver"
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2675
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2676
    ^ 1 / self tan
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2677
!
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2678
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2679
sin
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2680
    "return the sine of the receiver (interpreted as radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2681
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2682
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2683
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2684
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2685
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2686
	^ self asFloat sin.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2687
    ].
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2688
    ^ self sin_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2689
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2690
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2691
sinh
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2692
    "return the hyperbolic sine of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2693
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2694
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2695
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2696
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2697
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2698
	^ self asFloat sinh.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2699
    ].
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2700
    ^ self sinh_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2701
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2702
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2703
tan
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2704
    "return the tangens of the receiver (interpreted as radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2705
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2706
    "/ slow fallback
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2707
    ^ self sin / self cos
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2708
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2709
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2710
tanh
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2711
    "return the hyperbolic tangens of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2712
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2713
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2714
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2715
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2716
    or:[self generality < 1.0 generality]) ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2717
	^ self asFloat tanh.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2718
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  2719
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2720
    ^ self tanh_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2721
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2722
"/ If a fast exp is available, the following might be better...
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2723
"/
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2724
"/    |exp nexp|
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2725
"/
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2726
"/    "/ tanh is:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2727
"/    "/      sinh(x)
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2728
"/    "/      -------
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2729
"/    "/      cosh(x)
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2730
"/    "/
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2731
"/    "/ which is:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2732
"/    "/      (exp(x) - exp(-x)) / 2
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2733
"/    "/      ----------------------
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2734
"/    "/      (exp(x) + exp(-x)) / 2
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2735
"/
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2736
"/    exp := self exp.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2737
"/    nexp := self negated exp.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2738
"/
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2739
"/    ^ (exp - nexp) / (exp + nexp)
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2740
! !
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2741
5552
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5360
diff changeset
  2742
!Number methodsFor:'truncation & rounding'!
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2743
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2744
detentBy: detent atMultiplesOf: grid snap: snap
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2745
    "Map all values that are within detent/2 of any multiple of grid
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2746
     to that multiple.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2747
     Otherwise, if snap is true, return self, meaning that the values
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2748
     in the dead zone will never be returned.
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2749
     If snap is false, then expand the range between dead zones
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2750
     so that it covers the range between multiples of the grid,
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2751
     and scale the value by that factor."
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2752
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2753
    | r1 r2 |
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2754
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2755
    r1 := self roundTo: grid.                    "Nearest multiple of grid"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2756
    (self roundTo: detent) = r1 ifTrue: [^ r1].  "Snap to that multiple..."
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2757
    snap ifTrue: [^ self].                       "...or return self"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2758
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2759
    r2 := self < r1                               "Nearest end of dead zone"
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2760
	    ifTrue: [r1 - (detent asFloat/2)]
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2761
	    ifFalse: [r1 + (detent asFloat/2)].
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2762
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2763
    "Scale values between dead zones to fill range between multiples"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2764
    ^ r1 + ((self - r2) * grid asFloat / (grid - detent))
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2765
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2766
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2767
     (170 to: 190 by: 2) collect: [:a | a detentBy: 10 atMultiplesOf: 90 snap: true]
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2768
     (170 to: 190 by: 2) collect: [:a | a detentBy: 10 atMultiplesOf: 90 snap: false]
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2769
     (3.9 to: 4.1 by: 0.02) collect: [:a | a detentBy: 0.1 atMultiplesOf: 1.0 snap: true]
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2770
     (-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
  2771
    "
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2772
!
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2773
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2774
fractionPart
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2775
    "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
  2776
     i.e. the receiver minus its truncated value,
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  2777
     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
  2778
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  2779
    ^ self - self truncated
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2780
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2781
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2782
     1234.56789 fractionPart
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2783
     1.2345e6 fractionPart
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2784
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2785
     1.6 asLongFloat fractionPart + 1.6 asLongFloat truncated
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2786
     -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
  2787
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2788
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2789
    "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
  2790
    "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
  2791
!
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2792
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2793
integerPart
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2794
    "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
  2795
     (i.e. the truncated value)"
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2796
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2797
    ^ self truncated asFloat
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2798
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2799
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2800
     1234.56789 integerPart
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2801
     1.2345e6 integerPart
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2802
     12.5 integerPart
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2803
     -12.5 integerPart
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2804
     (5/3) integerPart
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2805
     (-5/3) integerPart
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2806
     (5/3) truncated
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2807
     (-5/3) truncated
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2808
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2809
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2810
    "Created: / 28.10.1998 / 17:14:56 / cg"
6154
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  2811
    "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
  2812
! !
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2813
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
  2814
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  2815
!Number class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2816
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2817
version
18850
172da07a4529 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18320
diff changeset
  2818
    ^ '$Header$'
12112
949f9713c4a5 changed: #readFrom:decimalPointCharacters:onError:
Claus Gittinger <cg@exept.de>
parents: 11944
diff changeset
  2819
!
949f9713c4a5 changed: #readFrom:decimalPointCharacters:onError:
Claus Gittinger <cg@exept.de>
parents: 11944
diff changeset
  2820
949f9713c4a5 changed: #readFrom:decimalPointCharacters:onError:
Claus Gittinger <cg@exept.de>
parents: 11944
diff changeset
  2821
version_CVS
18850
172da07a4529 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18320
diff changeset
  2822
    ^ '$Header$'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2823
! !
15078
997a122ceeb5 class: Number
Stefan Vogel <sv@exept.de>
parents: 14495
diff changeset
  2824