Number.st
author Claus Gittinger <cg@exept.de>
Sun, 15 Dec 2019 01:40:31 +0100
changeset 25122 a7acd17d012a
parent 25086 64b5d6493613
child 25144 03ca574d45c2
permissions -rw-r--r--
#DOCUMENTATION by exept class: Number comment/format in: #printfPrintString:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
     1
"{ Encoding: utf8 }"
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     4
 COPYRIGHT (c) 1988 by Claus Gittinger
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
     5
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
5360
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
    14
"{ Package: 'stx:libbasic' }"
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
    15
17469
17e4b64a023b class: Number
Claus Gittinger <cg@exept.de>
parents: 17224
diff changeset
    16
"{ NameSpace: Smalltalk }"
17e4b64a023b class: Number
Claus Gittinger <cg@exept.de>
parents: 17224
diff changeset
    17
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
ArithmeticValue subclass:#Number
18850
172da07a4529 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18320
diff changeset
    19
	instanceVariableNames:''
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
    20
	classVariableNames:'DecimalPointCharacterForPrinting DecimalPointCharactersForReading
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
    21
		DefaultDisplayRadix'
18850
172da07a4529 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18320
diff changeset
    22
	poolDictionaries:''
172da07a4529 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18320
diff changeset
    23
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    25
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    26
!Number class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    27
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    28
copyright
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    29
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    30
 COPYRIGHT (c) 1988 by Claus Gittinger
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    31
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    32
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    33
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    34
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    35
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    36
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    37
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    38
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    40
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    41
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    42
documentation
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    43
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    44
    abstract superclass for all kinds of numbers
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    45
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
    46
    [class variables:]
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    47
	DecimalPointCharacterForPrinting          <Character>                     used when printing
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    48
	DecimalPointCharactersForReading          <Collection of Character>       accepted as decimalPointChars when reading
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    49
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    50
	DefaultDisplayRadix     the radix in which integers present their
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    51
				displayString (which is used in inspectors)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    52
				If you are to look at many hex numbers, bitmasks
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    53
				etc. you may set this to 2 or 16.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    54
				(avoids typing printStringRadix:.. all the time
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    55
				 - I know - I am lazy ;-). Default is 10.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    56
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    57
    [author:]
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    58
	Claus Gittinger
1628
da30f2f41db7 comment
Claus Gittinger <cg@exept.de>
parents: 1557
diff changeset
    59
da30f2f41db7 comment
Claus Gittinger <cg@exept.de>
parents: 1557
diff changeset
    60
    [see also:]
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    61
	Integer LargeInteger SmallInteger
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    62
	LimitedPrecisionReal Float ShortFloat
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
    63
	Fraction FixedPoint
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    64
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    65
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    66
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    67
!Number class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    68
21871
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
    69
coerce:aNumber
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
    70
    "convert the argument aNumber into an instance of the receiver (class) and return it."
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
    71
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
    72
    self == Number ifTrue:[
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
    73
        self assert:(aNumber isNumber).
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
    74
        ^ aNumber
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
    75
    ].
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
    76
    ^ super coerce:aNumber
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
    77
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
    78
    "Created: / 21-06-2017 / 08:58:38 / cg"
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
    79
!
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
    80
11944
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    81
fastFromString:aString
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    82
    "return the next Float, Integer or ShortFloat from the string.
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    83
     No spaces are skipped.
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
     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
    86
     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
    87
     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
    88
     especially for mass-data."
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    89
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    90
    ^ self fastFromString:aString at:1
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    91
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    92
    "
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    93
     Float fromString:'12345.0'
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    94
     Float fastFromString:'12345.0'
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    95
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    96
     Integer fromString:'12345'
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    97
     Integer fastFromString:'12345'
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    98
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
    99
     should be roughly 10times faster than the general method:
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
     Time millisecondsToRun:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   102
	100000 timesRepeat:[ Float fromString:'12345.0' ]
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   103
     ].
11944
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
   104
     Time millisecondsToRun:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   105
	100000 timesRepeat:[ Float fastFromString:'12345.0' ]
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   106
     ].
11944
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
   107
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
   108
     Time millisecondsToRun:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   109
	100000 timesRepeat:[ Integer fromString:'12345' ]
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   110
     ].
11944
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
   111
     Time millisecondsToRun:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   112
	100000 timesRepeat:[ Integer fastFromString:'12345' ]
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   113
     ].
11944
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
   114
    "
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
   115
!
6fb9813181cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11770
diff changeset
   116
24449
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   117
fastFromString:aString at:startIndex
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   118
    "return the next Float, Integer or ShortFloat from the string.
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   119
     No spaces are skipped.
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   120
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   121
     This is a specially tuned entry (using a low-level C-call), which
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   122
     returns garbage if the argument string is not a valid float number.
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   123
     It has been added to allow high speed string decomposition into numbers,
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   124
     especially for mass-data."
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   125
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   126
    self subclassResponsibility
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   127
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   128
    "
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   129
     Float fromString:'12345.0'
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   130
     Float fastFromString:'12345.0'
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   131
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   132
     Integer fromString:'12345'
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   133
     Integer fastFromString:'12345'
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   134
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   135
     should be roughly 10times faster than the general method:
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   136
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   137
     Time millisecondsToRun:[
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   138
        100000 timesRepeat:[ Float fromString:'12345.0' ]
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   139
     ].
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   140
     Time millisecondsToRun:[
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   141
        100000 timesRepeat:[ Float fastFromString:'12345.0' ]
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   142
     ].
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   143
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   144
     Time millisecondsToRun:[
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   145
        100000 timesRepeat:[ Integer fromString:'12345' ]
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   146
     ].
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   147
     Time millisecondsToRun:[
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   148
        100000 timesRepeat:[ Integer fastFromString:'12345' ]
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   149
     ].
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   150
    "
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   151
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   152
    "Created: / 21-07-2019 / 19:17:17 / Claus Gittinger"
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   153
!
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   154
21871
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
   155
fromNumber:aNumber
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
   156
    "return aNumber coerced to myself"
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
   157
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
   158
    self isAbstract ifTrue:[^ aNumber]. 
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
   159
    ^ self coerce:aNumber
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
   160
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
   161
    "Created: / 21-06-2017 / 08:57:00 / cg"
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
   162
!
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
   163
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   164
fromString:aString
17056
dfbf6a7fd352 class: Number
Claus Gittinger <cg@exept.de>
parents: 16656
diff changeset
   165
    "return a number by reading from aString.
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   166
     In contrast to readFrom:, no garbage is allowed after the number.
17056
dfbf6a7fd352 class: Number
Claus Gittinger <cg@exept.de>
parents: 16656
diff changeset
   167
     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
   168
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   169
    ^ self
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   170
	fromString:aString
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   171
	decimalPointCharacters:(self decimalPointCharactersForReading)
9333
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
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   174
     Number fromString:'12345'
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   175
     Number fromString:'abc'
17056
dfbf6a7fd352 class: Number
Claus Gittinger <cg@exept.de>
parents: 16656
diff changeset
   176
     Number fromString:'1abc'   -> raises an error
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   177
     Number readFrom:'1abc'     -> reads a 1
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   178
     Number readFrom:'10/2'     -> reads a 10
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   179
     Number fromString:'10/2'   -> raises an error
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   180
     Number fromString:'(1/2)'  -> reads a fraction
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   181
     Number readFrom:'(1/2)'    -> reads a fraction
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   182
     Number readFrom:'(10/2)'   -> reads a 5
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   183
     '12345' asNumber
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   184
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   185
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   186
    "Modified: / 3.8.1998 / 20:05:11 / cg"
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   187
!
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   188
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   189
fromString:aString decimalPointCharacter:decimalPointCharacter
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   190
    "return a number by reading from aString.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   191
     In contrast to readFrom:, no garbage is allowed after the number.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   192
     I.e. the string must contain exactly one valid number (with optional separators around)"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   193
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   194
    ^ self fromString:aString decimalPointCharacters:(decimalPointCharacter asString)
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   195
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   196
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   197
     Number fromString:'12345.99' decimalPointCharacter:$.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   198
     Number fromString:'12345,99' decimalPointCharacter:$,
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   199
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   200
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   201
    "Created: / 21-07-2019 / 13:09:13 / Claus Gittinger"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   202
    "Modified (comment): / 21-07-2019 / 18:04:30 / Claus Gittinger"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   203
!
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   204
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   205
fromString:aString decimalPointCharacter:decimalPointCharacter onError:exceptionBlock
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   206
    "return a number by reading from aString.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   207
     In contrast to readFrom:, no garbage is allowed after the number.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   208
     I.e. the string must contain exactly one valid number (with optional separators around)"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   209
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   210
    ^ self 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   211
        fromString:aString 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   212
        decimalPointCharacters:(decimalPointCharacter asString) 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   213
        onError:exceptionBlock.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   214
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   215
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   216
     Number fromString:'12,345' decimalPointCharacter:',' onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   217
     Number fromString:'12,345' decimalPointCharacter:$, onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   218
     Number fromString:'12,345,456' decimalPointCharacter:$. thouseandsSeparator:$, onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   219
     Number fromString:'12,345,45' decimalPointCharacter:$. thouseandsSeparator:$, onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   220
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   221
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   222
    "Created: / 21-07-2019 / 13:07:39 / Claus Gittinger"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   223
    "Modified (comment): / 21-07-2019 / 18:50:18 / Claus Gittinger"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   224
!
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   225
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   226
fromString:aString decimalPointCharacter:decimalPointCharacter thousandsSeparator:thousandsSeparator onError:exceptionBlock
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   227
    "return a number by reading from aString.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   228
     In contrast to readFrom:, no garbage is allowed after the number.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   229
     I.e. the string must contain exactly one valid number (with optional separators around)"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   230
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   231
    ^ self 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   232
        fromString:aString 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   233
        decimalPointCharacters:(decimalPointCharacter asString) 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   234
        thousandsSeparator:thousandsSeparator
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   235
        onError:exceptionBlock.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   236
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   237
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   238
     Number fromString:'12,345' decimalPointCharacter:',' onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   239
     Number fromString:'12,345' decimalPointCharacter:$, onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   240
     Number fromString:'12345,456' decimalPointCharacter:$. thousandsSeparator:$, onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   241
     Number fromString:'12,345,456' decimalPointCharacter:$. thousandsSeparator:$, onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   242
     Number fromString:'12,345,456,789' decimalPointCharacter:$. thousandsSeparator:$, onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   243
     Number fromString:'12,345,456,789.89' decimalPointCharacter:$. thousandsSeparator:$, onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   244
     Number fromString:'12.345.456.789,89' decimalPointCharacter:$, thousandsSeparator:$. onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   245
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   246
    these report an error:
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   247
     Number fromString:'12,345,45' decimalPointCharacter:$. thousandsSeparator:$, onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   248
     Number fromString:'12.345.456.789' decimalPointCharacter:$. thousandsSeparator:$, onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   249
     Number fromString:'12.345.456.78' decimalPointCharacter:$. thousandsSeparator:$, onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   250
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   251
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   252
    "Created: / 21-07-2019 / 18:50:57 / Claus Gittinger"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   253
!
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   254
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   255
fromString:aString decimalPointCharacters:decimalPointCharacters
17056
dfbf6a7fd352 class: Number
Claus Gittinger <cg@exept.de>
parents: 16656
diff changeset
   256
    "return a number by reading from aString.
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   257
     In contrast to readFrom:, no garbage is allowed after the number.
17056
dfbf6a7fd352 class: Number
Claus Gittinger <cg@exept.de>
parents: 16656
diff changeset
   258
     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
   259
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   260
    |s num|
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   261
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   262
    s := aString readStream.
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   263
    num := self 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   264
            readFrom:s 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   265
            decimalPointCharacters:decimalPointCharacters 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   266
            onError:[^ ConversionError raiseRequestErrorString:' - invalid number'].
17056
dfbf6a7fd352 class: Number
Claus Gittinger <cg@exept.de>
parents: 16656
diff changeset
   267
    s atEnd ifFalse:[
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   268
        s skipSeparators.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   269
        s atEnd ifFalse:[
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   270
            ^ ConversionError raiseRequestErrorString:' - garbage at end of number'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   271
        ].
17056
dfbf6a7fd352 class: Number
Claus Gittinger <cg@exept.de>
parents: 16656
diff changeset
   272
    ].
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   273
    ^ num.
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   274
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   275
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   276
     Number fromString:'12345'
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   277
     Number fromString:'abc'
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   278
     Number fromString:'1abc'
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   279
     '12345' asNumber
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   280
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   281
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   282
    "Modified: / 03-08-1998 / 20:05:11 / cg"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   283
    "Modified (format): / 21-07-2019 / 18:04:58 / Claus Gittinger"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   284
!
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   285
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   286
fromString:aString decimalPointCharacters:decimalPointCharacters onError:exceptionBlock
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   287
    "return a number by reading from aString.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   288
     In contrast to readFrom:, no garbage is allowed after the number.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   289
     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
   290
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   291
    ^ self
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   292
        fromString:aString 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   293
        decimalPointCharacters:decimalPointCharacters 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   294
        thousandsSeparator:nil 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   295
        onError:exceptionBlock
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   296
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   297
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   298
     Number fromString:'12345' onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   299
     Number fromString:'12,345' decimalPointCharacters:',' onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   300
     Number fromString:'12,345' decimalPointCharacters:',' onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   301
     Number fromString:'fooBarBaz' onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   302
     Number fromString:'123fooBarBaz' onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   303
     Number fromString:'123,fooBarBaz' decimalPointCharacters:',' onError:0
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   304
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   305
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   306
    "Modified: / 03-08-1998 / 20:05:34 / cg"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   307
    "Modified: / 21-07-2019 / 18:02:55 / Claus Gittinger"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   308
!
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   309
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   310
fromString:aString decimalPointCharacters:decimalPointCharacters thousandsSeparator:thousandsSeparator onError:exceptionBlock
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   311
    "return a number by reading from aString.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   312
     In contrast to readFrom:, no garbage is allowed after the number.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   313
     I.e. the string must contain exactly one valid number (with optional separators around)"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   314
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   315
    |s num|
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   316
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   317
    s := aString readStream.
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   318
    num := self readFrom:s 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   319
            decimalPointCharacters:decimalPointCharacters 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   320
            thousandsSeparator:thousandsSeparator
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   321
            onError:[^ exceptionBlock value].
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   322
    s atEnd ifFalse:[
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   323
        s skipSeparators.
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   324
        s atEnd ifFalse:[
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   325
            ^ exceptionBlock value "/ - garbage at end of number'
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   326
        ].
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   327
    ].
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   328
    ^ num.
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   329
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   330
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   331
     Number fromString:'12345' onError:0
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   332
     Number fromString:'12,345' decimalPointCharacters:',' onError:0
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   333
     Number fromString:'12,345' decimalPointCharacters:',' onError:0
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   334
     Number fromString:'fooBarBaz' onError:0
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   335
     Number fromString:'123fooBarBaz' onError:0
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   336
     Number fromString:'123,fooBarBaz' decimalPointCharacters:',' onError:0
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   337
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   338
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   339
    "Created: / 21-07-2019 / 18:02:32 / Claus Gittinger"
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   340
!
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   341
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   342
fromString:aString onError:exceptionBlock
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   343
    "return a number by reading from aString.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   344
     In contrast to readFrom:, no garbage is allowed after the number.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   345
     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
   346
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   347
    ^ self fromString:aString decimalPointCharacters:(self decimalPointCharactersForReading) onError:exceptionBlock
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   348
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   349
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   350
     Number fromString:'12345' onError:0
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   351
     Number fromString:'fooBarBaz' onError:0
21142
d9692dfa814f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21105
diff changeset
   352
     Number fromString:'123fooBarBaz' onError:0
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   353
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   354
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   355
    "Modified: / 3.8.1998 / 20:05:34 / cg"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   356
!
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   357
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   358
readFrom:aStringOrStream decimalPointCharacter:decimalPointCharacter
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   359
    "return the next Number from the (character-)stream aStream;
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   360
     skipping all whitespace first.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   361
     Return the value of exceptionBlock, if no number can be read.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   362
     This method is less strict than the smalltalk number reader; it
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   363
     allows for prefixed + and also allows missing fractional part after eE.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   364
     It also allows garbage after the number - i.e. it reads what it can.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   365
     See #fromString: , which is more strict and does not allow garbage at the end."
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   366
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   367
    ^ self
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   368
        readFrom:aStringOrStream
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   369
        decimalPointCharacters:(decimalPointCharacter asString)
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   370
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   371
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   372
     Number readFrom:'123.456' decimalPointCharacter:$.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   373
     Number readFrom:'123,456' decimalPointCharacter:$,
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   374
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   375
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   376
    "Created: / 21-07-2019 / 13:09:52 / Claus Gittinger"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   377
!
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   378
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   379
readFrom:aStringOrStream decimalPointCharacter:decimalPointCharacter onError:exceptionBlock
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   380
    "return the next Number from the (character-)stream aStream;
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   381
     skipping all whitespace first.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   382
     Return the value of exceptionBlock, if no number can be read.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   383
     This method is less strict than the Smalltalk number reader; 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   384
     it allows for prefixed + and also allows missing fractional part after eE.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   385
     It supports the regular Smalltalk radix prefix xr.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   386
     It also allows garbage after the number - i.e. it reads what it can.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   387
     See #fromString: , which is more strict and does not allow garbage at the end.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   388
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   389
     Notice (see examples below): 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   390
        if sent to Number, it will decide which type of number to return (depending on the exponent character);
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   391
        if sent to a concrete number-class, an instance of that class will be returned (independent of the exponent character)
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   392
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   393
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   394
    ^ self readFrom:aStringOrStream decimalPointCharacters:(decimalPointCharacter asString) onError:exceptionBlock
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   395
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   396
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   397
     Number readFrom:(ReadStream on:'54.32e-01') decimalPointCharacter:$. onError:[self halt].
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   398
     Number readFrom:(ReadStream on:'54,32e-01') decimalPointCharacter:$, onError:[self halt].
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   399
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   400
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   401
    "Created: / 21-07-2019 / 13:11:12 / Claus Gittinger"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   402
!
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   403
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   404
readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   405
    "return the next Number from the (character-)stream aStream;
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   406
     skipping all whitespace first.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   407
     Return the value of exceptionBlock, if no number can be read.
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   408
     This method is less strict than the smalltalk number reader; it
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   409
     allows for prefixed + and also allows missing fractional part after eE.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   410
     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
   411
     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
   412
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   413
    ^ self
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   414
	readFrom:aStringOrStream
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   415
	decimalPointCharacters:decimalPointCharacters
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   416
	onError:[self error:'conversion error for: ' , self name]
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   417
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   418
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   419
     Number readFrom:'123.456' decimalPointCharacters:'.'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   420
     Number readFrom:'123,456' decimalPointCharacters:'.,'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   421
     Number readFrom:'123,456' decimalPointCharacters:'.'
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   422
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   423
!
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   424
23481
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   425
readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters allowCStyle:allowCStyle onError:exceptionBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   426
    "return the next Number from the (character-)stream aStream;
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   427
     skipping all whitespace first.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   428
     Return the value of exceptionBlock, if no number can be read.
23480
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   429
     This method is less strict than the Smalltalk number reader; 
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   430
     it allows for prefixed + and also allows missing fractional part after eE.
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   431
     It supports 0x, 0o and 0b prefixes (hex, octal and binary)
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   432
     and the regular Smalltalk radix prefix xr.
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
   433
     If also allows for strings like '1.0×1015' to be read (as 1E+15).
23615
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   434
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   435
     It also allows garbage after the number - i.e. it reads what it can.
21815
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   436
     See #fromString: , which is more strict and does not allow garbage at the end.
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   437
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   438
     Notice (see examples below): 
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   439
        if sent to Number, it will decide which type of number to return (depending on the exponent character);
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   440
        if sent to a concrete number-class, an instance of that class will be returned (independent of the exponent character)
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   441
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   442
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   443
    ^ self
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   444
        readFrom:aStringOrStream 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   445
        decimalPointCharacters:decimalPointCharacters
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   446
        thousandsSeparator:nil
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   447
        allowCStyle:allowCStyle onError:exceptionBlock
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   449
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   450
     Number readFrom:(ReadStream on:'1.234.567,99') 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   451
        decimalPointCharacter:$,
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   452
        thousandsSeparator:$.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   453
        onError:[self halt].
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   454
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   455
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   456
    "Created: / 27-10-2018 / 09:21:11 / Claus Gittinger"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   457
    "Modified: / 21-07-2019 / 13:06:54 / Claus Gittinger"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   458
!
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   459
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   460
readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters onError:exceptionBlock
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   461
    "return the next Number from the (character-)stream aStream;
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   462
     skipping all whitespace first.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   463
     Return the value of exceptionBlock, if no number can be read.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   464
     This method is less strict than the Smalltalk number reader; 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   465
     it allows for prefixed + and also allows missing fractional part after eE.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   466
     It supports the regular Smalltalk radix prefix xr.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   467
     It also allows garbage after the number - i.e. it reads what it can.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   468
     See #fromString: , which is more strict and does not allow garbage at the end.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   469
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   470
     Notice (see examples below): 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   471
        if sent to Number, it will decide which type of number to return (depending on the exponent character);
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   472
        if sent to a concrete number-class, an instance of that class will be returned (independent of the exponent character)
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   473
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   474
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   475
    ^ self 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   476
        readFrom:aStringOrStream 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   477
        decimalPointCharacters:decimalPointCharacters 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   478
        thousandsSeparator:nil
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   479
        allowCStyle:false 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   480
        onError:exceptionBlock
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   481
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   482
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   483
     Number readFrom:(ReadStream on:'54.32e-01') decimalPointCharacters:'.' onError:[self halt].
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   484
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   485
     Number readFrom:(ReadStream on:'12345') decimalPointCharacters:'.' onError:[self halt].
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   486
     Number readFrom:(ReadStream on:'12345.0') decimalPointCharacters:'.' onError:[self halt].
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   487
     
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   488
     Number readFrom:(ReadStream on:'12345.0f') decimalPointCharacters:'.' onError:[self halt].
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   489
     Number readFrom:(ReadStream on:'12345.0e') decimalPointCharacters:'.' onError:[self halt].
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   490
     Number readFrom:(ReadStream on:'12345.0q') decimalPointCharacters:'.' onError:[self halt].
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   491
     Number readFrom:(ReadStream on:'12345.0d') decimalPointCharacters:'.' onError:[self halt].
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   492
     Number readFrom:(ReadStream on:'12345.0s') decimalPointCharacters:'.' onError:[self halt].
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   493
     Number readFrom:(ReadStream on:'12345.01s') decimalPointCharacters:'.' onError:[self halt].
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   494
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   495
     Float readFrom:(ReadStream on:'12345') decimalPointCharacters:'.' onError:[self halt].
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   496
     
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   497
     Number readFrom:(ReadStream on:'12345678901234567890')
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   498
     Number readFrom:(ReadStream on:'12345678901234567890.0')
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   499
     Number readFrom:(ReadStream on:'12345678901234567890.012345678901234567890')
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   500
     Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   501
     Number readFrom:'16rAAAAFFFFAAAAFFFF'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   502
     Number readFrom:'16r100A'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   503
     Number readFrom:'16r100a'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   504
     Number readFrom:'0.000001'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   505
     '+00000123.45' asNumber
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   506
     Number readFrom:'(1/3)'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   507
     Number readFrom:'(-1/3)'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   508
     Number readFrom:'(1/-3)'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   509
     Number readFrom:'-(1/3)'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   510
     Number readFrom:'-(-1/3)'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   511
     Number readFrom:'(-1/3'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   512
     Number readFrom:'99s'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   513
     Number readFrom:'99.00s'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   514
     Number readFrom:'99.0000000s'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   515
     Number readFrom:'.0000000s'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   516
     Number readFrom:'.0000000q'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   517
     Number readFrom:'.0000000f'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   518
     Number readFrom:'.0000000e'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   519
     Number readFrom:'.0000000s1'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   520
     Number readFrom:'.0000000q1'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   521
     Number readFrom:'.0000000f1'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   522
     Number readFrom:'.0000000e1'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   523
     LongFloat readFrom:'.00000001'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   524
     Number readFrom:'.00000000000001'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   525
     Number readFrom:'.001'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   526
     ShortFloat readFrom:'.001'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   527
     Number readFrom:'123garbage'      -> returns 123
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   528
     Number fromString:'123garbage'    -> raises an error
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   529
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   530
     DecimalPointCharactersForReading := #( $. $, ).
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   531
     Number readFrom:'99,00'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   532
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   533
     DecimalPointCharactersForReading := #( $. ).
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   534
     Number readFrom:'99,00'
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   535
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   536
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   537
    "Modified: / 17-07-2017 / 15:18:03 / cg"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   538
    "Modified: / 21-07-2019 / 13:05:19 / Claus Gittinger"
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   539
!
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   540
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   541
readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters thousandsSeparator:thousandsSeparator allowCStyle:allowCStyle onError:exceptionBlock
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   542
    "return the next Number from the (character-)stream aStream;
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   543
     skipping all whitespace first.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   544
     Return the value of exceptionBlock, if no number can be read.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   545
     This method is less strict than the Smalltalk number reader; 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   546
     it allows for prefixed + and also allows missing fractional part after eE.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   547
     It supports 0x, 0o and 0b prefixes (hex, octal and binary)
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   548
     and the regular Smalltalk radix prefix xr.
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
   549
     If also allows for strings like '1.0×1015' to be read (as 1E+15).
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   550
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   551
     It also allows garbage after the number - i.e. it reads what it can.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   552
     See #fromString: , which is more strict and does not allow garbage at the end.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   553
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   554
     Notice (see examples below): 
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   555
        if sent to Number, it will decide which type of number to return (depending on the exponent character);
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   556
        if sent to a concrete number-class, an instance of that class will be returned (independent of the exponent character)
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   557
    "
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   558
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   559
    ^ [
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   560
        |value intValue mantissaAndScale scale decimalMantissa str
24996
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   561
         nextChar radix sign signExp exp numerator denom expChar expChar2
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   562
         fragment mantissa|
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   563
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   564
        str := aStringOrStream readStream.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   565
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   566
        nextChar := str skipSeparators.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   567
        nextChar isNil ifTrue:[^ exceptionBlock value].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   568
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   569
        (nextChar == $-) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   570
            sign := -1.
24449
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   571
            nextChar := str nextPeekOrNil
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   572
        ] ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   573
            sign := 1.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   574
            (nextChar == $+) ifTrue:[
24449
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   575
                nextChar := str nextPeekOrNil
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   576
            ]
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   577
        ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   578
        nextChar == $( ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   579
            "maybe a Fraction e.g. (1/3)"
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   580
            str next.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   581
            numerator := Integer readFrom:str onError:[^ exceptionBlock value].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   582
            str skipSeparators.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   583
            nextChar := str peekOrNil.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   584
            nextChar == $/ ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   585
                str next.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   586
                denom := Integer readFrom:str onError:[^ exceptionBlock value].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   587
                str skipSeparators.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   588
                nextChar := str peekOrNil.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   589
            ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   590
            nextChar == $) ifFalse:[^ exceptionBlock value].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   591
            str next.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   592
            value := Fraction numerator:numerator denominator:denom.
24996
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   593
            sign < 0 ifTrue:[ value := value negated ].
21871
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
   594
            (self ~~ Number and:[self ~~ Fraction]) ifTrue:[
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
   595
                value := self coerce:value.
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
   596
            ].    
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
   597
            ^ value
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   598
        ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   599
        nextChar isNil ifTrue:[^ exceptionBlock value].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   600
        (nextChar isDigit or:[(decimalPointCharacters includes:nextChar)]) ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   601
            ^ exceptionBlock value.
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   602
"/          value := super readFrom:str.
15197
a78cec832ef3 class: Number
Claus Gittinger <cg@exept.de>
parents: 15127
diff changeset
   603
"/          sign == -1 ifTrue:[value := value negated].
339
claus
parents: 329
diff changeset
   604
"/          ^ value
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   605
        ].
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   606
        radix := 10.
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   607
        (decimalPointCharacters includes:nextChar) ifTrue:[
22043
56a894e6e543 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21992
diff changeset
   608
            self isAbstract ifTrue:[
56a894e6e543 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21992
diff changeset
   609
                value := 0.0.
56a894e6e543 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21992
diff changeset
   610
            ] ifFalse:[    
56a894e6e543 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21992
diff changeset
   611
                value := self zero. "/ 0.0.
56a894e6e543 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21992
diff changeset
   612
            ].
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   613
            intValue := 0.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   614
        ] ifFalse:[
23481
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   615
            (allowCStyle and:[nextChar == $0]) ifTrue:[
24449
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   616
                nextChar := str nextPeekOrNil.
23480
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   617
                nextChar isNil ifTrue:[^ 0].
24449
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   618
                nextChar == $x ifTrue:[ str next. radix := 16 ] 
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   619
                ifFalse:[ nextChar == $b ifTrue:[ str next. radix := 2 ] 
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   620
                ifFalse:[ nextChar == $o ifTrue:[ str next. radix := 8 ] 
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   621
                ifFalse:[
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   622
                    nextChar isDigit ifFalse:[
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   623
                        ^ 0
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   624
                    ].        
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   625
                ]]].
23480
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   626
                value := Integer readFrom:str radix:radix.
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   627
                nextChar := str peekOrNil.
23480
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   628
            ] ifFalse:[        
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   629
                value := Integer readFrom:str radix:10.
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   630
                nextChar := str peekOrNil.
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   631
                [ thousandsSeparator notNil and:[nextChar == thousandsSeparator] ] whileTrue:[
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   632
                    str next.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   633
                    fragment := str next:3.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   634
                    (fragment conform:#isDigit) ifFalse:[
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   635
                        ^ exceptionBlock value.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   636
                    ].
24449
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   637
                    value := (value * 1000) + (Integer fastFromString:fragment at:1).
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   638
                    nextChar := str peekOrNil.
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   639
                ].    
23480
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   640
                ((nextChar == $r) or:[ nextChar == $R]) ifTrue:[
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   641
                    str next.
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   642
                    radix := value.
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   643
                    value := Integer readFrom:str radix:radix.
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   644
                    nextChar := str peekOrNil.
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   645
                ] ifFalse:[
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   646
                    radix := 10
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   647
                ].
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   648
            ].        
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   649
            intValue := value.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   650
        ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   651
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   652
        (self == Integer or:[self inheritsFrom:Integer]) ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   653
            (decimalPointCharacters includes:nextChar) ifTrue:[
24449
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   654
                nextChar := str nextPeekOrNil.
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   655
                decimalMantissa := 0.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   656
                (nextChar notNil and:[nextChar isDigitRadix:radix]) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   657
                    mantissaAndScale := self readMantissaAndScaleFrom:str radix:radix.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   658
                    mantissa := mantissaAndScale first.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   659
                    value := (mantissa coerce:value) + mantissa.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   660
                    nextChar := str peekOrNil.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   661
                ]
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   662
            ].
21815
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   663
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   664
            ('eEdDqQfF' includes:nextChar) ifTrue:[
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   665
                expChar := nextChar.
24449
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   666
                nextChar := str nextPeekOrNil.
24996
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   667
                expChar == $Q ifTrue:[
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   668
                    nextChar == $D ifTrue:[
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   669
                        expChar2 := nextChar.
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   670
                        nextChar := str nextPeekOrNil.
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   671
                    ] ifFalse:[
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   672
                        nextChar == $L ifTrue:[
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   673
                            expChar2 := nextChar.
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   674
                            nextChar := str nextPeekOrNil.
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   675
                        ]
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   676
                    ]
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   677
                ].
21815
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   678
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   679
                signExp := 1.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   680
                (nextChar == $+) ifTrue:[
24449
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   681
                    nextChar := str nextPeekOrNil.
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   682
                ] ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   683
                    (nextChar == $-) ifTrue:[
24449
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   684
                        nextChar := str nextPeekOrNil.
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   685
                        signExp := -1
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   686
                    ]
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   687
                ].
21815
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   688
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   689
                "/ if I am abstract (i.e. I am Number or LPReal),
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   690
                "/ let the exponent-character decide what kind of float we get:
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   691
                "/      qQ   -> LongFloat
23479
c73c6affd861 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23323
diff changeset
   692
                "/      eEdD -> Float      (which is ieee-double)
c73c6affd861 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23323
diff changeset
   693
                "/      fF   -> ShortFloat (which is ieee-float)
21815
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   694
                
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   695
                self isAbstract ifTrue:[
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   696
                    ('qQ' includes:expChar) ifTrue:[
24996
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   697
                        expChar2 == $D ifTrue:[
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   698
                            value := value asQDouble
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   699
                        ] ifFalse:[
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   700
                            expChar2 == $L ifTrue:[
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   701
                                value := value asLargeFloat
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   702
                            ] ifFalse:[
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   703
                                value := value asLongFloat.
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   704
                            ]
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
   705
                        ]
21815
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   706
                    ] ifFalse:[
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   707
                        ('fF' includes:expChar) ifTrue:[
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   708
                            value := value asShortFloat.
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   709
                        ] ifFalse:[    
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   710
                            "/ maybe in the far future we might create shortfloats when seeing eE,
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   711
                            "/ and only produce doubles on dD.
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   712
                            "/ (for now, always create Doubles for Dolphin, Squeak etc. compatibility)
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   713
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   714
                            false "('eE' includes:expChar)" ifTrue:[
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   715
                                value := value asShortFloat
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   716
                            ] ifFalse:[
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   717
                                value := value asFloat.
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   718
                            ].    
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   719
                        ].    
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   720
                    ].
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   721
                ] ifFalse:[
21871
2e74148f065b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21839
diff changeset
   722
                    value := self coerce:value.
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   723
                ].
21815
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   724
                
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   725
                (nextChar notNil and:[(nextChar isDigitRadix:radix)]) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   726
                    exp := (Integer readFrom:str radix:radix) * signExp.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   727
                    value := value * ((value class unity * 10.0) raisedToInteger:exp)
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   728
                ]
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   729
            ] ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   730
                ('sS' includes:nextChar) ifTrue:[
24449
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   731
                    nextChar := str nextPeekOrNil.
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   732
                    (nextChar notNil and:[ nextChar isDigit]) ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   733
                        scale := (Integer readFrom:str).
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   734
                    ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   735
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   736
                    mantissaAndScale isNil ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   737
                        value := intValue asFixedPoint:(scale ? 0).
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   738
                    ] ifFalse:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   739
                        denom := 10 raisedTo:mantissaAndScale last.
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   740
                        value := FixedPoint
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   741
                                    numerator:(intValue * denom) + (mantissaAndScale second)
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   742
                                    denominator:denom
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   743
                                    scale:(scale ? mantissaAndScale third).
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   744
                    ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   745
                ] ifFalse:[
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
   746
                    (nextChar == $×) ifTrue:[
23615
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   747
                        (((nextChar := str nextPeek) == $1)
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   748
                          and:[ ((nextChar := str nextPeek) == $0) ]
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   749
                        ) ifTrue:[
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   750
                            str next.
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   751
                            exp := (Integer readFrom:str).
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   752
                            value := value * ((value class unity * 10.0) raisedToInteger:exp).
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   753
                        ] ifFalse:[
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   754
                            ^ exceptionBlock value.
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   755
                        ].
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   756
                    ] ifFalse:[        
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   757
                        (self inheritsFrom:LimitedPrecisionReal) ifTrue:[
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   758
                            "when requesting a specific Float instance, coerce it.
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   759
                             otherwise return a value without loosing precision"
25085
8bcc521a9e18 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25051
diff changeset
   760
                            (self isAbstract not and:[value class == self]) ifFalse:[
8bcc521a9e18 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25051
diff changeset
   761
                                value := self coerce:value.
8bcc521a9e18 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25051
diff changeset
   762
                            ].
23615
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
   763
                        ].
21634
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   764
                    ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   765
                ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   766
            ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   767
        ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   768
        sign == -1 ifTrue:[
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   769
            value := value negated
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   770
        ].
312cdb36acc9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21536
diff changeset
   771
        value.
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   772
    ] on:Error do:exceptionBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   773
329
claus
parents: 325
diff changeset
   774
    "
21815
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   775
     Number readFrom:(ReadStream on:'54.32e-01') decimalPointCharacters:'.' onError:[self halt].
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   776
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   777
     Number readFrom:(ReadStream on:'12345') decimalPointCharacters:'.' onError:[self halt].
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   778
     Number readFrom:(ReadStream on:'12345.0') decimalPointCharacters:'.' onError:[self halt].
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   779
     
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   780
     Number readFrom:(ReadStream on:'12345.0f') decimalPointCharacters:'.' onError:[self halt].
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   781
     Number readFrom:(ReadStream on:'12345.0e') decimalPointCharacters:'.' onError:[self halt].
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   782
     Number readFrom:(ReadStream on:'12345.0q') decimalPointCharacters:'.' onError:[self halt].
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   783
     Number readFrom:(ReadStream on:'12345.0d') decimalPointCharacters:'.' onError:[self halt].
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   784
     Number readFrom:(ReadStream on:'12345.0s') decimalPointCharacters:'.' onError:[self halt].
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   785
     Number readFrom:(ReadStream on:'12345.01s') decimalPointCharacters:'.' onError:[self halt].
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   786
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   787
     Float readFrom:(ReadStream on:'12345') decimalPointCharacters:'.' onError:[self halt].
e017f9904c30 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21812
diff changeset
   788
     
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   789
     Number readFrom:(ReadStream on:'12345678901234567890')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   790
     Number readFrom:(ReadStream on:'12345678901234567890.0')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   791
     Number readFrom:(ReadStream on:'12345678901234567890.012345678901234567890')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   792
     Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   793
     Number readFrom:'16rAAAAFFFFAAAAFFFF'
23480
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   794
     Number readFrom:'16r100A'
4af396c83bb9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23479
diff changeset
   795
     Number readFrom:'16r100a'
23481
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   796
     Number readFrom:'0.000001'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   797
     '+00000123.45' asNumber
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   798
     Number readFrom:'(1/3)'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   799
     Number readFrom:'(-1/3)'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   800
     Number readFrom:'(1/-3)'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   801
     Number readFrom:'-(1/3)'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   802
     Number readFrom:'-(-1/3)'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   803
     Number readFrom:'(-1/3'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   804
     Number readFrom:'99s'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   805
     Number readFrom:'99.00s'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   806
     Number readFrom:'99.0000000s'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   807
     Number readFrom:'.0000000s'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   808
     Number readFrom:'.0000000q'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   809
     Number readFrom:'.0000000f'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   810
     Number readFrom:'.0000000e'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   811
     Number readFrom:'.0000000s1'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   812
     Number readFrom:'.0000000q1'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   813
     Number readFrom:'.0000000f1'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   814
     Number readFrom:'.0000000e1'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   815
     LongFloat readFrom:'.00000001'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   816
     Number readFrom:'.00000000000001'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   817
     Number readFrom:'.001'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   818
     ShortFloat readFrom:'.001'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   819
     Number readFrom:'123garbage'      -> returns 123
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   820
     Number fromString:'123garbage'    -> raises an error
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   821
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   822
     DecimalPointCharactersForReading := #( $. $, ).
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   823
     Number readFrom:'99,00'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   824
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   825
     DecimalPointCharactersForReading := #( $. ).
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   826
     Number readFrom:'99,00'
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   827
    "
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   828
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   829
    "Created: / 21-07-2019 / 13:05:04 / Claus Gittinger"
24449
8f3ac8e3b265 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24448
diff changeset
   830
    "Modified: / 21-07-2019 / 19:40:34 / Claus Gittinger"
23481
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   831
!
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   832
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   833
readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters thousandsSeparator:thousandsSeparator onError:exceptionBlock
23481
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   834
    "return the next Number from the (character-)stream aStream;
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   835
     skipping all whitespace first.
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   836
     Return the value of exceptionBlock, if no number can be read.
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   837
     This method is less strict than the Smalltalk number reader; 
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   838
     it allows for prefixed + and also allows missing fractional part after eE.
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   839
     It supports the regular Smalltalk radix prefix xr.
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   840
     It also allows garbage after the number - i.e. it reads what it can.
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   841
     See #fromString: , which is more strict and does not allow garbage at the end.
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   842
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   843
     Notice (see examples below): 
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   844
        if sent to Number, it will decide which type of number to return (depending on the exponent character);
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   845
        if sent to a concrete number-class, an instance of that class will be returned (independent of the exponent character)
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   846
    "
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   847
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   848
    ^ self 
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   849
        readFrom:aStringOrStream 
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   850
        decimalPointCharacters:decimalPointCharacters 
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   851
        thousandsSeparator:thousandsSeparator
23481
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   852
        allowCStyle:false 
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   853
        onError:exceptionBlock
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   854
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   855
    "
6a64d7b9df9f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23480
diff changeset
   856
     Number readFrom:(ReadStream on:'12345') decimalPointCharacters:'.' onError:[self halt].
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   857
     Number readFrom:(ReadStream on:'12,345.0') decimalPointCharacters:'.' thousandsSeparator:$, onError:[self halt].
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   858
     Number readFrom:(ReadStream on:'12,1345.0') decimalPointCharacters:'.' thousandsSeparator:$, onError:[self halt].
329
claus
parents: 325
diff changeset
   859
    "
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   860
24448
466c98f76a4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24431
diff changeset
   861
    "Created: / 21-07-2019 / 17:59:57 / Claus Gittinger"
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   862
!
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   863
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   864
readFrom:aStringOrStream onError:exceptionBlock
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   865
    "return the next Number from the (character-)stream aStream;
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   866
     skipping all whitespace first; return the value of exceptionBlock,
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   867
     if no number can be read.
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   868
     This method is less strict than the smalltalk number reader; it
17057
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   869
     allows for prefixed + and also allows missing fractional part after eE.
08f275c70437 class: Number
Claus Gittinger <cg@exept.de>
parents: 17056
diff changeset
   870
     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
   871
     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
   872
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   873
    ^ self
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   874
	readFrom:aStringOrStream
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   875
	decimalPointCharacters:(self decimalPointCharactersForReading)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   876
	onError:exceptionBlock
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   877
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   878
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   879
     Number readFrom:(ReadStream on:'54.32e-01')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   880
     Number readFrom:(ReadStream on:'12345678901234567890')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   881
     Number readFrom:(ReadStream on:'12345678901234567890.0')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   882
     Number readFrom:(ReadStream on:'12345678901234567890.012345678901234567890')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   883
     Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   884
     Number readFrom:'16rAAAAFFFFAAAAFFFF'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   885
     Number readFrom:'0.000001'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   886
     '+00000123.45' asNumber
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   887
     Number readFrom:'99s'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   888
     Number readFrom:'99.00s'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   889
     Number readFrom:'99.0000000s'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   890
     Number readFrom:'.0000000s'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   891
     Number readFrom:'.0000000q'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   892
     Number readFrom:'.0000000f'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   893
     Number readFrom:'.0000000e'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   894
     Number readFrom:'.0000000s1'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   895
     Number readFrom:'.0000000q1'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   896
     Number readFrom:'.0000000f1'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   897
     Number readFrom:'.0000000e1'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   898
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   899
     DecimalPointCharactersForReading := #( $. $, ).
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   900
     Number readFrom:'99,00'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   901
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   902
     DecimalPointCharactersForReading := #( $. ).
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   903
     Number readFrom:'99,00'
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   904
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   905
!
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   906
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   907
readSmalltalkSyntaxFrom:aStream
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   908
    "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
   909
     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
   910
     (character-) aStream.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   911
     Returns nil if aStream contains no valid number."
329
claus
parents: 325
diff changeset
   912
15776
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   913
    ^ self readSmalltalkSyntaxFrom:aStream onError:nil.
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   914
329
claus
parents: 325
diff changeset
   915
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   916
     Number readSmalltalkSyntaxFrom:'99d'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   917
     Number readSmalltalkSyntaxFrom:'99.00d'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   918
     Number readSmalltalkSyntaxFrom:'54.32e-01'
15078
997a122ceeb5 class: Number
Stefan Vogel <sv@exept.de>
parents: 14495
diff changeset
   919
     Number readSmalltalkSyntaxFrom:'12345678901234567890'
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   920
     Number readSmalltalkSyntaxFrom:'16rAAAAFFFFAAAAFFFF'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   921
     Number readSmalltalkSyntaxFrom:'foobar'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   922
     Number readSmalltalkSyntaxFrom:'(1/10)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   923
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   924
     Number readSmalltalkSyntaxFrom:'(1/0)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   925
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   926
     Number readFrom:'(1/3)'
15078
997a122ceeb5 class: Number
Stefan Vogel <sv@exept.de>
parents: 14495
diff changeset
   927
     Number readFrom:'(-1/3)'
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   928
     Number readFrom:'-(1/3)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   929
     Number readFrom:'(1/-3)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   930
     Number readFrom:'(-1/-3)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   931
     Number readFrom:'-(-1/-3)'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   932
     Number readSmalltalkSyntaxFrom:'+00000123.45'
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   933
     Number readFrom:'+00000123.45'
5013
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   934
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   935
     |s|
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   936
     s := ReadStream on:'2.'.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   937
     Number readSmalltalkSyntaxFrom:s.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   938
     s next
5013
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   939
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   940
     |s|
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   941
     s := ReadStream on:'2.0.'.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   942
     Number readSmalltalkSyntaxFrom:s.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   943
     s next
329
claus
parents: 325
diff changeset
   944
    "
3613
75629df7f224 fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents: 3394
diff changeset
   945
5013
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   946
    "Modified: / 19.11.1999 / 18:26:47 / cg"
15776
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   947
!
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   948
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   949
readSmalltalkSyntaxFrom:aStream onError:errorValue
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   950
    "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
   951
     read and return the next Number in smalltalk syntax from the
15776
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   952
     (character-) aStream.
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   953
     Returns nil if aStream contains no valid number."
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   954
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   955
    |n|
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   956
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   957
    [
24548
beea0f93303c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24494
diff changeset
   958
        n := Scanner scanNumberFrom:aStream.
15776
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   959
    ] on:Error do:[:ex|
24548
beea0f93303c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24494
diff changeset
   960
        n := nil
15776
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   961
    ].
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   962
    n isNil ifTrue:[^ errorValue value].
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   963
    ^ n
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   964
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   965
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
   966
     Number readSmalltalkSyntaxFrom:'foo' onError:123
24548
beea0f93303c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24494
diff changeset
   967
     Number readSmalltalkSyntaxFrom:'16r123' onError:-1
25041
d6edd7fd2430 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24996
diff changeset
   968
     Number readSmalltalkSyntaxFrom:'0x123' onError:-1   
d6edd7fd2430 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24996
diff changeset
   969
     Number readSmalltalkSyntaxFrom:'16r1.1' onError:-1  
d6edd7fd2430 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24996
diff changeset
   970
     Number readSmalltalkSyntaxFrom:'10r1.1' onError:-1    
d6edd7fd2430 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24996
diff changeset
   971
     Number readSmalltalkSyntaxFrom:'16r10.1' onError:-1  
d6edd7fd2430 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24996
diff changeset
   972
     Number readSmalltalkSyntaxFrom:'10r10.1' onError:-1    
d6edd7fd2430 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24996
diff changeset
   973
     Number readSmalltalkSyntaxFrom:'16r10.1e10' onError:-1  
d6edd7fd2430 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24996
diff changeset
   974
     Number readSmalltalkSyntaxFrom:'10r10.1e10' onError:-1    
15776
e7f5200ad493 class: Number
Claus Gittinger <cg@exept.de>
parents: 15595
diff changeset
   975
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   976
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   977
17686
f3233f56df6f class: Number
Claus Gittinger <cg@exept.de>
parents: 17469
diff changeset
   978
!Number class methodsFor:'Compatibility-VW'!
f3233f56df6f class: Number
Claus Gittinger <cg@exept.de>
parents: 17469
diff changeset
   979
f3233f56df6f class: Number
Claus Gittinger <cg@exept.de>
parents: 17469
diff changeset
   980
readIntegerFrom:aStream radix:radix
21789
abf8de4b8720 #DOCUMENTATION by mawalch
mawalch
parents: 21634
diff changeset
   981
    "for VisualWorks compatibility"
17686
f3233f56df6f class: Number
Claus Gittinger <cg@exept.de>
parents: 17469
diff changeset
   982
f3233f56df6f class: Number
Claus Gittinger <cg@exept.de>
parents: 17469
diff changeset
   983
    ^ Integer readFrom:aStream radix:radix
21789
abf8de4b8720 #DOCUMENTATION by mawalch
mawalch
parents: 21634
diff changeset
   984
abf8de4b8720 #DOCUMENTATION by mawalch
mawalch
parents: 21634
diff changeset
   985
    "Modified (comment): / 08-06-2017 / 13:58:36 / mawalch"
17686
f3233f56df6f class: Number
Claus Gittinger <cg@exept.de>
parents: 17469
diff changeset
   986
! !
f3233f56df6f class: Number
Claus Gittinger <cg@exept.de>
parents: 17469
diff changeset
   987
25122
a7acd17d012a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 25086
diff changeset
   988
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
   989
!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
   990
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
   991
e
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
   992
    "return the closest approximation of the irrational number e"
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
   993
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
   994
    ^ self subclassResponsibility
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
   995
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
   996
    "Modified: / 16-06-2017 / 11:04:49 / cg"
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
   997
!
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
   998
24262
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
   999
eDigits
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1000
    "return th printString of the irrational number e,
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1001
     with enough digits so that instances with different precision can read from it"
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1002
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1003
    "/ number asked from wolfram 
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1004
    ^ '2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746'
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1005
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1006
    "Created: / 06-06-2019 / 16:58:50 / Claus Gittinger"
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1007
!
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1008
21930
a892609c4586 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21916
diff changeset
  1009
i
a892609c4586 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21916
diff changeset
  1010
    "return the imaginary unit i"
a892609c4586 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21916
diff changeset
  1011
a892609c4586 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21916
diff changeset
  1012
    
a892609c4586 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21916
diff changeset
  1013
    ^ Complex real:0 imaginary:1
a892609c4586 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21916
diff changeset
  1014
a892609c4586 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21916
diff changeset
  1015
    "
22287
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  1016
     1 + Number i          -> (1+1i)
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  1017
     Number i + 10         -> (10+1i)
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  1018
     Number i * Number i   -> -1
21930
a892609c4586 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21916
diff changeset
  1019
    "
a892609c4586 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21916
diff changeset
  1020
a892609c4586 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21916
diff changeset
  1021
    "Created: / 01-07-2017 / 19:44:53 / cg"
22287
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  1022
    "Modified (comment): / 22-09-2017 / 09:53:14 / cg"
21930
a892609c4586 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21916
diff changeset
  1023
!
a892609c4586 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21916
diff changeset
  1024
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1025
ln10
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1026
    "return ln(10) in my representation (and accuracy)."
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1027
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1028
    ^ self subclassResponsibility
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1029
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1030
    "Created: / 16-06-2017 / 11:00:38 / cg"
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1031
!
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1032
24950
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  1033
ln2
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  1034
    "return ln(2) in my representation (and accuracy)."
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  1035
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  1036
    ^ self subclassResponsibility
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  1037
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  1038
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  1039
!
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  1040
24934
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1041
phi
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1042
    "return Phi in my representation (and accuracy)."
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1043
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1044
    ^ self subclassResponsibility
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1045
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1046
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1047
!
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1048
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1049
phiDigits
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1050
    "return th printString of the irrational number pi,
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1051
     with enough digits so that instances with different precision can read from it"
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1052
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1053
    ^ '1.618033988749894848204586834365638117720309179805762862135'
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1054
!
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  1055
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1056
pi
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1057
    "return Pi in my representation (and accuracy)."
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1058
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1059
    ^ self subclassResponsibility
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1060
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1061
    "Modified (format): / 16-06-2017 / 11:00:42 / cg"
24262
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1062
!
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1063
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1064
piDigits
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1065
    "return th printString of the irrational number pi,
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1066
     with enough digits so that instances with different precision can read from it"
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1067
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1068
    "/ number asked from wolfram 
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1069
    "/ ^ '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904'
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1070
    "/ rounded to 100 digits
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1071
    ^ '3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068'
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1072
dc3f1cc84694 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24237
diff changeset
  1073
    "Created: / 06-06-2019 / 17:08:17 / Claus Gittinger"
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1074
! !
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1075
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1076
!Number class methodsFor:'constants & defaults'!
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1077
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1078
decimalPointCharacter
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1079
    "printed"
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1080
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1081
    <resource: #obsolete>
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1082
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1083
    ^ self decimalPointCharacterForPrinting
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1084
!
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1085
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1086
decimalPointCharacter:aCharacter
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1087
    "printed"
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1088
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1089
    <resource: #obsolete>
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1090
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1091
    self decimalPointCharacterForPrinting:aCharacter
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1092
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1093
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1094
     1.5 printString
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1095
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1096
     Number decimalPointCharacter:$,.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1097
     1.5 printString
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1098
     Number decimalPointCharacter:$..
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1099
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1100
!
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1101
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1102
decimalPointCharacterForPrinting
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1103
    "printed"
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1104
16267
beef1cb9c801 class: Number
Claus Gittinger <cg@exept.de>
parents: 16070
diff changeset
  1105
    ^ DecimalPointCharacterForPrinting ? $.
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1106
!
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1107
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1108
decimalPointCharacterForPrinting:aCharacter
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1109
    "printed"
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1110
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1111
    DecimalPointCharacterForPrinting := aCharacter
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1112
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1113
    "
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1114
     1.5 printString
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1115
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
  1116
     Number decimalPointCharacterForPrinting:$,.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1117
     1.5 printString
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
  1118
     Number decimalPointCharacterForPrinting:$..
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1119
    "
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1120
!
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1121
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1122
decimalPointCharacters
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1123
    "accepted when converting from a string"
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1124
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1125
    <resource: #obsolete>
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1126
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1127
    ^ self decimalPointCharactersForReading
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1128
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1129
    "
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1130
     1.5 printString
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1131
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1132
     Number decimalPointCharacters:#( $. $,) .
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1133
     Number fromString:'1.5'.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1134
     Number fromString:'1,5'.
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1135
     Number decimalPointCharacters:#( $. ).
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1136
    "
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1137
!
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1138
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1139
decimalPointCharacters:aCollectionOfCharacters
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1140
    "accepted when converting from a string"
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1141
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1142
    <resource: #obsolete>
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1143
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1144
    self decimalPointCharactersForReading:aCollectionOfCharacters
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1145
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1146
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1147
     Number decimalPointCharacters:#( $. $,) .
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1148
     Number fromString:'1.5'.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1149
     Number fromString:'1,5'.
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1150
     Number decimalPointCharacters:#( $. ).
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1151
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1152
!
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1153
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1154
decimalPointCharactersForReading
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
  1155
    "default when converting from a string"
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1156
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
  1157
    "/ cg: changing the default leads to trouble in some
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
  1158
    "/ language processors (PrologScanner...)
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
  1159
    "/ 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
  1160
    "/ BETTER: pass the DecimalPointCharacterSet explicitly
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1161
    DecimalPointCharactersForReading isNil ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1162
	^ #( $. )
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1163
    ].
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1164
    ^ DecimalPointCharactersForReading
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1165
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1166
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1167
     1.5 printString
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1168
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
  1169
     Number decimalPointCharactersForReading:#( $. $,) .
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1170
     Number fromString:'1.5'.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1171
     Number fromString:'1,5'.
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
  1172
     Number decimalPointCharactersForReading:#( $. ).
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1173
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1174
!
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1175
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1176
decimalPointCharactersForReading:aCollectionOfCharacters
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1177
    "accepted when converting from a string"
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1178
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
  1179
    DecimalPointCharactersForReading := aCollectionOfCharacters
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1180
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1181
    "
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
  1182
     Number decimalPointCharactersForReading:#( $. $,) .
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1183
     Number fromString:'1.5'.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1184
     Number fromString:'1,5'.
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
  1185
     Number decimalPointCharactersForReading:#( $. ).
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
  1186
    "
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1187
! !
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1188
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  1189
!Number class methodsFor:'error reporting'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1190
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1191
raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel arg:arg errorString:text
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
  1192
    "ST-80 compatible signal raising. Provided for PD numeric classes"
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
  1193
4558
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
  1194
    <context: #return>
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
  1195
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
  1196
    ^ self
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1197
	raise:aSignalSymbolOrErrorClass
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1198
	receiver:someNumber
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1199
	selector:sel
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1200
	arguments:(Array with:arg)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1201
	errorString:text
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
  1202
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
  1203
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1204
     Number
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1205
	raise:#domainErrorSignal
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1206
	receiver:1.0
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1207
	selector:#sin
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1208
	arg:nil
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1209
	errorString:'foo bar test'
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
  1210
    "
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
  1211
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
  1212
    "Modified: / 16.11.2001 / 14:12:50 / cg"
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
  1213
!
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
  1214
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1215
raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel errorString:text
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
  1216
    "ST-80 compatible signal raising. Provided for PD numeric classes.
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
  1217
     aSignalSymbolOrErrorClass is either an Error-subclass, or
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
  1218
     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
  1219
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
  1220
    <context: #return>
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
  1221
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
  1222
    ^ self
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1223
	raise:aSignalSymbolOrErrorClass
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1224
	receiver:someNumber
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1225
	selector:sel
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1226
	arguments:#()
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1227
	errorString:text
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
  1228
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
  1229
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1230
     Number
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1231
	raise:#domainErrorSignal
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1232
	receiver:1.0
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1233
	selector:#foo
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1234
	errorString:'foo bar test'
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
  1235
    "
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
  1236
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
  1237
    "Modified: / 16.11.2001 / 14:13:16 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1238
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1239
18863
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1240
!Number class methodsFor:'misc'!
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1241
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1242
displayRadix:aNumber
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1243
    "being tired of always sending #printStringRadix: in the inspectors,
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1244
     this allows you to change the default print radix for the displayString
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1245
     method."
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1246
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1247
    DefaultDisplayRadix := aNumber
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1248
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1249
    "
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1250
     Integer displayRadix:16. 123456 inspect
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1251
     Integer displayRadix:10. 123456 inspect
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1252
    "
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1253
! !
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  1254
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  1255
!Number class methodsFor:'private'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1256
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1257
readMantissaAndScaleFrom:aStream radix:radix
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1258
    "helper for readFrom: -
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1259
     return the mantissa (post-decimal-point digits) from the (character-)stream aStream;
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1260
     in addition, the mantissa as integer and the scale (number of postDecimalPoint digits) is returned
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1261
     (both to support reading fixedPoint numbers and to not loose precision).
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1262
     The integer mantissa is needed as we do not yet know the target type (could be LongFloat or even QDouble).
22859
5475c802f68d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22844
diff changeset
  1263
     No whitespace is skipped."
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1264
24462
8018d0dcfa28 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24449
diff changeset
  1265
    |nextChar intMantissa scale digit scaleFactor value|
8018d0dcfa28 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24449
diff changeset
  1266
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1267
    scale := 0.
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1268
    scaleFactor := 1.
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1269
    intMantissa := 0.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1270
    nextChar := aStream peekOrNil.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1271
    [nextChar notNil and:[nextChar isDigitRadix:radix]] whileTrue:[
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1272
        digit := nextChar digitValue.
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1273
        scaleFactor := scaleFactor * radix.
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1274
        intMantissa := (intMantissa * radix) + digit.
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1275
        scale := scale + 1.
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1276
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1277
        aStream next.
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1278
        nextChar := aStream peekOrNil
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1279
    ].
7388
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1280
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1281
    self isAbstract ifFalse:[
24462
8018d0dcfa28 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24449
diff changeset
  1282
        value := (self coerce:intMantissa) / (self coerce:scaleFactor).
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1283
    ] ifTrue:[
24996
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  1284
        "/ Float decimalPrecision
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  1285
        "/ LongFloat decimalPrecision
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1286
        scale > 6 ifTrue:[
24996
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  1287
            "/ scale > 19 ifTrue:[
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  1288
            "/     value := intMantissa asLargeFloat / scaleFactor asLargeFloat.
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  1289
            "/ ] ifFalse:[
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  1290
                value := intMantissa asLongFloat / scaleFactor asLongFloat.
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  1291
            "/ ]
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1292
        ] ifFalse:[
24462
8018d0dcfa28 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24449
diff changeset
  1293
            value := intMantissa asFloat / scaleFactor asFloat.
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1294
        ].
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1295
    ].    
24462
8018d0dcfa28 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24449
diff changeset
  1296
    ^ (Array with:value with:intMantissa with:scale).
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1297
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1298
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1299
     Number readMantissaAndScaleFrom:'234'    readStream radix:10.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1300
     Number readMantissaAndScaleFrom:'2'      readStream radix:10.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1301
     Number readMantissaAndScaleFrom:'234567' readStream radix:10.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1302
     Number readMantissaAndScaleFrom:'234000' readStream radix:10.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1303
     Number readMantissaAndScaleFrom:'234'    readStream radix:10.
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1304
     Number readMantissaAndScaleFrom:'000234' readStream radix:10.
22844
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1305
     Number readMantissaAndScaleFrom:'01' readStream radix:10.
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1306
     Number readMantissaAndScaleFrom:'001' readStream radix:10.
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1307
     Number readMantissaAndScaleFrom:'0001' readStream radix:10.
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1308
     Number readMantissaAndScaleFrom:'000000000000000000000000000024' readStream radix:10.
22844
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1309
     Number readMantissaAndScaleFrom:'0000000000000000000000000000000000000000000024' readStream radix:10.
24996
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  1310
     Number readMantissaAndScaleFrom:'123456789012345678901234567890' readStream radix:10. 
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  1311
     Number readMantissaAndScaleFrom:'1234567890123456789012345678901234567890' readStream radix:10. 
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1312
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1313
     Number readMantissaAndScaleFrom:'12345678901234567890' readStream radix:10.
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1314
    "
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1315
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  1316
    "Modified: / 17-06-2017 / 03:03:03 / cg"
24462
8018d0dcfa28 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24449
diff changeset
  1317
    "Modified: / 22-07-2019 / 19:37:21 / Claus Gittinger"
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1318
!
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1319
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1320
readMantissaFrom:aStream radix:radix
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1321
    "helper for readFrom: -
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
  1322
     return the mantissa (post-decimal-point digits)
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
  1323
     from the (character-)stream aStream;
22859
5475c802f68d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22844
diff changeset
  1324
     No whitespace is skipped."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1325
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
  1326
    ^ (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
  1327
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
  1328
    "
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
  1329
     Number readMantissaFrom:'234'    readStream radix:10.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
  1330
     Number readMantissaFrom:'2'      readStream radix:10.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
  1331
     Number readMantissaFrom:'234567' readStream radix:10.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
  1332
    "
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
  1333
3375
7c64da3964e4 faster conversion from string (due to slow #pastEnd)
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  1334
    "Modified: / 14.4.1998 / 18:47:47 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1335
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1336
8892
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
  1337
!Number class methodsFor:'queries'!
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
  1338
24322
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1339
epsilon
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1340
    "return the maximum relative spacing of instances of mySelf
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1341
     (i.e. the value-delta of the least significant bit)"
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1342
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1343
     ^ self subclassResponsibility
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1344
!
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1345
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1346
epsilonForCloseTo
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1347
    "return the epsilon used in the closeTo: comparison.
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1348
     (useful would be something like self epsilon or epsilon*10,
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1349
      but for Squeak compatibility.... - sigh)"
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1350
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1351
    ^ 0.0001
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1352
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1353
    "
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1354
     Float epsilon
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1355
     ShortFloat epsilon
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1356
     Float epsilon10
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1357
     ShortFloat epsilon10
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1358
    "
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1359
!
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1360
8892
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
  1361
isAbstract
11224
a9a66cee404f comment
Claus Gittinger <cg@exept.de>
parents: 11136
diff changeset
  1362
    "Return if this class is an abstract class.
a9a66cee404f comment
Claus Gittinger <cg@exept.de>
parents: 11136
diff changeset
  1363
     True is returned for Number here; false for subclasses.
19457
8f56a5bde306 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19249
diff changeset
  1364
     Abstract subclasses must redefine this again."
11224
a9a66cee404f comment
Claus Gittinger <cg@exept.de>
parents: 11136
diff changeset
  1365
8892
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
  1366
    ^ self == Number
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
  1367
! !
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
  1368
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7214
diff changeset
  1369
!Number methodsFor:'Compatibility-Squeak'!
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
  1370
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
  1371
asSmallAngleDegrees
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1372
    "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
  1373
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1374
    | pos |
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
  1375
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1376
    pos := self \\ 360.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1377
    pos > 180 ifTrue: [pos := pos - 360].
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1378
    ^ pos
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
  1379
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1380
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1381
     #(-500 -300 -150 -5 0 5 150 300 500 1200)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1382
	collect: [:n | n asSmallAngleDegrees]
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1383
    "
6072
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1384
!
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
  1385
23323
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1386
sqrtWithErrorLessThan:epsilon
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1387
    "compute the square root, using the Newton method.
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1388
     The approximated return value has an error less than the given epsilon."
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1389
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1390
    ^ self sqrt_withAccuracy:epsilon
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1391
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1392
    "
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1393
     (2 asFixedPoint:4) sqrtWithErrorLessThan:0.001
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1394
    "
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1395
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1396
    "Modified: / 25-07-2017 / 15:58:46 / cg"
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1397
! !
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1398
25122
a7acd17d012a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 25086
diff changeset
  1399
23323
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1400
!Number methodsFor:'coercing & converting'!
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1401
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1402
i
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1403
    "return a complex number, with the receiver as imaginary part, 0 as real part"
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1404
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1405
    ^ Complex real:0 imaginary:self
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1406
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1407
    "
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1408
     3i     -> (0+3i)
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1409
     (1+1i) -> (1+1i)
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1410
    "
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1411
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1412
    "Modified (format): / 22-09-2017 / 09:53:27 / cg"
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1413
! !
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1414
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1415
!Number methodsFor:'comparing'!
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1416
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
  1417
closeFrom:aNumber
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
  1418
    "are these two numbers close?"
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
  1419
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1420
    ^ self closeFrom:aNumber withEpsilon:(self class epsilonForCloseTo)
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1421
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1422
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1423
     9.0 closeTo: 8.9999
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1424
     9.9 closeTo: 9
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1425
     (9/3) closeTo: 2.9999
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1426
     1 closeTo: 0.9999
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1427
     1 closeTo: 1.0001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1428
     1 closeTo: 1.001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1429
     1 closeTo: 0.999
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1430
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1431
     0.9999 closeTo: 1
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1432
     1.0001 closeTo: 1
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1433
     1.001 closeTo: 1
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1434
     0.999 closeTo: 1
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1435
     Float NaN closeTo:Float NaN
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1436
     Float infinity closeTo:Float infinity
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1437
    "
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1438
!
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1439
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1440
closeFrom:aNumber withEpsilon:eps
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1441
    "are these two numbers close?"
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1442
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
  1443
    | fuzz |
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
  1444
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1445
    self isNaN == aNumber isNaN ifFalse: [^ false].
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
  1446
    self isInfinite == aNumber isInfinite ifFalse: [^ false].
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
  1447
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1448
    fuzz := (self abs max:aNumber abs) * eps.
24494
5abd83f7fd57 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24462
diff changeset
  1449
    fuzz isFinite ifFalse:[^ false].
5abd83f7fd57 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24462
diff changeset
  1450
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
  1451
    ^ (self - aNumber) abs <= fuzz
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
  1452
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
  1453
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1454
     9.0 closeTo: 8.9999
23322
d46114c023f4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23127
diff changeset
  1455
     9.0 closeTo: 8.9999 withEpsilon:0.1
d46114c023f4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23127
diff changeset
  1456
     9.0 closeTo: 8.9999 withEpsilon:0.0001
d46114c023f4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23127
diff changeset
  1457
     9.0 closeTo: 8.9999 withEpsilon:0.00001
d46114c023f4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23127
diff changeset
  1458
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1459
     9.9 closeTo: 9
23322
d46114c023f4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23127
diff changeset
  1460
     9.9 closeTo: 9 withEpsilon:1
d46114c023f4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23127
diff changeset
  1461
     
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1462
     (9/3) closeTo: 2.9999
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1463
     1 closeTo: 0.9999
23322
d46114c023f4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23127
diff changeset
  1464
     1 closeTo: 0.9999 withEpsilon:0.0001
d46114c023f4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23127
diff changeset
  1465
     1 closeTo: 0.9999 withEpsilon:0.00001
d46114c023f4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23127
diff changeset
  1466
     
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1467
     1 closeTo: 1.0001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1468
     1 closeTo: 1.001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1469
     1 closeTo: 0.999
24494
5abd83f7fd57 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24462
diff changeset
  1470
5abd83f7fd57 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24462
diff changeset
  1471
     170 closeTo:(170 raisedTo:240)
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
  1472
    "
23322
d46114c023f4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23127
diff changeset
  1473
d46114c023f4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23127
diff changeset
  1474
    "Modified (comment): / 31-08-2018 / 12:24:39 / Claus Gittinger"
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
  1475
!
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
  1476
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  1477
closeTo:num
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1478
    "are these two numbers close to each other?"
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  1479
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1480
    ^ self closeTo:num withEpsilon:(self class epsilonForCloseTo)
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1481
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1482
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1483
     1 closeTo:1.0000000001
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1484
     1 closeTo:1.001
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1485
     1 closeTo:1.001 withEpsilon:0.001
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1486
    "
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1487
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1488
    "Created: / 5.11.2001 / 18:07:26 / cg"
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1489
!
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1490
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1491
closeTo:num withEpsilon:eps
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1492
    "are these two numbers close to each other?"
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1493
6374
fad888313ce3 closeTo: fix
Claus Gittinger <cg@exept.de>
parents: 6345
diff changeset
  1494
    num isNumber ifFalse:[^false].
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
  1495
    ^ num closeFrom:self withEpsilon:eps
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  1496
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  1497
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1498
     1 closeTo:1.0000000001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1499
     1 closeTo:1.001
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1500
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1501
     1 closeTo:1.001 withEpsilon:0.1
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1502
     1 closeTo:1.201 withEpsilon:0.1
12979
917a726bf375 comment/format in: #closeTo:withEpsilon:
Claus Gittinger <cg@exept.de>
parents: 12762
diff changeset
  1503
917a726bf375 comment/format in: #closeTo:withEpsilon:
Claus Gittinger <cg@exept.de>
parents: 12762
diff changeset
  1504
     3.14 closeTo:(3.14 asFixedPoint:2)
917a726bf375 comment/format in: #closeTo:withEpsilon:
Claus Gittinger <cg@exept.de>
parents: 12762
diff changeset
  1505
     (3.14 asFixedPoint:2) closeTo:3.14
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  1506
    "
6155
00eaf2fa55bc isReal comment
Claus Gittinger <cg@exept.de>
parents: 6154
diff changeset
  1507
12979
917a726bf375 comment/format in: #closeTo:withEpsilon:
Claus Gittinger <cg@exept.de>
parents: 12762
diff changeset
  1508
    "Created: / 05-11-2001 / 18:07:26 / cg"
917a726bf375 comment/format in: #closeTo:withEpsilon:
Claus Gittinger <cg@exept.de>
parents: 12762
diff changeset
  1509
    "Modified: / 02-08-2010 / 13:27:22 / cg"
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  1510
!
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  1511
24322
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1512
epsilonForCloseTo
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1513
    "return the epsilon used in the closeTo: comparison."
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1514
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1515
    ^ self class epsilonForCloseTo
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1516
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1517
    "
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1518
     1.0 epsilon
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1519
     10 asShortFloat epsilon
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1520
    "
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1521
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1522
    "Created: / 10-06-2019 / 21:20:18 / Claus Gittinger"
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1523
!
b70e88c857b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24262
diff changeset
  1524
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1525
isAlmostEqualTo:aNumber nEpsilon:nE
16656
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1526
    "return true, if the argument, aNumber represents almost the same numeric value
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1527
     as the receiver, false otherwise.
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1528
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1529
     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
  1530
     still be considered equal. See documentation in LimitedPrecisionReal for more detail.
16656
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1531
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1532
     For background information why floats need this
16656
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1533
     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
  1534
    "
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1535
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1536
    |f1 f2 diff scaledEpsilon largest|
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1537
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1538
    diff := (self - aNumber) abs.
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1539
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1540
    scaledEpsilon := nE * diff class epsilon.
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1541
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1542
    diff <= scaledEpsilon ifTrue:[
21812
4d60b6626208 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21789
diff changeset
  1543
        "compare for really close values near 0"
4d60b6626208 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21789
diff changeset
  1544
        ^ true.
16656
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1545
    ].
21812
4d60b6626208 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21789
diff changeset
  1546
4d60b6626208 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21789
diff changeset
  1547
    "scaled comparison for larger values"
4d60b6626208 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21789
diff changeset
  1548
    f1 := self abs.
4d60b6626208 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21789
diff changeset
  1549
    f2 := aNumber abs.
4d60b6626208 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21789
diff changeset
  1550
    largest := f1 > f2 ifTrue:[f1] ifFalse:[f2].
4d60b6626208 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21789
diff changeset
  1551
    ^ (diff <= (scaledEpsilon * largest)).
4d60b6626208 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21789
diff changeset
  1552
4d60b6626208 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21789
diff changeset
  1553
    "Modified: / 15-06-2017 / 09:55:15 / cg"
22290
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1554
!
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1555
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1556
isAlmostEqualTo:aNumber withError:errFraction
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1557
    "return true, if the receiver,is inside the interval aNumber-err .. aNumber+err.
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1558
     Err is a fraction of 0..1."
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1559
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1560
    ^ self between:(aNumber * (1-errFraction)) and:(aNumber * (1+errFraction))
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1561
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1562
    "
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1563
     within 10%?
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1564
     10.5 isAlmostEqualTo:10 withError:0.1
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1565
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1566
     within 1%
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1567
     10.5 isAlmostEqualTo:10 withError:0.01
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1568
    "
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1569
148ed9bf22cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22287
diff changeset
  1570
    "Created: / 23-09-2017 / 16:33:26 / cg"
23323
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1571
!
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1572
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1573
isEqual: aNumber within: accuracy
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  1574
	^(self - aNumber) abs < accuracy
16656
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1575
! !
9d93ee3916f6 class: Number
Stefan Vogel <sv@exept.de>
parents: 16630
diff changeset
  1576
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1577
!Number methodsFor:'converting'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1578
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1579
% aNumber
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1580
    "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
  1581
     aNumber as the imaginary part"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1582
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1583
    ^ Complex real:self imaginary:aNumber
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1584
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1585
    "Modified: / 9.7.1998 / 10:18:12 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1586
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1587
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1588
+/- anError
14009
a2b68a9c9719 comment
Claus Gittinger <cg@exept.de>
parents: 13898
diff changeset
  1589
    "return a MeasurementValue with a given error."
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1590
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1591
    ^ MeasurementValue value:self minValue:(self-anError) maxValue:(self+anError)
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1592
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1593
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1594
     (100 +/- 5) * 2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1595
     (100 +/- 5) * (100 +/- 10)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1596
     (100 +/- 5) + (100 +/- 10)
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1597
     (100 +/- 5) - (100 +/- 10)
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1598
    "
14009
a2b68a9c9719 comment
Claus Gittinger <cg@exept.de>
parents: 13898
diff changeset
  1599
a2b68a9c9719 comment
Claus Gittinger <cg@exept.de>
parents: 13898
diff changeset
  1600
    "Modified (comment): / 14-02-2012 / 14:17:36 / cg"
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1601
!
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1602
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1603
@ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1604
    "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
  1605
     as y-coordinate"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1606
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1607
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1608
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1609
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1610
     * I cannot tell if this special code is worth anything
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1611
     */
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
  1612
    if (__CanDoQuickNew(sizeof(struct __Point))) {      /* OBJECT ALLOCATION */
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1613
	OBJ newPoint;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1614
	int spc;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1615
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1616
	__qCheckedNew(newPoint, sizeof(struct __Point));
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1617
	__InstPtr(newPoint)->o_class = @global(Point);
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1618
	__qSTORE(newPoint, @global(Point));
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1619
	__PointInstPtr(newPoint)->p_x = self;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1620
	__PointInstPtr(newPoint)->p_y = aNumber;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1621
	if (! __bothSmallInteger(self, aNumber)) {
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1622
	    spc = __qSpace(newPoint);
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1623
	    __STORE_SPC(newPoint, aNumber, spc);
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1624
	    __STORE_SPC(newPoint, self, spc);
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1625
	}
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1626
	RETURN ( newPoint );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1627
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1628
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1629
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1630
    ^ Point x:self y:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1631
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1632
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1633
asComplex
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1634
    "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
  1635
     zero as the imaginary part"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1636
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  1637
    ^ Complex real:self
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1638
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1639
    "Modified: / 9.7.1998 / 10:18:16 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1640
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1641
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1642
asMetaNumber
21894
194db181170d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21888
diff changeset
  1643
    self isNaN ifTrue:[
194db181170d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21888
diff changeset
  1644
        ^ NotANumber NaN
194db181170d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21888
diff changeset
  1645
    ].    
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1646
    ^ SomeNumber new realNumber:self
21894
194db181170d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21888
diff changeset
  1647
194db181170d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21888
diff changeset
  1648
    "
194db181170d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21888
diff changeset
  1649
     Float NaN asMetaNumber
194db181170d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21888
diff changeset
  1650
     Float infinity asMetaNumber
194db181170d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21888
diff changeset
  1651
     Float negativeInfinity asMetaNumber
194db181170d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21888
diff changeset
  1652
    "
194db181170d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21888
diff changeset
  1653
194db181170d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21888
diff changeset
  1654
    "Modified (comment): / 21-06-2017 / 20:47:59 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1655
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1656
7214
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
  1657
asNumber
17060
7b39761eb1ce class: Number
Claus Gittinger <cg@exept.de>
parents: 17058
diff changeset
  1658
    "I am a number, so return myself"
7214
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
  1659
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
  1660
    ^ self.
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
  1661
!
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
  1662
19702
79ea925e1f35 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19701
diff changeset
  1663
asPercentFrom:fullAmount
79ea925e1f35 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19701
diff changeset
  1664
    "what is the percentage
79ea925e1f35 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19701
diff changeset
  1665
     taking the receiver's value from the argument"
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1666
19702
79ea925e1f35 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19701
diff changeset
  1667
    ^ (self / fullAmount) * 100.
19701
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1668
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1669
    "
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1670
     20 asPercentFrom:100
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1671
     (10 asPercentFrom:156) asFixedPoint:2
19702
79ea925e1f35 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19701
diff changeset
  1672
     (15.6 asPercentFrom:156) asFixedPoint:2
19701
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1673
    "
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1674
!
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1675
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1676
asPoint
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1677
    "return a new Point with the receiver as all coordinates;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1678
     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
  1679
     symmetrical gridding or scaling."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1680
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1681
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1682
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
  1683
    if (__CanDoQuickNew(sizeof(struct __Point))) {      /* OBJECT ALLOCATION */
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1684
	OBJ newPoint;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1685
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1686
	__qCheckedNew(newPoint, sizeof(struct __Point));
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1687
	__InstPtr(newPoint)->o_class = @global(Point);
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1688
	__qSTORE(newPoint, @global(Point));
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1689
	__PointInstPtr(newPoint)->p_x = self;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1690
	__PointInstPtr(newPoint)->p_y = self;
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1691
	__STORE(newPoint, self);
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1692
	RETURN ( newPoint );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1693
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1694
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1695
    ^ Point x:self y:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1696
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1697
13898
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1698
asTimeDuration
23619
90c9530305b7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23615
diff changeset
  1699
    "return an TimeDuration object from the receiver, 
90c9530305b7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23615
diff changeset
  1700
     taking the receiver as number of seconds"
13898
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1701
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1702
    ^ TimeDuration seconds:self
13898
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1703
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1704
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1705
     5 asTimeDuration
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1706
     50.25 asTimeDuration
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1707
     3600 asTimeDuration
23619
90c9530305b7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23615
diff changeset
  1708
     '5m' asTimeDuration
13898
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1709
    "
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1710
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1711
    "Created: / 08-01-2012 / 19:04:04 / cg"
23619
90c9530305b7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23615
diff changeset
  1712
    "Modified (comment): / 21-01-2019 / 10:31:15 / Claus Gittinger"
13898
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1713
!
42fd67913187 added: #asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 13631
diff changeset
  1714
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1715
degreesToRadians
21105
f51ebd03d20b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20866
diff changeset
  1716
    "interpreting the receiver as degrees, return the radians"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1717
8203
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  1718
    ^ 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
  1719
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1720
    "
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1721
     180 degreesToRadians
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1722
     Float pi radiansToDegrees
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1723
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1724
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1725
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1726
literalArrayEncoding
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
  1727
    "encode myself as an array literal, from which a copy of the receiver
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
  1728
     can be reconstructed with #decodeAsLiteralArray."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1729
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1730
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1731
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1732
    "Modified: 1.9.1995 / 02:25:26 / claus"
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
  1733
    "Modified: 22.4.1996 / 13:00:27 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1734
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1735
19701
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1736
percentOf:hundredPercent
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1737
    "how many is self-percent from the argument"
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1738
19701
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1739
    ^ (hundredPercent / 100 * self)
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1740
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1741
    "
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1742
     20 percentOf:100
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1743
     (10 percentOf:156) asFixedPoint:2
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1744
     (105 percentOf:156) asFixedPoint:2
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1745
    "
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1746
!
92aff12989fa #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19457
diff changeset
  1747
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1748
radiansToDegrees
21105
f51ebd03d20b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20866
diff changeset
  1749
    "interpreting the receiver as radians, return the degrees"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1750
8203
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  1751
    ^ 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
  1752
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1753
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1754
     180 degreesToRadians
7388
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1755
     Float pi radiansToDegrees
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  1756
    "
6637
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1757
!
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1758
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1759
withScale:newScale
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1760
    "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
  1761
     with newScale number of post-decimal digits"
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1762
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1763
    ^ self asFixedPoint:newScale
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1764
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1765
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1766
     1234 withScale:2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1767
     1234.1 withScale:2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1768
     1234.12 withScale:2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1769
     1234.123 withScale:2
6637
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1770
     (1/7) withScale:2
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
  1771
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1772
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1773
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1774
!Number methodsFor:'converting-times'!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1775
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1776
days
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1777
    "return a TimeDuration representing this number of days"
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1778
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1779
    ^ TimeDuration days:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1780
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1781
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1782
     1000 milliseconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1783
     10 seconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1784
     10 minutes
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1785
     1 days
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1786
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1787
!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1788
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1789
hours
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1790
    "return a TimeDuration representing this number of hours"
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1791
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1792
    ^ TimeDuration hours:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1793
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1794
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1795
     1000 milliseconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1796
     10 seconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1797
     10 minutes
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1798
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1799
!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1800
22844
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1801
microseconds
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1802
    "return a TimeDuration representing this number of microseconds."
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1803
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1804
    ^ TimeDuration fromMicroseconds:self
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1805
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1806
    "
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1807
     40 microseconds
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1808
    "
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1809
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1810
    "Modified (comment): / 21-09-2017 / 17:37:18 / cg"
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1811
!
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1812
22279
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1813
milliSeconds
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1814
    "return a TimeDuration representing this number of milliseconds
24431
47ab366e910f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24395
diff changeset
  1815
     Same as milliseconds, for dialect compatibility"
22279
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1816
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1817
    ^ TimeDuration fromMilliseconds:self
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1818
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1819
    "
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1820
     1000 milliSeconds
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1821
    "
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1822
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1823
    "Created: / 21-09-2017 / 17:26:32 / cg"
24431
47ab366e910f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24395
diff changeset
  1824
    "Modified (comment): / 18-07-2019 / 21:33:09 / Claus Gittinger"
22279
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1825
!
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1826
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1827
milliseconds
22279
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1828
    "return a TimeDuration representing this number of milliseconds.
24431
47ab366e910f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24395
diff changeset
  1829
     Same as milliSeconds, for dialect compatibility"
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1830
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1831
    ^ TimeDuration fromMilliseconds:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1832
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1833
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1834
     1000 milliseconds
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1835
    "
22279
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1836
3b4d8c69aa0d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22143
diff changeset
  1837
    "Modified (comment): / 21-09-2017 / 17:37:18 / cg"
24431
47ab366e910f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24395
diff changeset
  1838
    "Modified (comment): / 18-07-2019 / 21:33:12 / Claus Gittinger"
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1839
!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1840
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1841
minutes
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1842
    "return a TimeDuration representing this number of minutes"
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1843
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1844
    ^ TimeDuration minutes:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1845
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1846
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1847
     1000 milliseconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1848
     10 seconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1849
     10 minutes
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1850
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1851
!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1852
22844
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1853
nanoseconds
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1854
    "return a TimeDuration representing this number of nanoseconds."
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1855
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1856
    ^ TimeDuration fromNanoseconds:self
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1857
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1858
    "
22869
3580953da3de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22859
diff changeset
  1859
     40.5 nanoseconds asPicoseconds
3580953da3de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22859
diff changeset
  1860
     (40.5 nanoseconds / 2) asPicoseconds
3580953da3de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22859
diff changeset
  1861
22844
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1862
     40 nanoseconds
22869
3580953da3de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22859
diff changeset
  1863
     40 nanoseconds asPicoseconds
3580953da3de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22859
diff changeset
  1864
     44 milliseconds asMicroseconds
3580953da3de #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22859
diff changeset
  1865
     44 milliseconds 
22844
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1866
    "
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1867
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1868
    "Modified (comment): / 21-09-2017 / 17:37:18 / cg"
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1869
!
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1870
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1871
picoseconds
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1872
    "return a TimeDuration representing this number of picoseconds."
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1873
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1874
    ^ TimeDuration fromPicoseconds:self
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1875
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1876
    "
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1877
     40 picoseconds
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1878
    "
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1879
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1880
    "Modified (comment): / 21-09-2017 / 17:37:18 / cg"
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1881
!
46b2a5dfdfc6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22730
diff changeset
  1882
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1883
seconds
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1884
    "return a TimeDuration representing this number of seconds"
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1885
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1886
    ^ TimeDuration seconds:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1887
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1888
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1889
     1000 milliseconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1890
     10 seconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1891
     10 minutes
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1892
    "
13631
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1893
!
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1894
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1895
weeks
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1896
    "return a TimeDuration representing this number of weeks"
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1897
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1898
    ^ TimeDuration weeks:self
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1899
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1900
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1901
     1000 milliseconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1902
     10 seconds
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1903
     10 minutes
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1904
     1 days
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1905
     1 weeks
13631
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1906
    "
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1907
82875f651ca6 added: #weeks
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1908
    "Created: / 05-09-2011 / 11:17:59 / cg"
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1909
! !
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1910
16406
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1911
!Number methodsFor:'double dispatching'!
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1912
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1913
differenceFromTimestamp:aTimestamp
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1914
    "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
  1915
     before aTimestamp"
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1916
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1917
    ^ aTimestamp subtractMilliseconds:(self * 1000) truncated.
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1918
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1919
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1920
     100.0 differenceFromTimestamp:Timestamp now
16406
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1921
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1922
     |t1 t2|
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1923
     t1 := Timestamp now.
16406
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1924
     t2 := 1.5 differenceFromTimestamp:t1.
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1925
     t1 inspect. t2 inspect.
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1926
    "
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1927
! !
967b6c76169a class: Number
Stefan Vogel <sv@exept.de>
parents: 16267
diff changeset
  1928
24237
c68e7d2efaf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24158
diff changeset
  1929
!Number methodsFor:'inspecting'!
c68e7d2efaf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24158
diff changeset
  1930
c68e7d2efaf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24158
diff changeset
  1931
inspectorValueStringInListFor:anInspector
c68e7d2efaf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24158
diff changeset
  1932
    "returns a string to be shown in the inspector's list"
c68e7d2efaf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24158
diff changeset
  1933
c68e7d2efaf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24158
diff changeset
  1934
    ^ self printString contractTo:30
c68e7d2efaf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24158
diff changeset
  1935
c68e7d2efaf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24158
diff changeset
  1936
    "Created: / 29-05-2019 / 15:01:19 / Claus Gittinger"
c68e7d2efaf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24158
diff changeset
  1937
! !
23615
3faa6422e9b7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23481
diff changeset
  1938
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1939
!Number methodsFor:'intervals'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1940
6072
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1941
downTo:stop
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1942
    "return an interval from receiver down to the argument, incrementing by -1"
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1943
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1944
    ^ self to:stop by:-1
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1945
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1946
    "
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1947
     (10 downTo:1) do:[:i | Transcript showCR:i].
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1948
    "
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1949
!
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1950
15595
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1951
downTo:stop by:step
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1952
    "return an interval from receiver down to the argument, decrementing by step"
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1953
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1954
    ^ self to:stop by:step negated
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1955
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1956
    "
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1957
     (10 downTo:1 by:0.5) do:[:i | Transcript showCR:i].
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1958
    "
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1959
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1960
    "Created: / 01-08-2013 / 14:36:56 / cg"
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1961
!
fa5010435cda class: Number
Claus Gittinger <cg@exept.de>
parents: 15197
diff changeset
  1962
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1963
to:stop
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1964
    "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
  1965
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1966
    ^ Interval from:self to:stop
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1967
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1968
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1969
to:stop by:step
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1970
    "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
  1971
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1972
    ^ Interval from:self to:stop by:step
6154
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1973
!
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1974
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1975
to:stop byFactor:factor
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1976
    "return a geometric series from receiver up to the argument;
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1977
     elements have a constant factor in between"
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1978
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1979
    ^ GeometricSeries from:self to:stop byFactor:factor
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1980
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1981
    "
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1982
     (1 to:256 byFactor:2)
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1983
     (256 to:1 byFactor:1/2)
6154
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1984
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1985
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1986
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1987
!Number methodsFor:'iteration'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1988
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1989
timesRepeat:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1990
    "evaluate the argument, aBlock self times"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1991
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1992
    |count|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1993
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1994
    count := self.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1995
    [count > 0] whileTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1996
	aBlock value.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  1997
	count := count - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1998
    ]
24394
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  1999
!
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2000
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2001
timesRepeatWithExit:aOneArgBlock
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2002
    "evaluate the argument, aBlock self times;
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2003
     pass an exit block to the one-arg-block"
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2004
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2005
    |count exit|
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2006
24395
c245e7c02c2d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24394
diff changeset
  2007
    exit := [:values | ^ values firstIfEmpty:nil] asVarArgBlock.
24394
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2008
    count := self.
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2009
    [count > 0] whileTrue:[
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2010
        aOneArgBlock value:exit.
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2011
        count := count - 1
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2012
    ]
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2013
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2014
    "
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2015
    10 timesRepeatWithExit:[:exit |
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2016
        Transcript showCR:'iteration'.
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2017
        (Random nextBetween:1 and:10) > 7 ifTrue:[exit value].
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2018
    ].
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2019
    "
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2020
f98a6987c41a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24322
diff changeset
  2021
    "Created: / 28-06-2019 / 12:01:24 / Claus Gittinger"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2022
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2023
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2024
!Number methodsFor:'mathematical functions'!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2025
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2026
agm:y
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2027
    "return the arithmetic-geometric mean agm(x, y) of the receiver (x) and the argument, y.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2028
     See https://en.wikipedia.org/wiki/Arithmetic-geometric_mean
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2029
     and http://www.wolframalpha.com/input/?i=agm(24,+6)"
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2030
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2031
    |ai an gi gn epsilon delta|
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2032
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2033
    ai := (self + y) / 2.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2034
    gi := (self * y) sqrt.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2035
    epsilon := self epsilon.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2036
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2037
    [
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2038
        an := (ai + gi) / 2.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2039
        gn := (ai * gi) sqrt.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2040
        delta := (an - ai) abs.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2041
        ai := an.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2042
        gi := gn.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2043
    ] doUntil:[ delta < epsilon ].
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2044
    ^ ai
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2045
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2046
    "
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2047
     24 agm:6
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2048
    "
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2049
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2050
    "Created: / 03-07-2017 / 12:05:00 / cg"
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2051
!
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2052
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2053
cbrt
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2054
    "return the cubic root of the receiver"
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2055
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  2056
    "/ if I am not a Float (or a less general lpReal),
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  2057
    "/ retry after converting to float
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2058
    (self isLimitedPrecisionReal not
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2059
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2060
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2061
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2062
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2063
            ^ f cbrt.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2064
        ].
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2065
    ].
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  2066
    "/ very slow fallback
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2067
    ^ self cbrt_withAccuracy:self epsilon
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2068
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2069
    "Modified: / 05-07-2017 / 17:23:27 / cg"
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2070
!
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2071
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2072
conjugated
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2073
    "Return the complex conjugate of this Number."
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2074
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2075
    ^ self
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2076
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2077
    "Modified: / 9.7.1998 / 10:17:31 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2078
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2079
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2080
exp
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2081
    "compute e**x of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2082
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  2083
    "/ if I am not a Float (or a less general lpReal),
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  2084
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2085
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2086
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2087
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2088
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2089
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2090
            ^ f exp.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2091
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2092
    ].
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  2093
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2094
    ^ self exp_withAccuracy:self epsilon
21915
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  2095
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2096
    "Modified: / 05-07-2017 / 17:23:36 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2097
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2098
24934
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  2099
fibPhi
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  2100
    ^ (1 / 5 sqrt) * ((self class phi raisedTo:self) - ((-1 / self class phi) raisedTo:self))
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  2101
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  2102
    "
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  2103
     3 fib      
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  2104
     3.0 fibPhi   
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  2105
     100 fib     
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  2106
     100.0 fibPhi  
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  2107
    "
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  2108
!
27110d4e4a5e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24896
diff changeset
  2109
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2110
floorLog:radix
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2111
    "return the logarithm truncated as an integer"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2112
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2113
    ^ (self log:radix) floor
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2114
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2115
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2116
imaginary
23046
d566cd96c3e3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22869
diff changeset
  2117
    "Return the imaginary part of a complex number.
d566cd96c3e3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22869
diff changeset
  2118
     For non-complex numbers, zero is returned."
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2119
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2120
    ^ 0
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2121
23046
d566cd96c3e3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22869
diff changeset
  2122
    "Modified: / 09-07-1998 / 10:17:24 / cg"
d566cd96c3e3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22869
diff changeset
  2123
    "Modified (comment): / 01-06-2018 / 13:09:09 / Claus Gittinger"
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2124
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2125
21833
5276dd24e7c0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21828
diff changeset
  2126
ldexp:exp
5276dd24e7c0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21828
diff changeset
  2127
    "multiply the receiver by an integral power of 2.
24971
8f4585ee27f8 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24959
diff changeset
  2128
     I.e. return self * (2 ^ exp).
8f4585ee27f8 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24959
diff changeset
  2129
     This is also the operation to reconstruct the original float from its
8f4585ee27f8 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24959
diff changeset
  2130
     mantissa and exponent: (f mantissa ldexp:f exponent) = f"
21833
5276dd24e7c0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21828
diff changeset
  2131
5276dd24e7c0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21828
diff changeset
  2132
    ^ self * (2 raisedTo:exp)
5276dd24e7c0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21828
diff changeset
  2133
24959
aca1c02bc14a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24950
diff changeset
  2134
    "
aca1c02bc14a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24950
diff changeset
  2135
     1.0 ldexp:16  -> 65536.0
aca1c02bc14a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24950
diff changeset
  2136
     1.0 ldexp:100 -> 1.26765060022823E+30
aca1c02bc14a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24950
diff changeset
  2137
     1 * (2 raisedToInteger:100) -> 1267650600228229401496703205376
aca1c02bc14a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24950
diff changeset
  2138
     1 ldexp:200   -> 1606938044258990275541962092341162602522202993782792835301376
aca1c02bc14a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24950
diff changeset
  2139
     1.0 ldexp:200 -> 1.60693804425899E+60
aca1c02bc14a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24950
diff changeset
  2140
    "
aca1c02bc14a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24950
diff changeset
  2141
21833
5276dd24e7c0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21828
diff changeset
  2142
    "Created: / 19-06-2017 / 01:43:35 / cg"
5276dd24e7c0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21828
diff changeset
  2143
!
5276dd24e7c0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21828
diff changeset
  2144
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2145
ln
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2146
    "return the natural logarithm of myself.
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2147
     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
  2148
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  2149
    "/ if I am not a Float (or a less general lpReal),
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  2150
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2151
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2152
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2153
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2154
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2155
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2156
            ^ f ln.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2157
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2158
    ].
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  2159
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2160
    ^ self ln_withAccuracy:self epsilon
19249
Stefan Vogel <sv@exept.de>
parents: 19141
diff changeset
  2161
Stefan Vogel <sv@exept.de>
parents: 19141
diff changeset
  2162
    "
21833
5276dd24e7c0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21828
diff changeset
  2163
     (10 raisedTo:1000) ln
19249
Stefan Vogel <sv@exept.de>
parents: 19141
diff changeset
  2164
    "
21833
5276dd24e7c0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21828
diff changeset
  2165
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2166
    "Modified: / 05-07-2017 / 17:23:50 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2167
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2168
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2169
log
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2170
    "return log base 10 of the receiver.
12584
d32f98e9b219 comment/format in: #log
Claus Gittinger <cg@exept.de>
parents: 12112
diff changeset
  2171
     Alias for log:10."
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2172
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2173
    ^ self log10
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2174
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2175
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2176
log10
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  2177
    "return log base-10 of the receiver.
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  2178
     Raises an exception, if the receiver is less or equal to zero.
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  2179
     Here, fallback to the general logarithm code."
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2180
10550
0f2a07595d1c Fix bug 641: changed #log10 to be more accurate
Stefan Vogel <sv@exept.de>
parents: 10325
diff changeset
  2181
    (self isLimitedPrecisionReal not
0f2a07595d1c Fix bug 641: changed #log10 to be more accurate
Stefan Vogel <sv@exept.de>
parents: 10325
diff changeset
  2182
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2183
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2184
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2185
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2186
            ^ f log10.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2187
        ].
10550
0f2a07595d1c Fix bug 641: changed #log10 to be more accurate
Stefan Vogel <sv@exept.de>
parents: 10325
diff changeset
  2188
    ].
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  2189
    ^ self ln / self class ln10
19249
Stefan Vogel <sv@exept.de>
parents: 19141
diff changeset
  2190
Stefan Vogel <sv@exept.de>
parents: 19141
diff changeset
  2191
    "
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  2192
     (10 raisedTo:1000) log10
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  2193
     (10 raisedTo:2000) log10
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  2194
     (10 raisedTo:4000) log10
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  2195
     (10 raisedTo:8000) log10
19249
Stefan Vogel <sv@exept.de>
parents: 19141
diff changeset
  2196
    "
21828
d1a7e7c21694 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21815
diff changeset
  2197
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2198
    "Modified: / 05-07-2017 / 17:23:06 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2199
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2200
24950
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2201
log2
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2202
    "return log base-2 of the receiver.
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2203
     Raises an exception, if the receiver is less or equal to zero.
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2204
     Here, fallback to the general logarithm code."
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2205
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2206
    (self isLimitedPrecisionReal not
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2207
    or:[self generality < 1.0 generality]) ifTrue:[
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2208
        |f|
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2209
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2210
        (f := self asLongFloat) isFinite ifTrue:[
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2211
            ^ f log2.
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2212
        ].
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2213
    ].
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2214
    ^ self ln / self class ln2
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2215
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2216
    "
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2217
     2.0 log2  
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2218
     4.0 log2  
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2219
     (2.0 raisedTo:100.0) log2  
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2220
     (10 raisedTo:1000) log2
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2221
     (10 raisedTo:2000) log2
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2222
     (10 raisedTo:4000) log2
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2223
     (10 raisedTo:8000) log2
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2224
    "
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2225
!
b05cc09c455e #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24938
diff changeset
  2226
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2227
log:aNumber
18850
172da07a4529 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18320
diff changeset
  2228
    "return log base aNumber of the receiver.
172da07a4529 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18320
diff changeset
  2229
     This will usually return a float value"
7449
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
    ^ self ln / aNumber ln
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2232
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2233
    "
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2234
      1000 log:10
19049
7ab1aa4ef01e #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19041
diff changeset
  2235
      9 log:3
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2236
      (1000 log:10) floor
19249
Stefan Vogel <sv@exept.de>
parents: 19141
diff changeset
  2237
      (10 raisedTo:1000) log:10
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2238
    "
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2239
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2240
22098
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2241
nthRoot:n
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2242
    "return the nth root of the receiver"
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2243
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2244
    n == 2 ifTrue:[^ self sqrt ].
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2245
    n == 3 ifTrue:[^ self cbrt ].
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2246
    "/ slow fallback
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2247
    ^ self nthRoot:n withAccuracy:self epsilon
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2248
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2249
    "
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2250
     10 nthRoot:2 -> 3.16227766016838
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2251
     10 nthRoot:3 -> 2.154434690031883722
22287
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  2252
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  2253
     100.0 nthRoot:4 
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  2254
     100.0 nthRoot:5
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  2255
     (100.0 nthRoot:6) raisedTo:6
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  2256
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  2257
     16.0 nthRoot:2
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  2258
     -16.0 nthRoot:3
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  2259
     -16.0 nthRoot:5
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  2260
     
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  2261
     -16.0 nthRoot:4
22098
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2262
    "
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2263
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2264
    "Created: / 25-07-2017 / 16:15:11 / cg"
22287
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  2265
    "Modified (comment): / 22-09-2017 / 10:15:33 / cg"
22098
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2266
!
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  2267
7468
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  2268
raisedTo:aNumber
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  2269
    "return the receiver raised to aNumber"
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  2270
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  2271
    aNumber = 0 ifTrue:[^ 1].
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  2272
    aNumber = 1 ifTrue:[^ self].
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  2273
    aNumber isInteger ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2274
	^ self raisedToInteger:aNumber
7468
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  2275
    ].
19018
441811c95c15 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18863
diff changeset
  2276
    aNumber isNumber ifFalse:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2277
	^ aNumber raisedFromNumber:self.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2278
    ].
7468
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  2279
    ^ self asFloat raisedTo:aNumber
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  2280
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  2281
    "
19092
4a5b5b1e6f36 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19049
diff changeset
  2282
     2 raisedTo: 4
4a5b5b1e6f36 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19049
diff changeset
  2283
     -2 raisedTo: 4
4a5b5b1e6f36 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19049
diff changeset
  2284
     4 raisedTo: 1/2
4a5b5b1e6f36 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19049
diff changeset
  2285
     -4 raisedTo: 1/2
4a5b5b1e6f36 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19049
diff changeset
  2286
     8 raisedTo: 1/3
4a5b5b1e6f36 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19049
diff changeset
  2287
     -8 raisedTo: 1/3
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2288
     10 raisedTo: 4
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2289
     10 raisedTo: -4
7468
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  2290
    "
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  2291
!
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  2292
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2293
real
23046
d566cd96c3e3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22869
diff changeset
  2294
    "Return the real part of a complex number.
d566cd96c3e3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22869
diff changeset
  2295
     For non-complex numbers, the receiver is returned."
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2296
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2297
    ^ self
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2298
23046
d566cd96c3e3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22869
diff changeset
  2299
    "Modified: / 09-07-1998 / 10:17:17 / cg"
d566cd96c3e3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22869
diff changeset
  2300
    "Modified (comment): / 01-06-2018 / 13:09:33 / Claus Gittinger"
6258
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  2301
!
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  2302
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2303
sqrt
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2304
    "return the square root of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2305
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  2306
    "/ if I am not a Float (or a less general lpReal),
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  2307
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2308
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2309
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2310
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2311
22115
7781da9ddc6e #DOCUMENTATION by mawalch
mawalch
parents: 22106
diff changeset
  2312
        "/ do not make this a LongFloat;
22119
073225d994bf #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22115
diff changeset
  2313
        "/ it will return a LongFloat then, and Image rotated will fail then...
21992
f46021127b61 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21988
diff changeset
  2314
        (f := self asFloat) isFinite ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2315
            ^ f sqrt.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2316
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2317
    ].
19770
024784e1852b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19769
diff changeset
  2318
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2319
    ^ self sqrt_withAccuracy:self epsilon
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  2320
21992
f46021127b61 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21988
diff changeset
  2321
    "Modified (format): / 11-07-2017 / 13:32:02 / cg"
22115
7781da9ddc6e #DOCUMENTATION by mawalch
mawalch
parents: 22106
diff changeset
  2322
    "Modified (format): / 26-07-2017 / 12:30:16 / mawalch"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2323
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2324
6258
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  2325
timesTwoPower:anInteger
12762
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  2326
    "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
  2327
     For protocol completeness wrt. Squeak and ST80."
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  2328
12762
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  2329
    anInteger >= 0 ifTrue:[
24157
c75b75fd3aaf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23619
diff changeset
  2330
        ^ self * (1 bitShift:anInteger)
12762
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  2331
    ].
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  2332
    ^ self / (1 bitShift:anInteger negated)
6258
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  2333
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  2334
    "
24157
c75b75fd3aaf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23619
diff changeset
  2335
     123 timesTwoPower:0  = 123*1 -> 123
c75b75fd3aaf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23619
diff changeset
  2336
     123 timesTwoPower:1  = 123*2 -> 246
c75b75fd3aaf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23619
diff changeset
  2337
     123 timesTwoPower:2  = 123*4 -> 492
c75b75fd3aaf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23619
diff changeset
  2338
     123 timesTwoPower:3  = 123*8 -> 984
12762
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  2339
a41a496d8c61 changed: #timesTwoPower:
Claus Gittinger <cg@exept.de>
parents: 12759
diff changeset
  2340
     (2 timesTwoPower: -150) timesTwoPower: 150  -> 2
24157
c75b75fd3aaf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23619
diff changeset
  2341
     (2 timesTwoPower: 150) timesTwoPower: -150  -> 2
c75b75fd3aaf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23619
diff changeset
  2342
     (2 timesTwoPower: 150) timesTwoPower: -149  -> 4  
6258
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  2343
    "
24157
c75b75fd3aaf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23619
diff changeset
  2344
c75b75fd3aaf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23619
diff changeset
  2345
    "Modified (comment): / 26-05-2019 / 03:26:09 / Claus Gittinger"
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2346
! !
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  2347
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  2348
!Number methodsFor:'measurement values'!
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  2349
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  2350
maxValue
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2351
    "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
  2352
     as I am exact, that's myself"
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  2353
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  2354
    ^ self
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  2355
!
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  2356
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  2357
minValue
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2358
    "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
  2359
     as I am exact, that's myself"
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  2360
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  2361
    ^ self
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  2362
! !
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  2363
25085
8bcc521a9e18 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25051
diff changeset
  2364
8bcc521a9e18 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25051
diff changeset
  2365
8bcc521a9e18 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25051
diff changeset
  2366
8bcc521a9e18 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25051
diff changeset
  2367
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2368
!Number methodsFor:'printing & storing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2369
18863
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2370
displayOn:aGCOrStream
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2371
    "return a string to display the receiver.
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2372
     The output radix is usually 10, but can be changed by setting
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2373
     DefaultDisplayRadix (see Integer>>displayRadix:)"
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2374
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2375
    "/ what a kludge - Dolphin and Squeak mean: printOn: a stream;
21536
c71b535bfcbb #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21142
diff changeset
  2376
    "/ old ST80 means: draw-yourself on a GC.
18863
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2377
    (aGCOrStream isStream) ifFalse:[
21536
c71b535bfcbb #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21142
diff changeset
  2378
        ^ super displayOn:aGCOrStream
18863
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2379
    ].
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2380
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2381
    (DefaultDisplayRadix isNil or:[DefaultDisplayRadix == 10]) ifTrue:[
21536
c71b535bfcbb #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21142
diff changeset
  2382
        self printOn:aGCOrStream
18863
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2383
    ] ifFalse:[
21536
c71b535bfcbb #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21142
diff changeset
  2384
        self printOn:aGCOrStream base:DefaultDisplayRadix showRadix:true.
18863
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2385
    ].
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2386
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2387
    "
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2388
     Integer displayRadix:16. 12345
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2389
     Integer displayRadix:2.  12345
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2390
     Integer displayRadix:10. 12345
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2391
    "
21536
c71b535bfcbb #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21142
diff changeset
  2392
c71b535bfcbb #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21142
diff changeset
  2393
    "Modified (comment): / 22-02-2017 / 16:52:16 / cg"
18863
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2394
!
0fe8c5ecd2fd #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18862
diff changeset
  2395
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2396
printOn:aStream
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2397
    "append a printed description of the receiver to aStream"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2398
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2399
    self printOn:aStream base:10
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2400
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2401
    "Modified: / 20.1.1998 / 14:10:45 / stefan"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2402
!
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2403
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2404
printOn:aStream base:b
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2405
    "return a string representation of the receiver in the specified
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2406
     radix (without the initial XXr)"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2407
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2408
    ^ self printOn:aStream base:b showRadix:false
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2409
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2410
    "
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2411
     10 printOn:Transcript base:3
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2412
     31 printOn:Transcript base:3
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2413
     -20 printOn:Transcript base:16
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2414
     -20 printOn:Transcript base:10
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2415
     3000 factorial printOn:Transcript base:10
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2416
    "
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2417
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2418
    "Modified: / 20.1.1998 / 18:05:02 / stefan"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2419
    "Modified: / 7.9.2001 / 13:52:17 / cg"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2420
!
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2421
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2422
printOn:aStream base:b showRadix:showRadix
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2423
    "the central print method for integer.
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2424
     Must be defined in concrete classes"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2425
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2426
    self subclassResponsibility
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2427
!
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2428
5299
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  2429
printOn:aStream paddedWith:padCharacter to:size base:radix
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  2430
    |s|
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  2431
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  2432
    radix == 10 ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2433
	s := self printString.
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  2434
    ] ifFalse:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2435
	s := self printStringRadix:radix.
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  2436
    ].
5299
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  2437
    s printOn: aStream leftPaddedTo:size with: padCharacter
11098
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  2438
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  2439
    "
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  2440
     100 printOn:Transcript paddedWith:$0 to:10 base:10.     Transcript cr.
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  2441
     100 printOn:Transcript paddedWith:$0 to:10 base:16.     Transcript cr.
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  2442
     100 printOn:Transcript paddedWith:(Character space) to:10 base:16.     Transcript cr.
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  2443
     100 printOn:Transcript paddedWith:(Character space) to:10 base:2.     Transcript cr.
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  2444
    "
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  2445
!
5299
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  2446
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2447
printOn:aStream thousandsSeparator:thousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2448
    "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
  2449
     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
  2450
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  2451
    |rest|
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2452
11594
5440d97af571 #printStringWithThousandsSeparator fix for non-integers
Stefan Vogel <sv@exept.de>
parents: 11526
diff changeset
  2453
    self >= 1000 ifTrue:[
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2454
	(self // 1000) printOn:aStream thousandsSeparator:thousandsSeparator.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2455
	thousandsSeparator printOn:aStream.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2456
	rest := self \\ 1000.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2457
	rest < 100 ifTrue:[
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2458
	    aStream nextPut:$0.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2459
	    rest < 10 ifTrue:[
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2460
		aStream nextPut:$0.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2461
	    ].
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2462
	].
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2463
	rest printOn:aStream.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2464
	^ self.
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2465
    ].
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2466
    self printOn:aStream.
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2467
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2468
    "
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2469
     swiss style:
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2470
     1000000 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2471
     12345678 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2472
     1234567 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2473
     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
  2474
     123056 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2475
     12345 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2476
     1234 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2477
     123 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2478
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2479
     (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
  2480
     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
  2481
     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
  2482
     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
  2483
     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
  2484
     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
  2485
     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
  2486
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2487
     us style:
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2488
     1000000 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2489
     12345678 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2490
     1234567 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2491
     123456 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2492
     12345 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2493
     1234 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2494
     123 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2495
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2496
     german (european ?) style
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2497
     1000000 printOn:Transcript thousandsSeparator:$..     Transcript cr.
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2498
     12345678 printOn:Transcript thousandsSeparator:$..     Transcript cr.
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2499
     1234567 printOn:Transcript thousandsSeparator:$..     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2500
     123456 printOn:Transcript thousandsSeparator:$..     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2501
     12345 printOn:Transcript thousandsSeparator:$..     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2502
     1234 printOn:Transcript thousandsSeparator:$..     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2503
     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
  2504
    "
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2505
!
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2506
11660
62a726d91255 new: #printStringFormat:
Stefan Vogel <sv@exept.de>
parents: 11594
diff changeset
  2507
printStringFormat:formatString
23047
9aee14ae3d22 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23046
diff changeset
  2508
    "Return a printed representation of the receiver as specified by formatString,
9aee14ae3d22 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23046
diff changeset
  2509
     which is defined by PrintfScanf."
9aee14ae3d22 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23046
diff changeset
  2510
9aee14ae3d22 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23046
diff changeset
  2511
    ^ PrintfScanf printf:formatString argument:self.
9aee14ae3d22 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23046
diff changeset
  2512
    "/ ^ self printfPrintString:formatString
9aee14ae3d22 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23046
diff changeset
  2513
9aee14ae3d22 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23046
diff changeset
  2514
    "
9aee14ae3d22 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23046
diff changeset
  2515
     1.2345 printStringFormat:'%4.2f' -> '1.23'
9aee14ae3d22 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23046
diff changeset
  2516
     123 printStringFormat:'%4d' -> ' 123'
9aee14ae3d22 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23046
diff changeset
  2517
     123 printStringFormat:'%5.2f' -> '123.0'
9aee14ae3d22 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23046
diff changeset
  2518
    "
9aee14ae3d22 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23046
diff changeset
  2519
9aee14ae3d22 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23046
diff changeset
  2520
    "Modified (comment): / 03-06-2018 / 09:15:01 / Claus Gittinger"
11660
62a726d91255 new: #printStringFormat:
Stefan Vogel <sv@exept.de>
parents: 11594
diff changeset
  2521
!
62a726d91255 new: #printStringFormat:
Stefan Vogel <sv@exept.de>
parents: 11594
diff changeset
  2522
20142
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  2523
printStringRadix:base
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  2524
    "return a string representation of the receiver in the specified
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  2525
     base; does NOT prepend XXr to the string.
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  2526
     See also: radixPrintStringRadix:
20331
f9e364521eda #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20308
diff changeset
  2527
               printOn:base:showRadix:"
20142
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  2528
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  2529
    ^ self printStringRadix:base showRadix:false
11098
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  2530
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  2531
    "
20331
f9e364521eda #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20308
diff changeset
  2532
     10000000000000000000000000000000000000000000 printStringRadix:16    
f9e364521eda #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20308
diff changeset
  2533
     -10000000000000000000000000000000000000000000 printStringRadix:16   
11098
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  2534
    "
5299
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  2535
!
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  2536
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2537
printStringRadix:base showRadix:showRadixBoolean
23127
399ea1a6c384 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23047
diff changeset
  2538
    "return a string representation of the receiver in the specified base; 
399ea1a6c384 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23047
diff changeset
  2539
     optionally prepend XXr to the string.
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2540
     See also: radixPrintStringRadix:
23127
399ea1a6c384 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23047
diff changeset
  2541
               printOn:base:showRadix:"
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2542
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2543
    |s|
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2544
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2545
    s := WriteStream on:(String basicNew:20).
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2546
    self printOn:s base:base showRadix:showRadixBoolean.
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2547
    ^ s contents
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2548
20142
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  2549
    "
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  2550
     10000000000000000000000000000000000000000000 printStringRadix:16 showRadix:false
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  2551
     10000000000000000000000000000000000000000000 printStringRadix:16 showRadix:true
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  2552
    "
c1ec3253b3c1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19770
diff changeset
  2553
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2554
    "Created: / 23-09-2011 / 13:59:19 / cg"
23127
399ea1a6c384 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23047
diff changeset
  2555
    "Modified (comment): / 22-06-2018 / 09:56:17 / Claus Gittinger"
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2556
!
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2557
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2558
printStringWithThousandsSeparator
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2559
    "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
  2560
     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
  2561
20866
076ab5e1f702 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20421
diff changeset
  2562
    ^ self printStringWithThousandsSeparator:(UserPreferences current thousandsSeparatorCharacter).
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2563
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2564
    "
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2565
     1000000 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2566
     12345678 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2567
     1234567 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2568
     123456 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2569
     12345 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2570
     1234 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2571
     123 printStringWithThousandsSeparator
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2572
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2573
     1000000 asFixedPoint printStringWithThousandsSeparator
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2574
     12345678 asFixedPoint printStringWithThousandsSeparator
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2575
     1234567 asFixedPoint printStringWithThousandsSeparator
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2576
     123456 asFixedPoint printStringWithThousandsSeparator
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2577
     12345 asFixedPoint printStringWithThousandsSeparator
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2578
     1234 asFixedPoint printStringWithThousandsSeparator
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2579
     123 asFixedPoint printStringWithThousandsSeparator
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2580
     ((9999999//10000) asFixedPoint:9) printStringWithThousandsSeparator
20866
076ab5e1f702 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20421
diff changeset
  2581
     ((99999999//10000) asFixedPoint:9) printStringWithThousandsSeparator
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2582
    "
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2583
!
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2584
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2585
printStringWithThousandsSeparator:thousandsSeparator
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2586
    "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
  2587
     Notice:
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2588
	americans use comma
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2589
	germans (europeans ?) use a dot
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2590
	swiss people (business people ?) use a single quote
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2591
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2592
     Caveat: Should use the separator from the locale here"
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2593
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2594
    ^ String streamContents:[:s | self printOn:s thousandsSeparator:thousandsSeparator].
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2595
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2596
    "
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2597
     Transcript showCR:(1000000 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2598
     Transcript showCR:(12345678 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2599
     Transcript showCR:(1234567 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2600
     Transcript showCR:(123456 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2601
     Transcript showCR:(12345 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2602
     Transcript showCR:(1234 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2603
     Transcript showCR:(123 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2604
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2605
     Transcript showCR:(1000000 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2606
     Transcript showCR:(12345678 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2607
     Transcript showCR:(1234567 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2608
     Transcript showCR:(123456 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2609
     Transcript showCR:(12345 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2610
     Transcript showCR:(1234 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2611
     Transcript showCR:(123 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2612
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2613
     Transcript showCR:((1000000 asFixedPoint:2) printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2614
     Transcript showCR:((12345678 asFixedPoint:2) printStringWithThousandsSeparator:$,).
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2615
     Transcript showCR:((1234567 asFixedPoint:2) printStringWithThousandsSeparator:$,).
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2616
     Transcript showCR:((123456 asFixedPoint:2) printStringWithThousandsSeparator:$,).
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2617
     Transcript showCR:((12345 asFixedPoint:2) printStringWithThousandsSeparator:$,).
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2618
     Transcript showCR:((1234 asFixedPoint:2) printStringWithThousandsSeparator:$,).
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  2619
     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
  2620
    "
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2621
!
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  2622
21910
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2623
printfPrintString:formatString
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2624
    "Return a printed representation of the receiver as specified by formatString,
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2625
     which is defined by printf."
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2626
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2627
    ^ PrintfScanf printf:formatString argument:self
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2628
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2629
    "
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2630
     2.0 asQDouble printfPrintString:'%10f'
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2631
     2.0 asQDouble printfPrintString:'%10.8f'
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2632
     2.0 printfPrintString:'%10.8f'
25122
a7acd17d012a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 25086
diff changeset
  2633
     12345 printfPrintString:'0x%06x' 
21910
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2634
    "
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2635
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2636
    "Created: / 22-06-2017 / 13:55:22 / cg"
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2637
!
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  2638
18862
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2639
radixPrintStringRadix:radix
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2640
    "return a string representation of the receiver in the specified
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2641
     base; prepend XXr to the string"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2642
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2643
    ^ self printStringRadix:radix showRadix:true
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2644
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2645
    "
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2646
     31 radixPrintStringRadix:2
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2647
     31 radixPrintStringRadix:3
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2648
     31 radixPrintStringRadix:10
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2649
     31 radixPrintStringRadix:16
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2650
     31 radixPrintStringRadix:36
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2651
    "
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2652
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2653
    "Created: / 19-01-1998 / 17:38:00 / stefan"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2654
    "Modified: / 20-01-1998 / 14:11:03 / stefan"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2655
    "Modified: / 23-09-2011 / 14:00:02 / cg"
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2656
!
e0c777c9996f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18850
diff changeset
  2657
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2658
storeOn:aStream
11460
146fb82b5523 comment
Claus Gittinger <cg@exept.de>
parents: 11458
diff changeset
  2659
    "append a string for storing the receiver onto the argument, aStream
146fb82b5523 comment
Claus Gittinger <cg@exept.de>
parents: 11458
diff changeset
  2660
     - since numbers are literals,they store as they print."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2661
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2662
    ^ self printOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2663
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2664
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2665
storeString
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2666
    "return a string for storing
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2667
     - since numbers are literals, they store as they print."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2668
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2669
    ^ self printString
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2670
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2671
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2672
!Number methodsFor:'taylor series'!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2673
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2674
arcSin_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2675
    "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
  2676
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2677
    "/ uses taylor series:
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2678
    "/                 1*x^3   1*3 * x^5
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2679
    "/    arcSin = x + ----- + ---------- + ...
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2680
    "/                 2* 3    2*4 *  5
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2681
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2682
    |x2 num numf den denf approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2683
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2684
    ((self < -1) or:[self > 1]) ifTrue:[
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2685
        ^ self class
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2686
            raise:#domainErrorSignal
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2687
            receiver:self
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2688
            selector:#arcSin
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2689
            arguments:#()
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2690
            errorString:'bad receiver in arcSin'
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2691
    ].
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2692
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2693
    x2 := self squared.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2694
    num := x2 * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2695
    approx := self + (num / 6).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2696
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2697
    numf := 3.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2698
    denf := 4.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2699
    den := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2700
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2701
    [
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2702
        num := (num * x2) * numf.   numf := numf + 2.
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2703
        den := den * denf.          denf := denf + 2.
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2704
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2705
        delta := num / (den * numf).
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2706
        approx := approx + delta.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2707
    ] doUntil:[delta abs <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2708
    ^ approx
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
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2711
     0.5 arcSin                                    0.523599
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2712
     0.5q arcSin                        0.523598776
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2713
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2714
     0.5q arcSin_withAccuracy:1         0.520833333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2715
     0.5q arcSin_withAccuracy:0.1       0.520833333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2716
     0.5q arcSin_withAccuracy:0.01      0.523177083
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2717
     0.5q arcSin_withAccuracy:0.001     0.523525856
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2718
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2719
     0.5q arcSin_withAccuracy:1e-20     0.523598776
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2720
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2721
     0.5 asLargeFloat arcSin_withAccuracy:1e-30    -- not yet
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2722
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
     0.1 arcSin                                    0.100167
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2725
     0.1q arcSin                        0.100167421
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2726
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2727
     0.1q arcSin_withAccuracy:1         0.100166667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2728
     0.1q arcSin_withAccuracy:0.1       0.100166667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2729
     0.1q arcSin_withAccuracy:0.01      0.100166667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2730
     0.1q arcSin_withAccuracy:0.001     0.100166667
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2731
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2732
     0.1q arcSin_withAccuracy:1e-20     0.100167421
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2733
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2734
     0.1 asLargeFloat arcSin_withAccuracy:1e-30    -- not yet
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2735
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2736
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2737
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2738
arcTan_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2739
    "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
  2740
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2741
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2742
    "/                 x^3   x^5   x^7
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2743
    "/ arcTan(x) = x - --- + --- - --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2744
    "/                  3     5    7
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2745
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2746
    |x2 num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2747
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2748
    x2 := self squared.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2749
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2750
    num := (x2 * self) negated.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2751
    den := 3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2752
    approx := self + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2753
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2754
    [
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2755
        den := den + 2.
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2756
        num := (num * x2) negated.
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2757
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2758
        delta := num / den.
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2759
        approx := approx + delta.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2760
    ] doUntil:[delta abs <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2761
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2762
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2763
    "
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2764
     1.0 arcTan                       0.785398
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2765
     1q arcTan                        0.785398163
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2766
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2767
     1q arcTan_withAccuracy:1         0.666666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2768
     1q arcTan_withAccuracy:0.1       0.744011544
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2769
     1q arcTan_withAccuracy:0.01      0.790299653
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2770
     1q arcTan_withAccuracy:0.001     0.785897165
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2771
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2772
     1q arcTan_withAccuracy:1e-8      0.785398168
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2773
     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
  2774
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2775
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2776
     0.5 arcTan                         0.463648
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2777
     0.5q arcTan                        0.463647609
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2778
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2779
     0.5q arcTan_withAccuracy:1         0.458333333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2780
     0.5q arcTan_withAccuracy:0.1       0.458333333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2781
     0.5q arcTan_withAccuracy:0.01      0.464583333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2782
     0.5q arcTan_withAccuracy:0.001     0.463684276
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2783
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2784
     0.5q arcTan_withAccuracy:1e-20     0.463647609
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2785
     0.5 asLargeFloat arcTan_withAccuracy:1e-30    -- not yet
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2786
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2787
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2788
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2789
cbrt_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2790
    "compute cubic root of the receiver using a newton approx."
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2791
22097
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2792
    "Use Newton's method (not taylor):
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2793
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2794
                 2*x_n + (a / x_n^2)
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2795
        x_n+1 =  ---------------
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2796
                      3
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2797
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2798
        cbrt(a) = x_n
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2799
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2800
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2801
    |approx|
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2802
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2803
    self = 0 ifTrue:[
22097
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2804
        ^ self
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2805
    ].
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2806
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2807
    approx := 1.
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2808
    [
22097
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2809
        |lastApprox|
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2810
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2811
        lastApprox := approx.
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2812
        approx := ((approx * 2) + (self / approx / approx)) / 3.
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2813
        (approx - lastApprox) abs > epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2814
    ] whileTrue.
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2815
    ^ approx
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2816
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2817
    "
22097
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2818
     8q cbrt                                         2.0
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2819
     8q cbrt_withAccuracy:0.01                       2.000004911675504018
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2820
     8q cbrt_withAccuracy:0.0001                     2.000000000012062239
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2821
     8q cbrt_withAccuracy:0.0000001                  2.0
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2822
     8q cbrt_withAccuracy:0.0000000001               2.0
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2823
     8q cbrt_withAccuracy:0.000000000001             2.0
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2824
     8q cbrt_withAccuracy:LongFloat epsilon          2.0
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2825
     8q asQDouble cbrt_withAccuracy:QDouble epsilon  2.0
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2826
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2827
     27q cbrt_withAccuracy:0.01                      3.000000541064176501
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2828
     27q cbrt_withAccuracy:LongFloat epsilon         3.0
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2829
     -27q cbrt_withAccuracy:LongFloat epsilon        -3.0
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2830
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2831
     MessageTally spyOn:[ |arg|
22097
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2832
        arg := 2 asLongFloat.
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2833
        1000000 timesRepeat:[
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2834
             arg cbrt_withAccuracy:0.000000000001
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2835
        ]
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2836
     ]
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2837
     Time millisecondsToRun:[ |arg|
22097
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2838
        arg := 2 asLongFloat.
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2839
        1000000 timesRepeat:[
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2840
             arg cbrt_withAccuracy:0.000000000001
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2841
        ]
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2842
     ]
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2843
    "
22097
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2844
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  2845
    "Modified (comment): / 25-07-2017 / 16:09:22 / cg"
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2846
!
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2847
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2848
cos_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2849
    "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
  2850
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2851
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2852
    "/               x^2   x^4   x^6
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2853
    "/  cos(x) = 1 - --- + --- - --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2854
    "/                2!!    4!!    6!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2855
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2856
    |x2 facN num den approx lastApprox|
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2857
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2858
    x2 := self squared.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2859
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2860
    num := x2 negated.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2861
    den := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2862
    facN := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2863
    approx := 1 + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2864
    lastApprox := 1.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2865
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2866
    [ (lastApprox - approx) abs > epsilon ] whileTrue:[
24988
2b353bb8b70a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24971
diff changeset
  2867
        facN := facN + 2.
2b353bb8b70a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24971
diff changeset
  2868
        den := den * (facN - 1) * facN.
2b353bb8b70a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24971
diff changeset
  2869
        num := (num * x2) negated.
2b353bb8b70a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24971
diff changeset
  2870
        lastApprox := approx.
2b353bb8b70a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24971
diff changeset
  2871
        approx := approx + (num / den).
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2872
    ].
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2873
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2874
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2875
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2876
     1.0 cos                                    0.540302
24988
2b353bb8b70a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24971
diff changeset
  2877
     1.0 asLongFloat cos                        0.5403023058681397174
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2878
     1.0 asLongFloat cos_withAccuracy:1         0.5
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2879
     1.0 asLongFloat cos_withAccuracy:0.1       0.541666667
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2880
     1.0 asLongFloat cos_withAccuracy:0.01      0.540277778
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2881
     1.0 asLongFloat cos_withAccuracy:0.001     0.540302579
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2882
24988
2b353bb8b70a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24971
diff changeset
  2883
     1.0 asLongFloat cos_withAccuracy:1e-40     0.5403023058681397175
2b353bb8b70a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24971
diff changeset
  2884
     1.0 asQDouble cos                          0.5403023058681396874081335957994
2b353bb8b70a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24971
diff changeset
  2885
     1.0 asQDouble cos_withAccuracy:1e-40       
2b353bb8b70a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24971
diff changeset
  2886
     Wolfram:
2b353bb8b70a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24971
diff changeset
  2887
            0.5403023058681396874081335957994 
2b353bb8b70a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24971
diff changeset
  2888
            0.540302305868139717400936607442976603732310420617922227670...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2889
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2890
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2891
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2892
cosh_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  2893
    "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
  2894
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2895
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2896
    "/               x^2   x^4   x^6
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2897
    "/    cosh = x + --- + --- + --- ...
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2898
    "/                2!!    4!!    6!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2899
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2900
    |x2 facN num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2901
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2902
    x2 := self squared.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2903
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2904
    num := x2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2905
    den := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2906
    facN := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2907
    approx := self + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2908
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2909
    [
22143
b634ad282d1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22119
diff changeset
  2910
        facN := facN + 2.
b634ad282d1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22119
diff changeset
  2911
        den := den * (facN - 1) * facN.
b634ad282d1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22119
diff changeset
  2912
        num := num * x2.
b634ad282d1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22119
diff changeset
  2913
b634ad282d1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22119
diff changeset
  2914
        delta := num / den.
b634ad282d1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22119
diff changeset
  2915
        approx := approx + delta.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2916
    ] doUntil:[delta <= epsilon].
22143
b634ad282d1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22119
diff changeset
  2917
    ^ approx + self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2918
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2919
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2920
     1.0 cosh                                    1.54308
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2921
     1.0q cosh_withAccuracy:1         1.5
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2922
     1.0q cosh_withAccuracy:0.1       1.54308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2923
     1.0q cosh_withAccuracy:0.01      1.54308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2924
     1.0q cosh_withAccuracy:0.001     1.54308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2925
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2926
     1.0q cosh_withAccuracy:1e-40   -> 1.543080
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2927
    "
22143
b634ad282d1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22119
diff changeset
  2928
b634ad282d1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22119
diff changeset
  2929
    "Modified: / 01-08-2017 / 14:54:40 / stefan"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2930
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2931
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2932
epsilon
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2933
    "return the maximum relative spacing of instances of mySelf
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2934
     (i.e. the value-delta of the least significant bit)"
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2935
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2936
    ^ self class epsilon
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2937
!
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2938
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2939
exp_withAccuracy:epsilon
21888
f7b6885f1cec #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21871
diff changeset
  2940
    "compute e^x of the receiver using a taylor series approximation.
f7b6885f1cec #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21871
diff changeset
  2941
     This method is only invoked for limitedPrecisionReal classes, which do not compute
f7b6885f1cec #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21871
diff changeset
  2942
     exp themself (i.e. QDouble)"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2943
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2944
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2945
    "/             x    x^2   x^3
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2946
    "/  e^x = 1 + --- + --- + --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2947
    "/             1!!    2!!    3!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2948
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2949
    |x2 facN num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2950
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  2951
    x2 := self squared. "/ self squared.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2952
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2953
    num := x2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2954
    den := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2955
    facN := 2.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2956
    approx := self + 1 + (num / den).
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2957
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2958
    [
21888
f7b6885f1cec #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21871
diff changeset
  2959
        facN := facN + 1.
f7b6885f1cec #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21871
diff changeset
  2960
        den := den * facN.
f7b6885f1cec #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21871
diff changeset
  2961
        num := num * self.
f7b6885f1cec #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21871
diff changeset
  2962
f7b6885f1cec #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21871
diff changeset
  2963
        delta := num / den.
22302
cc8e3512ac18 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22290
diff changeset
  2964
"/ delta mantissa == 0 ifTrue:[self halt. num / den].
cc8e3512ac18 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22290
diff changeset
  2965
"/ Transcript showCR:delta.
cc8e3512ac18 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22290
diff changeset
  2966
        delta isNaN ifTrue:[self halt:'nan when dividing for delta'. num / den].
cc8e3512ac18 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22290
diff changeset
  2967
        delta = 0 ifTrue:[self halt:'zero delta'].
21888
f7b6885f1cec #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21871
diff changeset
  2968
        approx := approx + delta.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2969
    ] doUntil:[delta abs <= epsilon].
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2970
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2971
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2972
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2973
    "
22302
cc8e3512ac18 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22290
diff changeset
  2974
     wolfram:
cc8e3512ac18 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22290
diff changeset
  2975
                7.389056098930650227230427460575007813180315570551847324087
cc8e3512ac18 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22290
diff changeset
  2976
cc8e3512ac18 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22290
diff changeset
  2977
     (2 asLargeFloat exp_withAccuracy:1e-100) printfPrintString:'%50.48f'                      
cc8e3512ac18 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22290
diff changeset
  2978
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2979
     1.0 exp                                    2.71828
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2980
     1q exp                                     2.71828183
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  2981
     2q exp                                     7.3890561
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2982
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2983
     1q exp_withAccuracy:1                      2.66666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2984
     1q exp_withAccuracy:0.1                    2.70833333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2985
     1q exp_withAccuracy:0.01                   2.71666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2986
     1q exp_withAccuracy:0.001                  2.71825397
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2987
21912
c3fe3452acb2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21910
diff changeset
  2988
     -1 exp                                     0.367879441171442
c3fe3452acb2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21910
diff changeset
  2989
     -1q exp_withAccuracy:(1e-60)               0.3678794411714423216
c3fe3452acb2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21910
diff changeset
  2990
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  2991
     2q exp_withAccuracy:LongFloat epsilon      7.3890561
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2992
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2993
     42 asQDouble exp_withAccuracy:QDouble epsilon        
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2994
     42 asQDouble exp_withAccuracy:LongFloat epsilon  
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2995
     42 asQDouble exp_withAccuracy:Float epsilon    
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2996
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2997
     2 asQDouble exp_withAccuracy:QDouble epsilon   7.38905609893065022723     
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2998
     2 asQDouble exp_withAccuracy:LongFloat epsilon 7.38905609893065022723  
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  2999
     2 asQDouble exp_withAccuracy:Float epsilon     7.38905609893065022489
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3000
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3001
     1 asQDouble exp_withAccuracy:QDouble epsilon   2.71828182845904523536     
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3002
     1 asQDouble exp_withAccuracy:LongFloat epsilon 2.71828182845904523536 
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3003
     1 asQDouble exp_withAccuracy:Float epsilon     2.71828182845904522671
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3004
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3005
     1.0 asLongFloat exp_withAccuracy:1e-40     2.71828183
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3006
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3007
     5 exp_withAccuracy:1e-40
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3008
     (1 exp_withAccuracy:1e-100) asFixedPoint:100
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3009
    "
21888
f7b6885f1cec #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21871
diff changeset
  3010
22302
cc8e3512ac18 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22290
diff changeset
  3011
    "Modified: / 10-10-2017 / 16:04:08 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3012
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3013
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3014
ln_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  3015
    "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
  3016
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3017
    "uses taylor series:
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3018
                 u^2   u^3
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3019
        ln = u - --- + --- ...
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3020
                  2    3
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3021
      where:
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3022
             u = x - 1    and: x < 1
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3023
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3024
     Now we use modified taylor, which converges a little faster:
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3025
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3026
                   1+y        1   1       1
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3027
        ln(x) = ln --- = 2y ( - + - y^2 + - y^4 + ....)
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3028
                   1-y        1   3       5
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3029
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3030
        where y = (x-1) / (x+1)  and x > 0
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3031
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3032
     Warning: this converges very slowly. Find a better algorithm    
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3033
    "
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3034
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3035
    |denominator approx y y2 exp delta count|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3036
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3037
    self <= 0 ifTrue:[
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3038
        ^ self class
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3039
            raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal])
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3040
            receiver:self
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3041
            selector:#ln
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3042
            arguments:#()
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3043
            errorString:'bad receiver in ln (not strictly positive)'
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3044
    ].
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3045
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3046
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3047
    y := (self - 1)/(self + 1).
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3048
    exp := y2 := y squared.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3049
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3050
    approx := 1.0.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3051
    denominator := 3.0.
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3052
    count := 1.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3053
    
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3054
    [
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3055
        delta := exp / denominator.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3056
        approx := approx + delta.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3057
        exp := exp * y2.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3058
        denominator := denominator + 2.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3059
        
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3060
        count := count + 1.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3061
        (count \\ 100) == 0 ifTrue:[
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3062
            Logger warning:'slow ln-taylor converging...'.
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3063
        ].    
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3064
    ] doUntil:[delta <= epsilon or:[count > 10000]].
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3065
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3066
    ^ y * 2 * approx.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3067
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3068
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3069
    "
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3070
     2.0 ln                         0.693147180559945
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3071
     2.0q ln                        0.6931471805599453094
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3072
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3073
     2.0q ln_withAccuracy:1                  0.691358025
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3074
     2.0q ln_withAccuracy:0.1                0.691358025
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3075
     2.0q ln_withAccuracy:0.01               0.693004115
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3076
     2.0q ln_withAccuracy:0.0000001          0.69314718
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3077
     2.0q ln_withAccuracy:1e-10              0.6931471805589163927
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3078
     2.0q ln_withAccuracy:1e-20              0.6931471805599453094
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3079
     2.0q ln_withAccuracy:1e-40              0.6931471805599453094
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3080
     2.0q ln_withAccuracy:2.0q class epsilon 0.6931471805599453094
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3081
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3082
     (2 ln_withAccuracy:1e-40) -> a fraction        
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3083
     0 ln_withAccuracy:1e-40
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3084
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3085
     (2 ln_withAccuracy:1e-100) asFixedPoint:100
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3086
     (2 asFixedPoint:200) ln_withAccuracy:(1/(10 raisedTo:200))
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3087
        0.69314718055994530941723212145817656807550013436025525412068000949339362196969471560586332699641868754200148102057068573368552023575813055703267075163507596193072757082837143519030703862389167347112335
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3088
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3089
     (2 asFixedPoint:400) ln_withAccuracy:(1/(10 raisedTo:400))
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3090
        0.69314718055994530941723212145817656807550013436025525412068000949339362196969471560586332699641868754200148102057068573368552023575813055703267075163507596193072757082837143519030703862389167347112335 01153644979552391204751726815749320651555247341395258829504530070953263666426541042391578149520437404303855008019441706416715186447128399681717845469570262716310645461502572074024816377733896385506953
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3091
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3092
     (2.0 asQDouble ln_withAccuracy:QDouble epsilon) printfPrintString:'%60.58f'
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3093
        0.69314718055994 52709398341558750792990469129794959648865081'
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3094
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3095
     Wolfram says:
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3096
        0.69314718055994530941723212145817656807550013436025525412068000949339362196969471560586332699641868754200148102057068573368552023575813055703267075163507596193072757082837143519030703862389167347112335 01153644979552391204751726...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3097
    "
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3098
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3099
    "Modified: / 05-07-2017 / 17:16:24 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3100
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3101
21915
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3102
nthRoot:n withAccuracy:epsilon
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3103
    "compute nth root of the receiver using a newton approx."
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3104
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3105
    "
22104
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3106
      Use Newton's method:
21915
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3107
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3108
                 (n-1)*x_n^n + (a / x_n^(n-1))
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3109
        x_n+1 =  -----------------------------
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3110
                             n
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3111
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3112
        rt(n, a) = x_n
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3113
    "
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3114
22287
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  3115
    |approx delta absDelta prevDelta|
21915
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3116
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3117
    self = 0 ifTrue:[
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3118
        ^ self
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3119
    ].
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3120
22104
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3121
    "/ the demanded epsilon may NEVER be smaller than the real representation's epsilon
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3122
    self assert:(epsilon >= (self class epsilon)).
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3123
    
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3124
    approx := (self / 2).
22287
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  3125
    delta := ((self / (approx raisedToInteger:(n-1))) - approx) / n.
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  3126
    absDelta := delta abs.
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  3127
    approx := approx + delta.
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  3128
    
21915
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3129
    [
22287
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  3130
        prevDelta := absDelta.
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  3131
        
22104
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3132
        delta := ((self / (approx raisedToInteger:(n-1))) - approx) / n.
22287
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  3133
        absDelta := delta abs.
22104
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3134
        approx := approx + delta.
22098
e5884f5aa8df #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22097
diff changeset
  3135
        
22287
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  3136
        (absDelta < prevDelta) ifFalse:[ 
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  3137
            DomainError raiseRequestErrorString:'no convergence in Newton approx.'
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  3138
        ].
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  3139
        
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  3140
        (absDelta > epsilon)
21915
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3141
    ] whileTrue.
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3142
    ^ approx
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3143
22104
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3144
    "                                             
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3145
     8q nthRoot:3 withAccuracy:0.01               2.00000002488636242
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3146
     8q nthRoot:3 withAccuracy:0.0001             2.00000000000000031
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3147
     8q nthRoot:3 withAccuracy:0.0000001          2.00000000000000031
21915
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3148
     8q nthRoot:3 withAccuracy:0.0000000001       2.0
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3149
     8q nthRoot:3 withAccuracy:0.000000000001     2.0
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3150
     8q nthRoot:3 withAccuracy:LongFloat epsilon  2.0
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3151
22104
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3152
     27q nthRoot:3 withAccuracy:0.01                3.000000081210202031
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3153
     27q nthRoot:3 withAccuracy:LongFloat epsilon   3.0
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3154
     -27q nthRoot:3 withAccuracy:LongFloat epsilon  -3.0
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3155
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3156
     10000q nthRoot:5 withAccuracy:1e-18        -> 6.309573444801932495 
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3157
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3158
     (10000 asQDouble nthRoot:5) printfPrintString:'%70.68f'
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3159
               6.30957344480193249434360136622343864672945257188228724527729528834741'
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3160
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3161
     actual result (Mathematica):        
06243cca0b18 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22098
diff changeset
  3162
               6.309573444801932494343601366223438646729452571882287245277...
21915
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3163
    "
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3164
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3165
    "Created: / 22-06-2017 / 15:51:55 / cg"
22287
df6101a1d351 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22279
diff changeset
  3166
    "Modified: / 22-09-2017 / 10:14:59 / cg"
21915
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3167
!
358869e5f606 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21912
diff changeset
  3168
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3169
sin_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  3170
    "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
  3171
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3172
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3173
    "/               x^3   x^5   x^7
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3174
    "/  sin(x) = x - --- + --- - --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3175
    "/                3!!    5!!    7!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3176
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3177
    |x2 facN num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3178
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3179
    x2 := self squared.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3180
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3181
    num := (x2 * self) negated.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3182
    den := 2*3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3183
    facN := 3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3184
    approx := self + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3185
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3186
    [
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3187
        facN := facN + 2.
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3188
        den := den * (facN - 1) * facN.
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3189
        num := (num * x2) negated.
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3190
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3191
        delta := num / den.
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3192
        approx := approx + delta.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3193
    ] doUntil:[delta abs <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3194
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3195
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3196
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3197
     1.0 sin                                    0.841471
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3198
     1.0q sin                        0.841470985
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3199
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3200
     1.0q sin_withAccuracy:1         0.833333333
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3201
     1.0q sin_withAccuracy:0.1       0.841666667
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3202
     1.0q sin_withAccuracy:0.01      0.841666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3203
     1.0q sin_withAccuracy:0.001     0.841468254
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3204
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3205
     1.0q sin_withAccuracy:1e-40     0.841470985
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3206
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3207
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3208
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3209
sinh_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  3210
    "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
  3211
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3212
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3213
    "/               x^3   x^5   x^7
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3214
    "/ sinh(x) = x + --- + --- + --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3215
    "/                3!!    5!!    7!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3216
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3217
    |x2 facN num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3218
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3219
    x2 := self squared.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3220
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3221
    num := x2 * self.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3222
    den := 2*3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3223
    facN := 3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3224
    approx := self + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3225
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3226
    [
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3227
        facN := facN + 2.
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3228
        den := den * (facN - 1) * facN.
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3229
        num := num * x2.
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3230
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3231
        delta := num / den.
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3232
        approx := approx + delta.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3233
    ] doUntil:[delta abs <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3234
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3235
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3236
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3237
     1.0 sinh                                    1.1752
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3238
     1q sinh                        1.17520119
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3239
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3240
     1q sinh_withAccuracy:1         1.16666667
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3241
     1q sinh_withAccuracy:0.1       1.175
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3242
     1q sinh_withAccuracy:0.01      1.175
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3243
     1q sinh_withAccuracy:0.001     1.17519841
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3244
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3245
     1q sinh_withAccuracy:1e-40     1.17520119
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3246
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3247
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3248
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3249
sqrt_withAccuracy:epsilon
21910
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3250
    "compute square root of the receiver using newton-raphson/heron algorithm"
22097
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  3251
    "Use the Heron algorithm (not Taylor)"
21910
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3252
22096
9215a25fe639 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22043
diff changeset
  3253
    |guess|
9215a25fe639 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22043
diff changeset
  3254
9215a25fe639 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22043
diff changeset
  3255
    false "self isInteger" ifTrue:[
9215a25fe639 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22043
diff changeset
  3256
        guess := 1 bitShift:(self highBit // 2)
9215a25fe639 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22043
diff changeset
  3257
    ] ifFalse:[
22106
9f2406985b6f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22104
diff changeset
  3258
        guess := self / 2.0.
22096
9215a25fe639 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22043
diff changeset
  3259
    ].    
9215a25fe639 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22043
diff changeset
  3260
    ^ self sqrt_withAccuracy:epsilon fromInitialGuess:guess
21910
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3261
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3262
    "
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3263
     2 sqrt                                  1.4142135623731      - computed by CPU/FPU
22096
9215a25fe639 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22043
diff changeset
  3264
     200000000 sqrt                          
21910
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3265
     
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3266
     2q sqrt                                 1.414213562373095049 - computed by CPU/FPU
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3267
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3268
     2q sqrt_withAccuracy:0.01               1.414215686274509804 - computed by Smalltalk
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3269
     2q sqrt_withAccuracy:0.0001             1.414213562374689911
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3270
     2q sqrt_withAccuracy:0.0000001          1.414213562373095049
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3271
     2q sqrt_withAccuracy:0.0000000001       1.414213562373095049
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3272
     2q sqrt_withAccuracy:0.000000000001     1.414213562373095049
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3273
     
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3274
     2q sqrt_withAccuracy:LongFloat epsilon  1.414213562373095049
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3275
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3276
     (4 sqrt_withAccuracy:Integer epsilon) asFloat
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3277
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3278
     MessageTally spyOn:[ |arg|
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3279
        arg := 2 asLongFloat.
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3280
        1000000 timesRepeat:[
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3281
             arg sqrt_withAccuracy:0.000000000001
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3282
        ]
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3283
     ]
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3284
     Time millisecondsToRun:[ |arg|
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3285
        arg := 2 asLongFloat.
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3286
        1000000 timesRepeat:[
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3287
             arg sqrt_withAccuracy:0.000000000001
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3288
        ]
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3289
     ]
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3290
    "
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3291
22106
9f2406985b6f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22104
diff changeset
  3292
    "Modified: / 25-07-2017 / 17:44:46 / cg"
21910
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3293
!
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3294
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3295
sqrt_withAccuracy:epsilon fromInitialGuess:guess
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3296
    "compute square root of the receiver using newton-raphson/heron algorithm"
22097
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  3297
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  3298
    "Use the Heron algorithm (not Taylor):
21910
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3299
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3300
                 x_n + (a / x_n)
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3301
        x_n+1 =  ---------------
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3302
                      2
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3303
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3304
        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
  3305
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3306
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3307
    |approx lastApprox|
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3308
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3309
    self <= 0 ifTrue:[
21910
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3310
        self = 0 ifTrue:[
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3311
            ^ self
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3312
        ].
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3313
        ^ self class
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3314
            raise:#imaginaryResultSignal
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3315
            receiver:self
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3316
            selector:#sqrt
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3317
            arguments:#()
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3318
            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
  3319
    ].
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3320
21910
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3321
    approx := guess.
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3322
    [
21910
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3323
        lastApprox := approx.
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3324
        approx := ((self / approx) + approx) / 2.
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3325
        (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
  3326
    ] whileTrue.
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3327
    ^ approx
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3328
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3329
    "
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  3330
     2 sqrt                                  1.4142135623731
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  3331
     2q sqrt                                 1.414213562373095049
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  3332
     2q sqrt_withAccuracy:0.01               1.414215686274509804
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  3333
     2q sqrt_withAccuracy:0.0001             1.414213562374689911
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  3334
     2q sqrt_withAccuracy:0.0000001          1.414213562373095049
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  3335
     2q sqrt_withAccuracy:0.0000000001       1.414213562373095049
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  3336
     2q sqrt_withAccuracy:0.000000000001     1.414213562373095049
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  3337
     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
  3338
21916
da181b5ca94e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21915
diff changeset
  3339
     (2 asQDouble sqrt_withAccuracy:LongFloat epsilon) printfPrintString:'%70.68f'
da181b5ca94e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21915
diff changeset
  3340
            1.41421356237309504880168872420969807856967187537723400156101313309966
da181b5ca94e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21915
diff changeset
  3341
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3342
     (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
  3343
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3344
     MessageTally spyOn:[ |arg|
21910
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3345
        arg := 2 asLongFloat.
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3346
        1000000 timesRepeat:[
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3347
             arg sqrt_withAccuracy:0.000000000001
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3348
        ]
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3349
     ]
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3350
     Time millisecondsToRun:[ |arg|
21910
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3351
        arg := 2 asLongFloat.
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3352
        1000000 timesRepeat:[
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3353
             arg sqrt_withAccuracy:0.000000000001
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3354
        ]
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3355
     ]
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3356
    "
21910
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3357
97611fd50260 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21894
diff changeset
  3358
    "Created: / 22-06-2017 / 13:59:48 / cg"
22097
5aa70f7b0d9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22096
diff changeset
  3359
    "Modified (comment): / 25-07-2017 / 16:07:37 / cg"
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3360
!
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  3361
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3362
tan_withAccuracy:epsilon
17190
284d9c71385f class: Number
Claus Gittinger <cg@exept.de>
parents: 17127
diff changeset
  3363
    "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
  3364
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3365
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3366
    "/                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
  3367
    "/    tan = x + 1*--- + 2*--- + 17*--- + 62*----... ----------------------------------...
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3368
    "/                 3       15      315      2835                 (2n)!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3369
    "/ where Bi is the ith bernoulli number.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3370
22543
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3371
    |factors idx x2 num t approx lastApprox delta nFactors|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3372
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3373
    "/    (1 to:20) collect:[:n| |num den|
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3374
    "/        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
  3375
    "/        den := (2*n) factorial.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3376
    "/        num / den
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3377
    "/    ]
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3378
   factors := #(
22543
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3379
        (1 3)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3380
        (2 15)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3381
        (17 315)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3382
        (62 2835)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3383
        (1382 155925)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3384
        (21844 6081075)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3385
        (929569 638512875)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3386
        (6404582 10854718875)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3387
        (443861162 1856156927625)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3388
        (18888466084 194896477400625)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3389
        (113927491862 2900518163668125)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3390
        (58870668456604 3698160658676859375)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3391
        (8374643517010684 1298054391195577640625)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3392
        (689005380505609448 263505041412702261046875)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3393
        (129848163681107301953 122529844256906551386796875)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3394
        (1736640792209901647222 4043484860477916195764296875)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3395
        (418781231495293038913922 2405873491984360136479756640625)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3396
        (56518638202982204522669764 801155872830791925447758961328125)
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3397
        (32207686319158956594455462 1126482925555250126673224649609375)).
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3398
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3399
    nFactors := factors size.
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3400
    x2 := self squared.
8203
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  3401
    num := x2 * self.               "/ =  x^3
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  3402
    approx := self + (num / 3).     "/ do the first iteration
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3403
    lastApprox := self.
8203
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  3404
    idx := 2.
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  3405
    [
22543
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3406
        idx > nFactors ifTrue:[
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3407
            ArithmeticError raiseErrorString:'too many iterations'.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3408
"/ Not enough bernoulli numbers for now...
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3409
"/            |tempNum tempDen|
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3410
"/            tempNum := 2 raisedTo:(2*idx).
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3411
"/            tempNum := tempNum * (tempNum-1) * ((2*idx) bernoulli).
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3412
"/            tempDen := (2*idx) factorial.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3413
"/            t := Array with:tempNum with:tempDen.
22543
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3414
        ].
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3415
        t := factors at:idx.
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3416
        idx := idx + 1.
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3417
        num := num * x2.
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3418
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3419
        delta := num * t first / t second.
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3420
        approx := approx + delta.
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3421
        delta abs > epsilon
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3422
    ] whileTrue.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3423
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3424
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3425
    "
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3426
     0.5 tan                         0.546302
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3427
     0.5q tan                        0.54630249
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3428
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3429
     0.5q tan_withAccuracy:1         0.541666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3430
     0.5q tan_withAccuracy:0.1       0.541666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3431
     0.5q tan_withAccuracy:0.01      0.545833333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3432
     0.5q tan_withAccuracy:0.001     0.54625496
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3433
     0.5q tan_withAccuracy:1e-15     0.54630249
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3434
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  3435
     0.5q tan_withAccuracy:1e-40     -- too many iterations
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3436
    "
22543
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3437
0e18000866a1 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22302
diff changeset
  3438
    "Modified: / 15-02-2018 / 18:53:37 / stefan"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3439
! !
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3440
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3441
!Number methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3442
17224
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  3443
even
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  3444
    "return true if the receiver is divisible by 2."
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  3445
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  3446
    self fractionPart = 0 ifTrue:[
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3447
        ^ (self / 2) fractionPart = 0
17224
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  3448
    ].
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  3449
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  3450
    "this will raise an error"
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  3451
    ^ super even
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  3452
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  3453
    "
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3454
     2 even
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3455
     2.0 even
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3456
     3.0 even
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3457
     2.4 even
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3458
     (5/3) even
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3459
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3460
     2 asFraction even
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3461
     (2 asFixedPoint:5) even
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3462
     2 asFloatE even
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3463
     2 asFloatD even
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3464
     2 asFloatQ even
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3465
     2 asFloatQD even
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3466
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3467
     (2.1 asFloatQD - (QDouble readFrom:'2.1')) fractionPart
17224
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  3468
    "
21982
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3469
e5e18c857a2b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21930
diff changeset
  3470
    "Modified (comment): / 03-07-2017 / 14:14:46 / cg"
17224
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  3471
!
43a8ca39cc90 class: Number
Stefan Vogel <sv@exept.de>
parents: 17207
diff changeset
  3472
5360
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  3473
isDivisibleBy:aNumber
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  3474
    "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
  3475
     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
  3476
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  3477
    aNumber = 0 ifTrue: [^ false].
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  3478
    aNumber isInteger ifFalse: [^ false].
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  3479
    ^ (self \\ aNumber) = 0
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  3480
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  3481
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3482
     3 isDivisibleBy:2
5360
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  3483
     4 isDivisibleBy:2
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3484
     4.0 isDivisibleBy:2
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3485
     4.5 isDivisibleBy:4.5
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3486
     4.5 isDivisibleBy:1.0
5360
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  3487
    "
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  3488
!
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  3489
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  3490
isNaN
24702
b1559a3850a0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24548
diff changeset
  3491
    "return true, if the receiver is an invalid number (NaN - not a number)."
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  3492
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  3493
    ^ false
6155
00eaf2fa55bc isReal comment
Claus Gittinger <cg@exept.de>
parents: 6154
diff changeset
  3494
00eaf2fa55bc isReal comment
Claus Gittinger <cg@exept.de>
parents: 6154
diff changeset
  3495
    "Created: / 5.11.2001 / 18:07:26 / cg"
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  3496
!
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  3497
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3498
isNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3499
    "return true, if the receiver is a kind of number"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3500
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3501
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3502
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3503
19136
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3504
isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3505
    "return true if I am a perfect square.
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3506
     That is a number for which the square root is an integer."
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3507
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3508
    self truncated = self ifFalse:[^ false].
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3509
    ^ self asInteger isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3510
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3511
    "
24938
3d1e65070dce #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24934
diff changeset
  3512
     0 isPerfectSquare   
19136
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3513
     0.0 isPerfectSquare
24938
3d1e65070dce #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24934
diff changeset
  3514
     1 isPerfectSquare  
3d1e65070dce #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24934
diff changeset
  3515
     1.0 isPerfectSquare 
3d1e65070dce #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24934
diff changeset
  3516
     2 isPerfectSquare  
3d1e65070dce #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24934
diff changeset
  3517
     2.0 isPerfectSquare 
19136
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3518
     3 isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3519
     3.0 isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3520
     4 isPerfectSquare
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3521
     4.0 isPerfectSquare
24938
3d1e65070dce #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24934
diff changeset
  3522
     9 isPerfectSquare   
3d1e65070dce #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24934
diff changeset
  3523
     9.0 isPerfectSquare  
24867
985f27e62272 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24702
diff changeset
  3524
     123456789012345678901234567890 squared isPerfectSquare
24938
3d1e65070dce #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24934
diff changeset
  3525
     1000 factorial squared isPerfectSquare  
19136
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3526
    "
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3527
!
5645cf0c4774 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19092
diff changeset
  3528
6087
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  3529
isReal
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  3530
    "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
  3531
     true is returned here - the method is redefined from Object."
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  3532
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  3533
    ^ true
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  3534
!
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  3535
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3536
isZero
1557
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  3537
    "return true, if the receiver is zero"
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  3538
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3539
    ^ self = 0
1557
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  3540
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  3541
    "Modified: 18.7.1996 / 12:40:49 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3542
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  3543
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  3544
!Number methodsFor:'tracing'!
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  3545
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4659
diff changeset
  3546
traceInto:aRequestor level:level from:referrer
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  3547
    "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
  3548
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4659
diff changeset
  3549
    ^ aRequestor traceNumber:self level:level from:referrer
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  3550
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  3551
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  3552
! !
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  3553
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3554
!Number methodsFor:'trigonometric'!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3555
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3556
arcCos
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3557
    "return the arccosine of the receiver (in radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3558
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3559
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3560
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3561
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3562
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3563
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3564
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3565
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3566
            ^ f arcCos.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3567
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3568
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3569
    "/ slow fallback
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  3570
    ^ (self class pi / 2) - self arcSin
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3571
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3572
    "Modified: / 05-07-2017 / 17:24:32 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3573
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3574
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3575
arcCosech
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3576
    "return the inverse hyperbolic cosecant of the receiver."
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3577
    "caveat: misnomer; should be called aCosech or arCosech"
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3578
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3579
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3580
    "/ retry after converting to float
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3581
    (self isLimitedPrecisionReal not
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3582
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3583
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3584
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3585
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3586
            ^ f arcCosech.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3587
        ].
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3588
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3589
    "/ slow fallback
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3590
    ^ ((1 + ((self squared)+1) sqrt) / self) ln
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3591
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3592
    "Modified: / 05-07-2017 / 17:24:56 / cg"
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3593
!
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3594
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3595
arcCosh
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3596
    "return the inverse hyperbolic cosine of the receiver."
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3597
    "caveat: misnomer; should be called aCosh or arCosh"
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3598
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3599
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3600
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3601
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3602
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3603
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3604
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3605
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3606
            ^ f arcCosh.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3607
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3608
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3609
    "/ slow fallback
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3610
    ^ (self + (self squared-1) sqrt) ln.
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3611
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3612
    "Modified: / 05-07-2017 / 17:25:03 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3613
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3614
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3615
arcCoth
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3616
    "return the inverse hyperbolic cotangent of the receiver."
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3617
    "caveat: misnomer; should be called aCoth or arCoth"
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3618
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3619
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3620
    "/ retry after converting to float
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3621
    (self isLimitedPrecisionReal not
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3622
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3623
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3624
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3625
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3626
            ^ f arcCoth.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3627
        ].
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3628
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3629
    "/ slow fallback
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3630
    ^ ((self+1) / (self-1)) ln / 2
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3631
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3632
    "Modified: / 05-07-2017 / 17:25:14 / cg"
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3633
!
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3634
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3635
arcSech
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3636
    "return the inverse hyperbolic secant of the receiver."
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3637
    "caveat: misnomer; should be called aSech or arSech"
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3638
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3639
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3640
    "/ retry after converting to float
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3641
    (self isLimitedPrecisionReal not
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3642
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3643
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3644
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3645
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3646
            ^ f arcSech.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3647
        ].
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3648
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3649
    "/ slow fallback
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3650
    ^ ((1 + (1-(self squared)) sqrt) / self) ln
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3651
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3652
    "Modified: / 05-07-2017 / 17:25:22 / cg"
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3653
!
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3654
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3655
arcSin
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3656
    "return the arcsine of the receiver (in radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3657
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3658
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3659
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3660
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3661
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3662
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3663
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3664
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3665
            ^ f arcSin.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3666
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3667
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3668
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  3669
    ^ self arcSin_withAccuracy:self epsilon
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3670
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3671
    "Modified: / 05-07-2017 / 17:25:30 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3672
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3673
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3674
arcSinh
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3675
    "return the inverse hyperbolic sine of the receiver."
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3676
    "caveat: misnomer; should be called aSinh or arSinh"
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3677
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3678
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3679
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3680
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3681
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3682
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3683
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3684
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3685
            ^ f arcSinh.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3686
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3687
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3688
    "/ slow fallback
25086
64b5d6493613 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 25085
diff changeset
  3689
    ^ ( self + (self squared+1) sqrt ) ln
22730
d9060b5c2b4a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22727
diff changeset
  3690
    "/    ^ self arcSinh_withAccuracy:self epsilon
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3691
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3692
    "Modified: / 05-07-2017 / 17:25:38 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3693
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3694
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3695
arcTan
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3696
    "return the arctangent of the receiver (as radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3697
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3698
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3699
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3700
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3701
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3702
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3703
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3704
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3705
            ^ f arcTan.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3706
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3707
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3708
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  3709
    ^ self arcTan_withAccuracy:self epsilon
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3710
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3711
    "Modified: / 05-07-2017 / 17:25:46 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3712
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3713
11488
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  3714
arcTan2:x
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  3715
    "return atan2(self,x) (as radians)"
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  3716
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3717
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3718
    "/ retry after converting to float
11488
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  3719
    (self isLimitedPrecisionReal not
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  3720
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3721
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3722
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3723
        (f := self asFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3724
            ^ f arcTan2:x.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3725
        ].
11488
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  3726
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3727
    "/ very slow fallback
11488
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  3728
    ^ self arcTan2_withAccuracy:self epsilon x:x
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3729
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3730
    "Modified: / 05-07-2017 / 17:26:16 / cg"
11488
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  3731
!
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  3732
22727
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3733
arcTan:denominator
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3734
    "Evaluate the four quadrant arc tangent of the argument denominator (x) and the receiver (y)."
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3735
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3736
    |t|
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3737
    
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3738
    (self isZero) ifTrue: [
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3739
        (denominator strictlyPositive)
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3740
            ifTrue: [ ^ 0 ]
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3741
            ifFalse: [ ^ self class pi ]
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3742
    ].
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3743
    (denominator isZero) ifTrue: [
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3744
        (self strictlyPositive)
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3745
            ifTrue: [ ^ self class halfpi ]
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3746
            ifFalse: [ ^ self class halfpiNegative ]
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3747
    ].
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3748
    t := (self / denominator) arcTan.
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3749
    (denominator strictlyPositive)
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3750
        ifTrue: [ ^ t ]
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3751
        ifFalse: [ ^ t + self class pi ]
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3752
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3753
    "Created: / 07-06-2007 / 21:10:32 / cg"
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3754
    "Modified: / 11-06-2007 / 12:58:34 / cg"
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3755
!
c5c0850734f3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22543
diff changeset
  3756
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3757
arcTanh
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3758
    "return the inverse hyperbolic tangent of the receiver."
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3759
    "caveat: misnomer; should be called aTanh or arTanh"
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3760
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3761
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3762
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3763
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3764
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3765
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3766
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3767
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3768
            ^ f arcTanh.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3769
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3770
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3771
    "/ slow fallback
19768
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3772
    ^ ((1 + self) / (1 - self)) ln / 2
55e36a939e1e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19702
diff changeset
  3773
    "/ s^ ((1 + self) ln / 2) - ((1 - self) ln / 2)
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3774
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3775
    "Modified: / 05-07-2017 / 17:26:27 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3776
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3777
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3778
cos
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3779
    "return the cosine of the receiver (interpreted as radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3780
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3781
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3782
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3783
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3784
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3785
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3786
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3787
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3788
            ^ f cos.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3789
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3790
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3791
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  3792
    ^ self cos_withAccuracy:self epsilon
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3793
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3794
    "Modified: / 05-07-2017 / 17:26:33 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3795
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3796
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3797
cosh
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3798
    "return the hyperbolic cosine of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3799
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3800
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3801
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3802
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3803
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3804
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3805
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3806
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3807
            ^ f cosh.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3808
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3809
    ].
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3810
    "/ very slow fallback
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  3811
    ^ self cosh_withAccuracy:self epsilon
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3812
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3813
    "Modified: / 05-07-2017 / 17:26:39 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3814
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3815
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  3816
cot
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  3817
    "return the cotangent of the receiver"
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  3818
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  3819
    ^ 1 / self tan
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  3820
!
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  3821
24896
421293afdb60 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24869
diff changeset
  3822
csc
421293afdb60 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24869
diff changeset
  3823
    "return the cosecant of the receiver (interpreted as radians)"
421293afdb60 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24869
diff changeset
  3824
421293afdb60 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24869
diff changeset
  3825
    ^ 1 / self sin
421293afdb60 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24869
diff changeset
  3826
!
421293afdb60 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24869
diff changeset
  3827
421293afdb60 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24869
diff changeset
  3828
sec
421293afdb60 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24869
diff changeset
  3829
    "return the secant of the receiver (interpreted as radians)"
421293afdb60 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24869
diff changeset
  3830
421293afdb60 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24869
diff changeset
  3831
    ^ 1 / self cos
421293afdb60 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24869
diff changeset
  3832
!
421293afdb60 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24869
diff changeset
  3833
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3834
sin
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3835
    "return the sine of the receiver (interpreted as radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3836
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3837
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3838
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3839
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3840
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3841
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3842
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3843
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3844
            ^ f sin.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3845
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3846
    ].
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  3847
    ^ self sin_withAccuracy:self epsilon
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3848
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3849
    "Modified: / 05-07-2017 / 17:26:47 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3850
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3851
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3852
sinh
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3853
    "return the hyperbolic sine of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3854
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3855
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3856
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3857
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3858
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3859
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3860
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3861
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3862
            ^ f sinh.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3863
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3864
    ].
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  3865
    ^ self sinh_withAccuracy:self epsilon
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3866
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3867
    "
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3868
        10 sinh                     -> 11013.23287470339338
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3869
        (10 exp - (-10 exp)) / 2    -> 11013.23287470339338
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3870
    "
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3871
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3872
    "Modified (comment): / 05-07-2017 / 17:32:27 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3873
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3874
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3875
tan
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3876
    "return the tangens of the receiver (interpreted as radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3877
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3878
    "/ slow fallback
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3879
    ^ self sin / self cos
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3880
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3881
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3882
tanh
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3883
    "return the hyperbolic tangens of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3884
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3885
    "/ tanh is:
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3886
    "/      sinh(x)
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3887
    "/      -------
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3888
    "/      cosh(x)
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3889
    "/
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3890
    "/ which is:
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3891
    "/      (exp(x) - exp(-x)) / 2
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3892
    "/      ----------------------
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3893
    "/      (exp(x) + exp(-x)) / 2
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3894
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3895
    |exp nexp|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3896
    
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3897
    "/ if I am not a Float (or a less general lpReal),
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3898
    "/ retry after converting to float
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3899
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3900
    or:[self generality < 1.0 generality]) ifTrue:[
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3901
        |f|
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3902
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3903
        (f := self asLongFloat) isFinite ifTrue:[
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3904
            ^ f tanh.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3905
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3906
    ].
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3907
19769
57962c690836 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19768
diff changeset
  3908
    "/ very slow fallback
21988
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3909
    "/ assuming that if we arrive here, the stuff is taylor computed manually anyway,
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3910
    "/ the question is if taylor-for-exp converges faster than tailor-for-sin/cos
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3911
    "/ So it may be faster to:
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3912
    "/      ^ self sinh / self cosh
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3913
    
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3914
    exp := self exp.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3915
    nexp := self negated exp.
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3916
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3917
    ^ (exp - nexp) / (exp + nexp)
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3918
e3f286797775 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21982
diff changeset
  3919
    "Modified (comment): / 05-07-2017 / 17:34:59 / cg"
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3920
! !
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  3921
24158
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3922
!Number methodsFor:'trigonometric (degrees)'!
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3923
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3924
degreeCos
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3925
    "Return the cosine of the receiver taken as an angle in degrees."
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3926
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3927
    ^ self degreesToRadians cos
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3928
!
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3929
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3930
degreeSin
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3931
    "Return the sine of the receiver taken as an angle in degrees."
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3932
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3933
    ^ self degreesToRadians sin
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3934
!
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3935
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3936
degreeTan
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3937
    "Return the cosine of the receiver taken as an angle in degrees."
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3938
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3939
    ^ self degreesToRadians tan
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3940
! !
fb63564d89d8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24157
diff changeset
  3941
5552
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5360
diff changeset
  3942
!Number methodsFor:'truncation & rounding'!
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  3943
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3944
detentBy: detent atMultiplesOf: grid snap: snap
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3945
    "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
  3946
     to that multiple.
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3947
     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
  3948
     in the dead zone will never be returned.
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3949
     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
  3950
     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
  3951
     and scale the value by that factor."
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3952
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3953
    | r1 r2 |
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3954
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3955
    r1 := self roundTo: grid.                    "Nearest multiple of grid"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3956
    (self roundTo: detent) = r1 ifTrue: [^ r1].  "Snap to that multiple..."
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3957
    snap ifTrue: [^ self].                       "...or return self"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3958
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3959
    r2 := self < r1                               "Nearest end of dead zone"
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3960
	    ifTrue: [r1 - (detent asFloat/2)]
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3961
	    ifFalse: [r1 + (detent asFloat/2)].
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3962
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3963
    "Scale values between dead zones to fill range between multiples"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3964
    ^ r1 + ((self - r2) * grid asFloat / (grid - detent))
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3965
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3966
    "
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  3967
     (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
  3968
     (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
  3969
     (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
  3970
     (-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
  3971
    "
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3972
!
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  3973
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  3974
fractionPart
25051
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  3975
    "return a number with value from digits after the decimal point.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3976
     i.e. the receiver minus its truncated value,
25051
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  3977
     such that (self truncated + self fractionPart) = self
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  3978
     Floats will return an inexact float; fractions will return a fraction"
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  3979
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3980
    ^ self - self truncated
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  3981
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  3982
    "
24996
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  3983
     1234.56789 fractionPart -- beware rounding errors in floats
25051
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  3984
     1.2345e0 fractionPart    
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  3985
     1.2345e1 fractionPart  
24996
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  3986
     1.2345e6 fractionPart  
25051
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  3987
     (16/10) fractionPart    
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  3988
     (8/9) fractionPart    
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  3989
     (11/9) fractionPart    
24996
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  3990
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  3991
     1.6 asLongFloat fractionPart + 1.6 asLongFloat truncated  -- beware rounding errors in floats 
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  3992
     -1.6 asLongFloat fractionPart + -1.6 asLongFloat truncated -1.600000000000000089
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  3993
     (16/10) fractionPart + (16/10) truncated -> 16/10
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  3994
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  3995
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  3996
    "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
  3997
    "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
  3998
!
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  3999
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  4000
integerPart
25051
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  4001
    "return a number with value from digits before the decimal point.
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  4002
     (i.e. the value truncated towards zero)
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  4003
     such that (self integerPart + self fractionPart) = self
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  4004
     Floats will return an inexact float; fractions will return an exact integer.
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  4005
     "
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  4006
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  4007
    ^ self truncated
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  4008
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  4009
    "
24996
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  4010
     1234.56789 integerPart  
20308
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  4011
     1.2345e6 integerPart
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  4012
     12.5 integerPart
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  4013
     -12.5 integerPart
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  4014
     (5/3) integerPart
9110f117d260 ALIGNMENT code clean up
Claus Gittinger <cg@exept.de>
parents: 20142
diff changeset
  4015
     (-5/3) integerPart
25051
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  4016
     (5/3) truncated        
137cfc9c2e83 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 25041
diff changeset
  4017
     (-5/3) truncated 
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  4018
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  4019
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  4020
    "Created: / 28.10.1998 / 17:14:56 / cg"
6154
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  4021
    "Modified: / 5.11.2001 / 17:54:22 / cg"
23323
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4022
!
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4023
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4024
rounded:n
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4025
    "Answer the float rounded with n digits of precision"
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4026
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4027
    | mult |
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4028
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4029
    mult := 10 raisedTo: n.
24996
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  4030
    ^ (((self * mult) rounded) asLimitedPrecisionReal / mult).
23323
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4031
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4032
    "
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4033
     7 rounded:2
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4034
     7.1 rounded:2
24996
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  4035
     7.2345 rounded:2  -> 7.23 
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  4036
     7.2385 rounded:2  -> 7.24 
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  4037
     7.2341 rounded:3  -> 7.234
23323
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4038
     7.2345 rounded:3
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4039
     7.2348 rounded:3
24996
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  4040
     (1/3) rounded:3   -> 0.333
79c4c3430535 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24988
diff changeset
  4041
     (2/3) rounded:3   -> 0.667
23323
fbc7256b2b0c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23322
diff changeset
  4042
    "
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  4043
! !
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  4044
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  4045
!Number class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4046
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4047
version
18850
172da07a4529 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18320
diff changeset
  4048
    ^ '$Header$'
12112
949f9713c4a5 changed: #readFrom:decimalPointCharacters:onError:
Claus Gittinger <cg@exept.de>
parents: 11944
diff changeset
  4049
!
949f9713c4a5 changed: #readFrom:decimalPointCharacters:onError:
Claus Gittinger <cg@exept.de>
parents: 11944
diff changeset
  4050
949f9713c4a5 changed: #readFrom:decimalPointCharacters:onError:
Claus Gittinger <cg@exept.de>
parents: 11944
diff changeset
  4051
version_CVS
18850
172da07a4529 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18320
diff changeset
  4052
    ^ '$Header$'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  4053
! !
15078
997a122ceeb5 class: Number
Stefan Vogel <sv@exept.de>
parents: 14495
diff changeset
  4054