Number.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 15 Jun 2009 20:55:05 +0100
branchjv
changeset 17711 39faaaf888b4
parent 11770 37bd8fc58d59
child 17732 a1892eeca6c0
permissions -rw-r--r--
Added branch jv
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
5360
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
    12
"{ Package: 'stx:libbasic' }"
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
    13
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    14
ArithmeticValue subclass:#Number
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
    15
	instanceVariableNames:''
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
    16
	classVariableNames:'DecimalPointCharacter DecimalPointCharacterForPrinting
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
    17
		DecimalPointCharacters DecimalPointCharactersForReading'
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
    18
	poolDictionaries:''
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
    19
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    22
!Number class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    23
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    26
 COPYRIGHT (c) 1988 by Claus Gittinger
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
    27
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    28
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    36
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    37
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    38
documentation
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    40
    abstract superclass for all kinds of numbers
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    41
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
    42
    [class variables:]
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
    43
        DecimalPointCharacterForPrinting          <Character>                     used when printing
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
    44
        DecimalPointCharactersForReading          <Collection of Character>       accepted as decimalPointChars when reading
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
    45
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
    46
    [author:]
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
    47
        Claus Gittinger
1628
da30f2f41db7 comment
Claus Gittinger <cg@exept.de>
parents: 1557
diff changeset
    48
da30f2f41db7 comment
Claus Gittinger <cg@exept.de>
parents: 1557
diff changeset
    49
    [see also:]
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
    50
        Integer LargeInteger SmallInteger
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
    51
        LimitedPrecisionReal Float ShortFloat
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
    52
        Fraction FixedPoint
88
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    53
"
81dacba7a63a *** empty log message ***
claus
parents: 56
diff changeset
    54
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    55
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    56
!Number class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    57
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    58
fromString:aString
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    59
    "for compatibility with other smalltalks - same as #readFrom:"
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    60
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    61
    ^ self
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    62
        fromString:aString
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    63
        decimalPointCharacters:(self decimalPointCharactersForReading) 
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    64
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    65
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    66
     Number fromString:'12345'
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    67
     Number fromString:'abc'
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    68
     Number fromString:'1abc'
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    69
     '12345' asNumber
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    70
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    71
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    72
    "Modified: / 3.8.1998 / 20:05:11 / cg"
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    73
!
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    74
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    75
fromString:aString decimalPointCharacters:decimalPointCharacters
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    76
    "for compatibility with other smalltalks - same as #readFrom:"
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    77
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    78
    |s num|
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    79
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    80
    s := aString readStream.
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    81
    num := self readFrom:s decimalPointCharacters:decimalPointCharacters onError:[^ self error:'invalid number'].
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    82
    s atEnd ifFalse:[^ self error:'garbage at end of number'].
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    83
    ^ num.
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    84
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    85
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    86
     Number fromString:'12345'
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    87
     Number fromString:'abc'
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
    88
     Number fromString:'1abc'
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    89
     '12345' asNumber
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    90
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    91
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
    92
    "Modified: / 3.8.1998 / 20:05:11 / cg"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    93
!
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    94
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    95
fromString:aString decimalPointCharacters:decimalPointCharacters onError:exceptionBlock
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    96
    "for compatibility with other smalltalks - same as #readFrom:"
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    97
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    98
    ^ self readFrom:aString decimalPointCharacters:decimalPointCharacters onError:exceptionBlock
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
    99
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   100
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   101
     Number fromString:'12345' onError:0
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   102
     Number fromString:'fooBarBaz' onError:0
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   103
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   104
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   105
    "Modified: / 3.8.1998 / 20:05:34 / cg"
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   106
!
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   107
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   108
fromString:aString onError:exceptionBlock
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   109
    "for compatibility with other smalltalks - same as #readFrom:"
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   110
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   111
    ^ self readFrom:aString onError:exceptionBlock
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   112
3716
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   113
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   114
     Number fromString:'12345' onError:0
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   115
     Number fromString:'fooBarBaz' onError:0
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   116
    "
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   117
e7904bd50d9d comment
Claus Gittinger <cg@exept.de>
parents: 3634
diff changeset
   118
    "Modified: / 3.8.1998 / 20:05:34 / cg"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   119
!
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   120
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   121
readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters 
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   122
    "return the next Number from the (character-)stream aStream;
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   123
     skipping all whitespace first; return the value of exceptionBlock,
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   124
     if no number can be read.
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   125
     This method is less strict than the smalltalk number reader; it
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   126
     allows for prefixed + and also allows missing fractional part after eE"
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   127
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   128
    ^ self
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   129
        readFrom:aStringOrStream 
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   130
        decimalPointCharacters:decimalPointCharacters 
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   131
        onError:[self error:'conversion error for: ' , self name]
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   132
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   133
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   134
     Number readFrom:'123.456' decimalPointCharacters:'.'      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   135
     Number readFrom:'123,456' decimalPointCharacters:'.,'     
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   136
     Number readFrom:'123,456' decimalPointCharacters:'.'     
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   137
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   138
!
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   139
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   140
readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters onError:exceptionBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   141
    "return the next Number from the (character-)stream aStream;
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   142
     skipping all whitespace first; return the value of exceptionBlock,
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   143
     if no number can be read.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   144
     This method is less strict than the smalltalk number reader; it
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   145
     allows for prefixed + and also allows missing fractional part after eE"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   146
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   147
    ^ [
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   148
        |value intValue mantissaAndScale scale decimalMantissa str 
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   149
         nextChar radix negative signExp exp denom|
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
   150
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   151
        str := aStringOrStream readStream.
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   152
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   153
        nextChar := str skipSeparators.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   154
        nextChar isNil ifTrue:[^ exceptionBlock value].
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   155
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   156
        (nextChar == $-) ifTrue:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   157
            negative := true.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   158
            str next.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   159
            nextChar := str peekOrNil
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   160
        ] ifFalse:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   161
            negative := false.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   162
            (nextChar == $+) ifTrue:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   163
                str next.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   164
                nextChar := str peekOrNil
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   165
            ]
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   166
        ].
11526
474c8ba65e7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11488
diff changeset
   167
        nextChar isNil ifTrue:[^ exceptionBlock value].    
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   168
        (nextChar isDigit or:[(decimalPointCharacters includes:nextChar)]) ifFalse:[
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   169
            ^ exceptionBlock value.
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   170
"/          value := super readFrom:str.
339
claus
parents: 329
diff changeset
   171
"/          negative ifTrue:[value := value negated].
claus
parents: 329
diff changeset
   172
"/          ^ value
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   173
        ].
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   174
        (decimalPointCharacters includes:nextChar) ifTrue:[
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   175
            radix := 10.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   176
            value := 0.0.
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   177
            intValue := 0.
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   178
        ] ifFalse:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   179
            value := Integer readFrom:str radix:10.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   180
            nextChar := str peekOrNil.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   181
            ((nextChar == $r) or:[ nextChar == $R]) ifTrue:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   182
                str next.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   183
                radix := value.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   184
                value := Integer readFrom:str radix:radix.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   185
            ] ifFalse:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   186
                radix := 10
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   187
            ].
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   188
            intValue := value.
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   189
        ].
4637
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4558
diff changeset
   190
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   191
        (decimalPointCharacters includes:nextChar) ifTrue:[
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   192
            str next.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   193
            nextChar := str peekOrNil.
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   194
            decimalMantissa := 0.
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   195
            (nextChar notNil and:[nextChar isDigitRadix:radix]) ifTrue:[
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   196
                mantissaAndScale := Number readMantissaAndScaleFrom:str radix:radix.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   197
                value := value asFloat + (mantissaAndScale first).
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   198
                nextChar := str peekOrNil
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   199
            ]
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   200
        ].
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   201
        ('eEdDqQ' includes:nextChar) ifTrue:[
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   202
            str next.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   203
            nextChar := str peekOrNil.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   204
            signExp := 1.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   205
            (nextChar == $+) ifTrue:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   206
                str next.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   207
                nextChar := str peekOrNil.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   208
            ] ifFalse:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   209
                (nextChar == $-) ifTrue:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   210
                    str next.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   211
                    nextChar := str peekOrNil.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   212
                    signExp := -1
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   213
                ]
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   214
            ].
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   215
            ('qQ' includes:nextChar) ifTrue:[
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   216
                value := value asLongFloat.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   217
            ] ifFalse:[
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   218
                value := value asFloat.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   219
"/ future: (for now, always create Doubles for Dolphin,Squeak etc. compatibility
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   220
"/                ('eE' includes:nextChar) ifTrue:[
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   221
"/                    value := value asShortFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   222
"/                ]
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   223
            ].
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   224
            (nextChar notNil and:[(nextChar isDigitRadix:radix)]) ifTrue:[
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   225
                exp := (Integer readFrom:str radix:radix) * signExp.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   226
                value := value * ((value class unity * 10.0) raisedToInteger:exp)
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   227
            ]
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   228
        ] ifFalse:[
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   229
            ('s' includes:nextChar) ifTrue:[
9130
07e7a292aa76 fixedPoint reading fixed (explicit scale)
Claus Gittinger <cg@exept.de>
parents: 9127
diff changeset
   230
                str next.
07e7a292aa76 fixedPoint reading fixed (explicit scale)
Claus Gittinger <cg@exept.de>
parents: 9127
diff changeset
   231
07e7a292aa76 fixedPoint reading fixed (explicit scale)
Claus Gittinger <cg@exept.de>
parents: 9127
diff changeset
   232
                nextChar := str peekOrNil.
9138
a43f3145527f fixedPoint reading
Claus Gittinger <cg@exept.de>
parents: 9130
diff changeset
   233
                (nextChar notNil and:[ nextChar isDigit]) ifTrue:[
a43f3145527f fixedPoint reading
Claus Gittinger <cg@exept.de>
parents: 9130
diff changeset
   234
                    scale := (Integer readFrom:str).
9130
07e7a292aa76 fixedPoint reading fixed (explicit scale)
Claus Gittinger <cg@exept.de>
parents: 9127
diff changeset
   235
                ].
07e7a292aa76 fixedPoint reading fixed (explicit scale)
Claus Gittinger <cg@exept.de>
parents: 9127
diff changeset
   236
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   237
                mantissaAndScale isNil ifTrue:[
9130
07e7a292aa76 fixedPoint reading fixed (explicit scale)
Claus Gittinger <cg@exept.de>
parents: 9127
diff changeset
   238
                    value := intValue asFixedPoint:(scale ? 0).
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   239
                ] ifFalse:[
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   240
                    denom := 10 raisedTo:mantissaAndScale last.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   241
                    value := FixedPoint 
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   242
                                numerator:(intValue * denom) + (mantissaAndScale second)
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   243
                                denominator:denom
9130
07e7a292aa76 fixedPoint reading fixed (explicit scale)
Claus Gittinger <cg@exept.de>
parents: 9127
diff changeset
   244
                                scale:(scale ? mantissaAndScale last).
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   245
                ].
7456
42a1cbc55b6c care to not always return longFloats
Claus Gittinger <cg@exept.de>
parents: 7451
diff changeset
   246
            ] ifFalse:[
42a1cbc55b6c care to not always return longFloats
Claus Gittinger <cg@exept.de>
parents: 7451
diff changeset
   247
                value isLimitedPrecisionReal ifTrue:[
42a1cbc55b6c care to not always return longFloats
Claus Gittinger <cg@exept.de>
parents: 7451
diff changeset
   248
                    value := value asFloat.
42a1cbc55b6c care to not always return longFloats
Claus Gittinger <cg@exept.de>
parents: 7451
diff changeset
   249
                ]
42a1cbc55b6c care to not always return longFloats
Claus Gittinger <cg@exept.de>
parents: 7451
diff changeset
   250
            ].
6632
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   251
        ].
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   252
        negative ifTrue:[
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   253
            value := value negated
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   254
        ].
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   255
        value.
65014fd967d9 Avoid creation of block in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents: 6584
diff changeset
   256
    ] on:Error do:exceptionBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   257
329
claus
parents: 325
diff changeset
   258
    "
claus
parents: 325
diff changeset
   259
     Number readFrom:(ReadStream on:'54.32e-01')      
claus
parents: 325
diff changeset
   260
     Number readFrom:(ReadStream on:'12345678901234567890') 
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   261
     Number readFrom:(ReadStream on:'12345678901234567890.0') 
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   262
     Number readFrom:(ReadStream on:'12345678901234567890.012345678901234567890') 
329
claus
parents: 325
diff changeset
   263
     Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF') 
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   264
     Number readFrom:'16rAAAAFFFFAAAAFFFF' 
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   265
     Number readFrom:'0.000001'  
329
claus
parents: 325
diff changeset
   266
     '+00000123.45' asNumber  
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   267
     Number readFrom:'99s'      
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   268
     Number readFrom:'99.00s'      
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   269
     Number readFrom:'99.0000000s'      
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   270
     Number readFrom:'.0000000s'      
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   271
     Number readFrom:'.0000000q'      
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   272
     Number readFrom:'.0000000f'      
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   273
     Number readFrom:'.0000000e'      
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   274
     Number readFrom:'.0000000s1'      
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   275
     Number readFrom:'.0000000q1'      
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   276
     Number readFrom:'.0000000f1'      
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   277
     Number readFrom:'.0000000e1'      
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   278
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   279
     DecimalPointCharactersForReading := #( $. $, ).   
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   280
     Number readFrom:'99,00'      
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   281
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   282
     DecimalPointCharactersForReading := #( $. ).   
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   283
     Number readFrom:'99,00'      
329
claus
parents: 325
diff changeset
   284
    "
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   285
3375
7c64da3964e4 faster conversion from string (due to slow #pastEnd)
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
   286
    "Modified: / 14.4.1998 / 19:22:50 / cg"
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   287
!
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   288
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   289
readFrom:aStringOrStream onError:exceptionBlock
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   290
    "return the next Number from the (character-)stream aStream;
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   291
     skipping all whitespace first; return the value of exceptionBlock,
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   292
     if no number can be read.
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   293
     This method is less strict than the smalltalk number reader; it
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   294
     allows for prefixed + and also allows missing fractional part after eE"
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   295
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   296
    ^ self 
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   297
        readFrom:aStringOrStream 
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   298
        decimalPointCharacters:(self decimalPointCharactersForReading) 
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   299
        onError:exceptionBlock
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   300
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   301
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   302
     Number readFrom:(ReadStream on:'54.32e-01')      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   303
     Number readFrom:(ReadStream on:'12345678901234567890') 
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   304
     Number readFrom:(ReadStream on:'12345678901234567890.0') 
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   305
     Number readFrom:(ReadStream on:'12345678901234567890.012345678901234567890') 
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   306
     Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF') 
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   307
     Number readFrom:'16rAAAAFFFFAAAAFFFF' 
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   308
     Number readFrom:'0.000001'  
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   309
     '+00000123.45' asNumber  
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   310
     Number readFrom:'99s'      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   311
     Number readFrom:'99.00s'      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   312
     Number readFrom:'99.0000000s'      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   313
     Number readFrom:'.0000000s'      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   314
     Number readFrom:'.0000000q'      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   315
     Number readFrom:'.0000000f'      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   316
     Number readFrom:'.0000000e'      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   317
     Number readFrom:'.0000000s1'      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   318
     Number readFrom:'.0000000q1'      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   319
     Number readFrom:'.0000000f1'      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   320
     Number readFrom:'.0000000e1'      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   321
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   322
     DecimalPointCharactersForReading := #( $. $, ).   
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   323
     Number readFrom:'99,00'      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   324
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   325
     DecimalPointCharactersForReading := #( $. ).   
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   326
     Number readFrom:'99,00'      
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   327
    "
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   328
!
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   329
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   330
readSmalltalkSyntaxFrom:aStream
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   331
    "ST-80 compatibility (thanks to a note from alpha testers)
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   332
     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
   333
     (character-) aStream.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   334
     Returns nil if aStream contains no valid number."
329
claus
parents: 325
diff changeset
   335
3613
75629df7f224 fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents: 3394
diff changeset
   336
    ^ Scanner scanNumberFrom:aStream
75629df7f224 fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents: 3394
diff changeset
   337
"/    ^ Compiler evaluate:aStream compile:false "/ self readFrom:aStream.
296
754358c5508a *** empty log message ***
claus
parents: 293
diff changeset
   338
329
claus
parents: 325
diff changeset
   339
    "
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   340
     Number readSmalltalkSyntaxFrom:'99d'    
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   341
     Number readSmalltalkSyntaxFrom:'99.00d'    
329
claus
parents: 325
diff changeset
   342
     Number readSmalltalkSyntaxFrom:(ReadStream on:'54.32e-01')    
claus
parents: 325
diff changeset
   343
     Number readSmalltalkSyntaxFrom:(ReadStream on:'12345678901234567890')
claus
parents: 325
diff changeset
   344
     Number readSmalltalkSyntaxFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
claus
parents: 325
diff changeset
   345
     Number readSmalltalkSyntaxFrom:(ReadStream on:'(1/10)') 
claus
parents: 325
diff changeset
   346
     Number readFrom:(ReadStream on:'(1/10)') 
claus
parents: 325
diff changeset
   347
     Number readSmalltalkSyntaxFrom:(ReadStream on:'+00000123.45')  
claus
parents: 325
diff changeset
   348
     Number readFrom:(ReadStream on:'+00000123.45')  
5013
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   349
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   350
     |s|
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   351
     s := ReadStream on:'2.'.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   352
     Number readSmalltalkSyntaxFrom:s.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   353
     s next    
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   354
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   355
     |s|
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   356
     s := ReadStream on:'2.0.'.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   357
     Number readSmalltalkSyntaxFrom:s.
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   358
     s next    
329
claus
parents: 325
diff changeset
   359
    "
3613
75629df7f224 fixed readSmalltalkSyntax (dont read behind number)
Claus Gittinger <cg@exept.de>
parents: 3394
diff changeset
   360
5013
e2aff65e6eba comment
Claus Gittinger <cg@exept.de>
parents: 4988
diff changeset
   361
    "Modified: / 19.11.1999 / 18:26:47 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   362
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   363
11712
b83c3734b1ce added #degreeTan
sr
parents: 11660
diff changeset
   364
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
   365
!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
   366
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   367
decimalPointCharacter 
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   368
    "printed"
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   369
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   370
    <resource: #obsolete>
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   371
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   372
    ^ self decimalPointCharacterForPrinting
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   373
!
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   374
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   375
decimalPointCharacter:aCharacter 
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   376
    "printed"
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   377
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   378
    <resource: #obsolete>
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   379
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   380
    self decimalPointCharacterForPrinting:aCharacter
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   381
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   382
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   383
     1.5 printString
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   384
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   385
     Number decimalPointCharacter:$,.
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   386
     1.5 printString       
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   387
     Number decimalPointCharacter:$..
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   388
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   389
!
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   390
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   391
decimalPointCharacterForPrinting 
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   392
    "printed"
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   393
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   394
    DecimalPointCharacterForPrinting isNil ifTrue:[
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   395
        ^ $.
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   396
    ].
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   397
    ^ DecimalPointCharacterForPrinting
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   398
!
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   399
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   400
decimalPointCharacterForPrinting:aCharacter 
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   401
    "printed"
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   402
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   403
    DecimalPointCharacterForPrinting := aCharacter
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   404
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   405
    "
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   406
     1.5 printString
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   407
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
   408
     Number decimalPointCharacterForPrinting:$,.
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   409
     1.5 printString       
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
   410
     Number decimalPointCharacterForPrinting:$..
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   411
    "
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   412
!
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   413
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   414
decimalPointCharacters 
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   415
    "accepted when converting from a string"
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   416
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   417
    <resource: #obsolete>
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   418
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   419
    ^ self decimalPointCharactersForReading
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   420
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   421
    "
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   422
     1.5 printString
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   423
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   424
     Number decimalPointCharacters:#( $. $,) .
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   425
     Number fromString:'1.5'.     
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   426
     Number fromString:'1,5'.     
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   427
     Number decimalPointCharacters:#( $. ).
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   428
    "
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   429
!
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   430
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   431
decimalPointCharacters:aCollectionOfCharacters 
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   432
    "accepted when converting from a string"
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   433
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   434
    <resource: #obsolete>
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   435
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   436
    self decimalPointCharactersForReading:aCollectionOfCharacters 
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   437
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   438
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   439
     Number decimalPointCharacters:#( $. $,) .
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   440
     Number fromString:'1.5'.     
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   441
     Number fromString:'1,5'.     
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   442
     Number decimalPointCharacters:#( $. ).
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   443
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   444
!
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   445
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   446
decimalPointCharactersForReading 
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   447
    "default when converting from a string"
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   448
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   449
    "/ cg: changing the default leads to trouble in some
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   450
    "/ language processors (PrologScanner...)
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   451
    "/ 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
   452
    "/ BETTER: pass the DecimalPointCharacterSet explicitly
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   453
    DecimalPointCharactersForReading isNil ifTrue:[
9333
c1d712705426 decimalPointCharacter stuff
Claus Gittinger <cg@exept.de>
parents: 9274
diff changeset
   454
        ^ #( $. )
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   455
    ].
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   456
    ^ DecimalPointCharactersForReading
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   457
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   458
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   459
     1.5 printString
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   460
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
   461
     Number decimalPointCharactersForReading:#( $. $,) .
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   462
     Number fromString:'1.5'.     
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   463
     Number fromString:'1,5'.     
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
   464
     Number decimalPointCharactersForReading:#( $. ).
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   465
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   466
!
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   467
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   468
decimalPointCharactersForReading:aCollectionOfCharacters 
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   469
    "accepted when converting from a string"
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   470
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   471
    DecimalPointCharactersForReading := aCollectionOfCharacters
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   472
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   473
    "
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
   474
     Number decimalPointCharactersForReading:#( $. $,) .
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   475
     Number fromString:'1.5'.     
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   476
     Number fromString:'1,5'.     
9274
f3b231fb2ef7 comments
Claus Gittinger <cg@exept.de>
parents: 9140
diff changeset
   477
     Number decimalPointCharactersForReading:#( $. ).
8303
837daadaab78 decimalPointCharacter definition
werner
parents: 8301
diff changeset
   478
    "
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   479
!
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
   480
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
   481
epsilon
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
   482
    "return the maximum relative spacing of instances of mySelf 
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
   483
     (i.e. the value-delta of the least significant bit)"
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
   484
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
   485
     ^ self subclassResponsibility
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
   486
!
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
   487
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   488
epsilonForCloseTo
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   489
    "return the epsilon used in the closeTo: comparison.
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   490
     (useful would be something like self epsilon or epsilon*10,
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   491
      but for Squeak compatibility.... - sigh)"
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   492
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   493
    ^ 0.0001
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   494
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   495
    "
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   496
     Float epsilon     
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   497
     ShortFloat epsilon 
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   498
     Float epsilon10    
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   499
     ShortFloat epsilon10
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   500
    "
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   501
!
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   502
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
   503
pi
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
   504
    "return Pi in my representation (and accuracy)."
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
   505
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
   506
     ^ self subclassResponsibility
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
   507
! !
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
   508
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   509
!Number class methodsFor:'error reporting'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   510
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   511
raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel arg:arg errorString:text 
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   512
    "ST-80 compatible signal raising. Provided for PD numeric classes"
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   513
4558
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   514
    <context: #return>
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   515
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   516
    ^ self
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   517
        raise:aSignalSymbolOrErrorClass 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   518
        receiver:someNumber 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   519
        selector:sel 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   520
        arguments:(Array with:arg)
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   521
        errorString:text 
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   522
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   523
    "
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   524
     Number 
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   525
        raise:#domainErrorSignal
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   526
        receiver:1.0
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   527
        selector:#sin
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   528
        arg:nil
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   529
        errorString:'foo bar test'
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   530
    "
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   531
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   532
    "Modified: / 16.11.2001 / 14:12:50 / cg"
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   533
!
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   534
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   535
raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel arguments:argArray errorString:text 
6194
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   536
    "ST-80 compatible signal raising. Provided for PD numeric classes.
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   537
     aSignalSymbolOrErrorClass is either an Error-subclass, or
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   538
     the selector which is sent to myself, to retrieve the Exception class / Signal."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   539
4558
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   540
    <context: #return>
94044dccefab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   541
6194
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   542
    |msg signalOrException|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   543
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   544
    msg := MessageSend
6194
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   545
                receiver:someNumber
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   546
                selector:sel
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   547
                arguments:argArray.
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   548
6194
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   549
    aSignalSymbolOrErrorClass isSymbol ifTrue:[
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   550
        signalOrException := self perform:aSignalSymbolOrErrorClass.
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   551
    ] ifFalse:[
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   552
        signalOrException := aSignalSymbolOrErrorClass.    "/ assume its an Error-Subclass
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   553
    ].
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   554
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   555
    ^ signalOrException
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   556
         raiseRequestWith:msg 
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   557
         errorString:text 
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   558
         in:thisContext sender
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   559
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   560
    "
3394
33e8273b95f3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3375
diff changeset
   561
     Number 
6194
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   562
        raise:#domainErrorSignal
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   563
        receiver:1.0
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   564
        selector:#foo 
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   565
        errorString:'foo bar test'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   566
    "
6194
e060dbb4f75c allow Exception-arg in #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6155
diff changeset
   567
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   568
    "Modified: / 16.11.2001 / 14:12:09 / cg"
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   569
!
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   570
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   571
raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel errorString:text 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   572
    "ST-80 compatible signal raising. Provided for PD numeric classes.
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   573
     aSignalSymbolOrErrorClass is either an Error-subclass, or
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   574
     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
   575
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   576
    <context: #return>
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   577
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   578
    ^ self
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   579
        raise:aSignalSymbolOrErrorClass 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   580
        receiver:someNumber 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   581
        selector:sel 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   582
        arguments:#()
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   583
        errorString:text 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   584
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   585
    "
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   586
     Number 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   587
        raise:#domainErrorSignal
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   588
        receiver:1.0
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   589
        selector:#foo 
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   590
        errorString:'foo bar test'
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   591
    "
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   592
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6194
diff changeset
   593
    "Modified: / 16.11.2001 / 14:13:16 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   594
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   595
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   596
!Number class methodsFor:'private'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   597
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   598
readMantissaAndScaleFrom:aStream radix:radix
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   599
    "helper for readFrom: -
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   600
     return the mantissa (post-decimal-point digits) from the (character-)stream aStream;
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   601
     In addition, the scale (number of postDecimalPoint digits) is returned 
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   602
     (to support reading fixedPoint numbers).
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   603
     No whitespace is skipped.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   604
     Errs if no number is available on aStream."
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   605
10321
c07d199084fc avoid double-send of digitValue
Claus Gittinger <cg@exept.de>
parents: 10320
diff changeset
   606
    |nextChar value factor intMantissa scale digit|
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   607
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   608
    value := 0.0.
10320
a573647dad4f avoid longfloats if possible
Claus Gittinger <cg@exept.de>
parents: 10191
diff changeset
   609
    factor := 1.0 / radix.
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   610
    scale := 0.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   611
    intMantissa := 0.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   612
    nextChar := aStream peekOrNil.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   613
    [nextChar notNil and:[nextChar isDigitRadix:radix]] whileTrue:[
10321
c07d199084fc avoid double-send of digitValue
Claus Gittinger <cg@exept.de>
parents: 10320
diff changeset
   614
        digit := nextChar digitValue.
c07d199084fc avoid double-send of digitValue
Claus Gittinger <cg@exept.de>
parents: 10320
diff changeset
   615
        value := value + (digit * factor).
c07d199084fc avoid double-send of digitValue
Claus Gittinger <cg@exept.de>
parents: 10320
diff changeset
   616
        intMantissa := (intMantissa * radix) + digit.
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   617
        factor := factor / radix.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   618
        scale := scale + 1.
10320
a573647dad4f avoid longfloats if possible
Claus Gittinger <cg@exept.de>
parents: 10191
diff changeset
   619
        scale > 6 ifTrue:[
a573647dad4f avoid longfloats if possible
Claus Gittinger <cg@exept.de>
parents: 10191
diff changeset
   620
            factor := factor asLongFloat.
a573647dad4f avoid longfloats if possible
Claus Gittinger <cg@exept.de>
parents: 10191
diff changeset
   621
            value := value asLongFloat.
a573647dad4f avoid longfloats if possible
Claus Gittinger <cg@exept.de>
parents: 10191
diff changeset
   622
        ].
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   623
        aStream next.
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   624
        nextChar := aStream peekOrNil
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   625
    ].
7388
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   626
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   627
    ^ (Array with:value with:intMantissa with:scale).
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   628
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   629
    "
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   630
     Number readMantissaAndScaleFrom:'234'    readStream radix:10. 
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   631
     Number readMantissaAndScaleFrom:'2'      readStream radix:10. 
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   632
     Number readMantissaAndScaleFrom:'234567' readStream radix:10. 
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   633
     Number readMantissaAndScaleFrom:'234000' readStream radix:10. 
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   634
     Number readMantissaAndScaleFrom:'234'    readStream radix:10. 
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   635
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   636
     Number readMantissaAndScaleFrom:'12345678901234567890' readStream radix:10. 
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   637
    "
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   638
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   639
    "Modified: / 14.4.1998 / 18:47:47 / cg"
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   640
!
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   641
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   642
readMantissaFrom:aStream radix:radix
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   643
    "helper for readFrom: -
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   644
     return the mantissa (post-decimal-point digits)
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   645
     from the (character-)stream aStream;
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   646
     No whitespace is skipped.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   647
     Errs if no number available."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   648
6899
9ed8494c9f10 support for fixedPoint numbers (s-exponentCharacter)
Claus Gittinger <cg@exept.de>
parents: 6702
diff changeset
   649
    ^ (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
   650
6692
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   651
    "
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   652
     Number readMantissaFrom:'234'    readStream radix:10.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   653
     Number readMantissaFrom:'2'      readStream radix:10.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   654
     Number readMantissaFrom:'234567' readStream radix:10.
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   655
    "
314f88dcbbd1 comment
Claus Gittinger <cg@exept.de>
parents: 6637
diff changeset
   656
3375
7c64da3964e4 faster conversion from string (due to slow #pastEnd)
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
   657
    "Modified: / 14.4.1998 / 18:47:47 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   658
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   659
8892
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
   660
!Number class methodsFor:'queries'!
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
   661
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
   662
isAbstract
11224
a9a66cee404f comment
Claus Gittinger <cg@exept.de>
parents: 11136
diff changeset
   663
    "Return if this class is an abstract class.
a9a66cee404f comment
Claus Gittinger <cg@exept.de>
parents: 11136
diff changeset
   664
     True is returned for Number here; false for subclasses.
a9a66cee404f comment
Claus Gittinger <cg@exept.de>
parents: 11136
diff changeset
   665
     Abstract subclasses must redefine again."
a9a66cee404f comment
Claus Gittinger <cg@exept.de>
parents: 11136
diff changeset
   666
8892
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
   667
    ^ self == Number
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
   668
! !
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8844
diff changeset
   669
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7214
diff changeset
   670
!Number methodsFor:'Compatibility-Squeak'!
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   671
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   672
asSmallAngleDegrees
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   673
    "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
   674
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   675
    | pos |
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   676
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   677
    pos := self \\ 360.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   678
    pos > 180 ifTrue: [pos := pos - 360].
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   679
    ^ pos
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   680
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   681
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   682
     #(-500 -300 -150 -5 0 5 150 300 500 1200) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   683
        collect: [:n | n asSmallAngleDegrees]
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   684
    "
6072
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
   685
!
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   686
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   687
closeFrom:aNumber
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   688
    "are these two numbers close?"
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   689
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   690
    ^ self closeFrom:aNumber withEpsilon:(self class epsilonForCloseTo)
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   691
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   692
    "
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   693
     9.0 closeTo: 8.9999     
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   694
     9.9 closeTo: 9          
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   695
     (9/3) closeTo: 2.9999      
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   696
     1 closeTo: 0.9999      
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   697
     1 closeTo: 1.0001      
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   698
     1 closeTo: 1.001       
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   699
     1 closeTo: 0.999       
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   700
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   701
     0.9999 closeTo: 1      
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   702
     1.0001 closeTo: 1      
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   703
     1.001 closeTo: 1     
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   704
     0.999 closeTo: 1
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   705
     Float NaN closeTo:Float NaN
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   706
     Float infinity closeTo:Float infinity
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   707
    "
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   708
!
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   709
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   710
closeFrom:aNumber withEpsilon:eps
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   711
    "are these two numbers close?"
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   712
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   713
    | fuzz |
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   714
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   715
    self isNaN == aNumber isNaN ifFalse: [^ false]. 
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   716
    self isInfinite == aNumber isInfinite ifFalse: [^ false].
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   717
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   718
    fuzz := (self abs max:aNumber abs) * eps. 
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   719
    ^ (self - aNumber) abs <= fuzz
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   720
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   721
    "
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   722
     9.0 closeTo: 8.9999     
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   723
     9.9 closeTo: 9          
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   724
     (9/3) closeTo: 2.9999      
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   725
     1 closeTo: 0.9999      
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   726
     1 closeTo: 1.0001      
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   727
     1 closeTo: 1.001       
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   728
     1 closeTo: 0.999       
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   729
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   730
     0.9999 closeTo: 1      
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   731
     1.0001 closeTo: 1      
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   732
     1.001 closeTo: 1     
6345
cfe5db4fe391 Only comments
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
   733
     0.999 closeTo: 1
cfe5db4fe391 Only comments
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
   734
     Float NaN closeTo:Float NaN
cfe5db4fe391 Only comments
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
   735
     Float infinity closeTo:Float infinity
6335
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   736
    "
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   737
!
8286bc57d05e closeTo: generalized for all numbers
Claus Gittinger <cg@exept.de>
parents: 6258
diff changeset
   738
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   739
closeTo:num
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   740
    "are these two numbers close to each other?"
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   741
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   742
    ^ self closeTo:num withEpsilon:(self class epsilonForCloseTo)
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   743
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   744
    "
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   745
     1 closeTo:1.0000000001 
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   746
     1 closeTo:1.001
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   747
     1 closeTo:1.001 withEpsilon:0.001
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   748
    "
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   749
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   750
    "Created: / 5.11.2001 / 18:07:26 / cg"
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   751
!
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   752
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   753
closeTo:num withEpsilon:eps
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   754
    "are these two numbers close to each other?"
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   755
6374
fad888313ce3 closeTo: fix
Claus Gittinger <cg@exept.de>
parents: 6345
diff changeset
   756
    num isNumber ifFalse:[^false].
10727
4e6346eb48a9 closeTo: with epsilon parameter
sr
parents: 10556
diff changeset
   757
    ^ num closeFrom:self withEpsilon:eps
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   758
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   759
    "
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   760
     1 closeTo:1.0000000001
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   761
     1 closeTo:1.001
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   762
    "
6155
00eaf2fa55bc isReal comment
Claus Gittinger <cg@exept.de>
parents: 6154
diff changeset
   763
00eaf2fa55bc isReal comment
Claus Gittinger <cg@exept.de>
parents: 6154
diff changeset
   764
    "Created: / 5.11.2001 / 18:07:26 / cg"
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   765
!
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
   766
9139
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   767
degreeCos
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   768
    "Return the cosine of the receiver taken as an angle in degrees."
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   769
    
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   770
    ^ self degreesToRadians cos
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   771
!
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   772
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   773
degreeSin
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   774
    "Return the sine of the receiver taken as an angle in degrees."
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   775
    
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   776
    ^ self degreesToRadians sin
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   777
!
94df665b3260 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9138
diff changeset
   778
11712
b83c3734b1ce added #degreeTan
sr
parents: 11660
diff changeset
   779
degreeTan
b83c3734b1ce added #degreeTan
sr
parents: 11660
diff changeset
   780
    "Return the cosine of the receiver taken as an angle in degrees."
b83c3734b1ce added #degreeTan
sr
parents: 11660
diff changeset
   781
    
b83c3734b1ce added #degreeTan
sr
parents: 11660
diff changeset
   782
    ^ self degreesToRadians tan
b83c3734b1ce added #degreeTan
sr
parents: 11660
diff changeset
   783
!
b83c3734b1ce added #degreeTan
sr
parents: 11660
diff changeset
   784
4988
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   785
newTileMorphRepresentative
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   786
	^ TileMorph new addArrows; setLiteral: self; addSuffixIfCan
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   787
!
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   788
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   789
stringForReadout
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   790
    ^ self rounded printString
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   791
! !
ac426684e852 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4895
diff changeset
   792
11712
b83c3734b1ce added #degreeTan
sr
parents: 11660
diff changeset
   793
9127
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   794
!Number methodsFor:'coercing & converting'!
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   795
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   796
i
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   797
    "return a complex number, with the receiver as imaginary part, 0 as real part"
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   798
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   799
    ^ Complex
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   800
        real:0
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   801
        imaginary:self
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   802
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   803
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   804
     3i          
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   805
     (1+1i)      
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   806
    "
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   807
! !
04cd80c64a30 decimapPointCharacter stuff;
Claus Gittinger <cg@exept.de>
parents: 8979
diff changeset
   808
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   809
!Number methodsFor:'converting'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   810
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   811
% aNumber 
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   812
    "Return a complex number with the receiver as the real part and 
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   813
     aNumber as the imaginary part"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   814
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   815
    ^ Complex real:self imaginary:aNumber
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   816
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   817
    "Modified: / 9.7.1998 / 10:18:12 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   818
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   819
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
   820
+/- anError
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
   821
    "return a MeasurementValue with the given error."
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
   822
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
   823
    ^ MeasurementValue value:self minValue:(self-anError) maxValue:(self+anError)
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
   824
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
   825
    "
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
   826
     (100 +/- 5) * 2            
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
   827
     (100 +/- 5) * (100 +/- 10)  
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
   828
     (100 +/- 5) + (100 +/- 10)  
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
   829
     (100 +/- 5) - (100 +/- 10)  
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
   830
    "
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
   831
!
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
   832
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   833
@ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   834
    "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
   835
     as y-coordinate"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   836
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   837
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   838
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   839
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   840
     * I cannot tell if this special code is worth anything
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   841
     */
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   842
    if (__CanDoQuickNew(sizeof(struct __Point))) {      /* OBJECT ALLOCATION */
7857
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   843
        OBJ newPoint;
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   844
        int spc;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   845
7857
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   846
        __qCheckedAlignedNew(newPoint, sizeof(struct __Point));
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   847
        __InstPtr(newPoint)->o_class = @global(Point);
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   848
        __qSTORE(newPoint, @global(Point));
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   849
        __PointInstPtr(newPoint)->p_x = self;
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   850
        __PointInstPtr(newPoint)->p_y = aNumber;
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   851
        if (! __bothSmallInteger(self, aNumber)) {
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   852
            spc = __qSpace(newPoint);
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   853
            __STORE_SPC(newPoint, aNumber, spc);
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   854
            __STORE_SPC(newPoint, self, spc);
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   855
        }
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   856
        RETURN ( newPoint );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   857
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   858
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   859
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   860
    ^ Point x:self y:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   861
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   862
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   863
asComplex
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   864
    "Return a complex number with the receiver as the real part and 
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   865
     zero as the imaginary part"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   866
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   867
    ^ Complex real:self
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   868
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   869
    "Modified: / 9.7.1998 / 10:18:16 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   870
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
   871
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   872
asMetaNumber
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   873
    ^ SomeNumber new realNumber:self
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   874
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
   875
7214
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
   876
asNumber
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
   877
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
   878
    ^ self.
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
   879
!
2315f1d48b84 *** empty log message ***
martin
parents: 6899
diff changeset
   880
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   881
asPoint
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   882
    "return a new Point with the receiver as all coordinates;  
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   883
     often used to supply the same value in two dimensions, as with 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   884
     symmetrical gridding or scaling."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   885
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   886
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   887
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
   888
    if (__CanDoQuickNew(sizeof(struct __Point))) {      /* OBJECT ALLOCATION */
7857
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   889
        OBJ newPoint;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   890
7857
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   891
        __qCheckedAlignedNew(newPoint, sizeof(struct __Point));
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   892
        __InstPtr(newPoint)->o_class = @global(Point);
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   893
        __qSTORE(newPoint, @global(Point));
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   894
        __PointInstPtr(newPoint)->p_x = self;
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   895
        __PointInstPtr(newPoint)->p_y = self;
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   896
        __STORE(newPoint, self);
51971c337c26 Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents: 7729
diff changeset
   897
        RETURN ( newPoint );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   898
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   899
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   900
    ^ Point x:self y:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   901
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   902
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   903
degreesToRadians
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   904
    "interpreting the receiver as radians, return the degrees"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   905
8203
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
   906
    ^ 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
   907
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   908
    "
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   909
     180 degreesToRadians
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   910
     Float pi radiansToDegrees
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   911
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   912
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   913
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   914
literalArrayEncoding
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   915
    "encode myself as an array literal, from which a copy of the receiver
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   916
     can be reconstructed with #decodeAsLiteralArray."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   917
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   918
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   919
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   920
    "Modified: 1.9.1995 / 02:25:26 / claus"
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   921
    "Modified: 22.4.1996 / 13:00:27 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   922
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   923
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   924
radiansToDegrees
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   925
    "interpreting the receiver as degrees, return the radians"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   926
8203
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
   927
    ^ 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
   928
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   929
    "
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   930
     180 degreesToRadians     
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   931
     Float pi radiansToDegrees
bb89a53e2682 fixed conversion from string to not loose precision which is later
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   932
    "
6637
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   933
!
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   934
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   935
withScale:newScale
8203
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
   936
    "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
   937
     with newScale number of post-decimal digits"
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   938
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   939
    ^ self asFixedPoint:newScale
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   940
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   941
    "
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   942
     1234 withScale:2 
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   943
     1234.1 withScale:2 
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   944
     1234.12 withScale:2 
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   945
     1234.123 withScale:2 
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   946
     (1/7) withScale:2
b6ee031f3096 withScale moved up.
Claus Gittinger <cg@exept.de>
parents: 6632
diff changeset
   947
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   948
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   949
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   950
!Number methodsFor:'converting-times'!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   951
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   952
days
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   953
    "return a TimeDuration representing this number of days"
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   954
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   955
    ^ TimeDuration days:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   956
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   957
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   958
     1000 milliseconds 
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   959
     10 seconds 
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   960
     10 minutes 
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   961
     1 days 
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   962
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   963
!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   964
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   965
hours
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   966
    "return a TimeDuration representing this number of hours"
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   967
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   968
    ^ TimeDuration hours:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   969
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   970
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   971
     1000 milliseconds 
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   972
     10 seconds 
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   973
     10 minutes 
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   974
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   975
!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   976
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   977
milliseconds
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   978
    "return a TimeDuration representing this number of milliseconds"
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   979
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   980
    ^ TimeDuration fromMilliseconds:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   981
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   982
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   983
     1000 milliseconds 
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   984
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   985
!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   986
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   987
minutes
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   988
    "return a TimeDuration representing this number of minutes"
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   989
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   990
    ^ TimeDuration minutes:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   991
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   992
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   993
     1000 milliseconds 
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   994
     10 seconds 
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   995
     10 minutes 
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   996
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   997
!
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   998
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
   999
seconds
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1000
    "return a TimeDuration representing this number of seconds"
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1001
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1002
    ^ TimeDuration seconds:self
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1003
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1004
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1005
     1000 milliseconds 
11770
37bd8fc58d59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11712
diff changeset
  1006
     10 seconds      
37bd8fc58d59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11712
diff changeset
  1007
     10 minutes      
11008
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1008
    "
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1009
! !
5a92714a522b timeDuration conversions added
Michael Beyl <mb@exept.de>
parents: 10727
diff changeset
  1010
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1011
!Number methodsFor:'intervals'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1012
6072
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1013
downTo:stop
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1014
    "return an interval from receiver down to the argument, incrementing by -1"
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1015
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1016
    ^ self to:stop by:-1
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1017
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1018
    "
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1019
     (10 downTo:1) do:[:i | Transcript showCR:i].
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1020
    "
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1021
!
55858717097a added #downTo:
Claus Gittinger <cg@exept.de>
parents: 5565
diff changeset
  1022
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1023
to:stop
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1024
    "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
  1025
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1026
    ^ Interval from:self to:stop
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1027
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1028
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1029
to:stop by:step
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1030
    "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
  1031
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1032
    ^ Interval from:self to:stop by:step
6154
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1033
!
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1034
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1035
to:stop byFactor:factor
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1036
    "return a geometric series from receiver up to the argument;
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1037
     elements have a constant factor in between"
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1038
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1039
    ^ GeometricSeries from:self to:stop byFactor:factor
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1040
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1041
    "
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1042
     (1 to:256 byFactor:2)
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1043
     (256 to:1 byFactor:1/2)     
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  1044
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1045
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1046
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1047
!Number methodsFor:'iteration'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1048
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1049
timesRepeat:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1050
    "evaluate the argument, aBlock self times"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1051
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1052
    |count|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1053
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1054
    count := self.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1055
    [count > 0] whileTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
  1056
	aBlock value.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
  1057
	count := count - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1058
    ]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1059
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1060
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1061
!Number methodsFor:'mathematical functions'!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1062
11488
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  1063
^ aNumber
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  1064
    "return the receiver raised to aNumber"
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  1065
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  1066
    ^ self raisedTo:aNumber
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  1067
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  1068
    "
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  1069
     2 ^ 4    
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  1070
     10 ^ 4    
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  1071
    "
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  1072
!
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  1073
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1074
conjugated
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1075
    "Return the complex conjugate of this Number."
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1076
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1077
    ^ self
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1078
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1079
    "Modified: / 9.7.1998 / 10:17:31 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1080
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1081
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1082
exp
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1083
    "compute e**x of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1084
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1085
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1086
    or:[self generality < 1.0 generality]) ifTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1087
        ^ self asFloat exp.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1088
    ].
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  1089
    ^ self exp_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1090
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1091
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1092
floorLog:radix
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1093
    "return the logarithm truncated as an integer"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1094
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1095
    ^ (self log:radix) floor
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1096
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1097
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1098
imaginary
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1099
    "Return the imaginary part of this Number."
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1100
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1101
    ^ 0
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1102
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1103
    "Modified: / 9.7.1998 / 10:17:24 / cg"
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1104
!
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1105
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1106
ln
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1107
    "compute ln of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1108
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1109
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1110
    or:[self generality < 1.0 generality]) ifTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1111
        ^ self asFloat ln.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1112
    ].
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  1113
    ^ self ln_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1114
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1115
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1116
log
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1117
    "return log base 10 of the receiver.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1118
     Alias for log10."
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1119
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1120
    ^ self log10
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1121
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1122
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1123
log10
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1124
    "return log base 10 of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1125
10550
0f2a07595d1c Fix bug 641: changed #log10 to be more accurate
Stefan Vogel <sv@exept.de>
parents: 10325
diff changeset
  1126
    (self isLimitedPrecisionReal not
0f2a07595d1c Fix bug 641: changed #log10 to be more accurate
Stefan Vogel <sv@exept.de>
parents: 10325
diff changeset
  1127
    or:[self generality < 1.0 generality]) ifTrue:[
0f2a07595d1c Fix bug 641: changed #log10 to be more accurate
Stefan Vogel <sv@exept.de>
parents: 10325
diff changeset
  1128
        ^ self asFloat log10.
0f2a07595d1c Fix bug 641: changed #log10 to be more accurate
Stefan Vogel <sv@exept.de>
parents: 10325
diff changeset
  1129
    ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1130
    ^ self log:10
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1131
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1132
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1133
log:aNumber
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1134
    "return log base aNumber of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1135
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1136
    ^ self ln / aNumber ln
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1137
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1138
    "
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1139
      1000 log:10
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1140
      (1000 log:10) floor
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1141
    "
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1142
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1143
7468
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1144
raisedTo:aNumber
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1145
    "return the receiver raised to aNumber"
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1146
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1147
    aNumber = 0 ifTrue:[^ 1].
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1148
    aNumber = 1 ifTrue:[^ self].
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1149
    aNumber isInteger ifTrue:[
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1150
        ^ self raisedToInteger:aNumber
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1151
    ].
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1152
    ^ self asFloat raisedTo:aNumber
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1153
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1154
    "
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1155
     2 raisedTo: 4    
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1156
     10 raisedTo: 4    
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1157
    "
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1158
!
61c8a3053bf4 moved math functions to number
Claus Gittinger <cg@exept.de>
parents: 7456
diff changeset
  1159
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1160
real
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1161
    "Return the real part of this Number."
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1162
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1163
    ^ self
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1164
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1165
    "Modified: / 9.7.1998 / 10:17:17 / cg"
6258
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1166
!
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1167
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1168
sqrt
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1169
    "return the square root of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1170
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1171
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1172
    or:[self generality < 1.0 generality]) ifTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1173
        ^ self asFloat sqrt.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1174
    ].
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  1175
    ^ self sqrt_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1176
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1177
10191
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1178
sqrtWithErrorLessThan:epsilon
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1179
    "compute the square root, using the Newton method.
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1180
     The approximated return value has an error less than the given epsilon."
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1181
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1182
    |y yN|
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1183
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1184
    yN := self / 2.
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1185
    [
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1186
       y := yN.
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1187
       yN := ( y + (self / y) ) / 2.
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1188
    ] doUntil:[ (yN - y) abs < epsilon ].
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1189
    ^ yN.
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1190
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1191
    "
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1192
     (2 asFixedPoint:4) sqrtWithErrorLessThan:0.001   
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1193
    "
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1194
!
4974027704a5 sqrtWithErrorLessThan:
Claus Gittinger <cg@exept.de>
parents: 9333
diff changeset
  1195
6258
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1196
timesTwoPower:anInteger
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1197
    "Return the receiver multiplied by 2.0 raised to the power of the argument.
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1198
     For protocol completeness wrt. Squeak and ST80."
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1199
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1200
    ^ self * (2.0 raisedToInteger:anInteger)
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1201
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1202
    "
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1203
     123 timesTwoPower:0  
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1204
     123 timesTwoPower:1  
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1205
     123 timesTwoPower:2  
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1206
     123 timesTwoPower:3  
435600a44e73 added timesTwoPower.
Claus Gittinger <cg@exept.de>
parents: 6195
diff changeset
  1207
    "
3634
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1208
! !
bbf443dce0cf complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  1209
11458
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1210
!Number methodsFor:'measurement values'!
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1211
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1212
maxValue
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1213
    "the maximum possible value taking me as a measurement with possible error; 
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1214
     as I am exact, thats myself"
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1215
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1216
    ^ self
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1217
!
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1218
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1219
minValue
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1220
    "the minimum possible value taking me as a measurement with possible error; 
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1221
     as I am exact, thats myself"
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1222
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1223
    ^ self
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1224
! !
d668f83e44d1 measurement support
Claus Gittinger <cg@exept.de>
parents: 11224
diff changeset
  1225
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1226
!Number methodsFor:'printing & storing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1227
5299
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  1228
printOn:aStream paddedWith:padCharacter to:size base:radix
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  1229
    |s|
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  1230
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1231
    radix == 10 ifTrue:[
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1232
        s := self printString.
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1233
    ] ifFalse:[
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1234
        s := self printStringRadix:radix.
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1235
    ].
5299
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  1236
    s printOn: aStream leftPaddedTo:size with: padCharacter
11098
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1237
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1238
    "
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1239
     100 printOn:Transcript paddedWith:$0 to:10 base:10.     Transcript cr.
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1240
     100 printOn:Transcript paddedWith:$0 to:10 base:16.     Transcript cr.
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1241
     100 printOn:Transcript paddedWith:(Character space) to:10 base:16.     Transcript cr.
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1242
     100 printOn:Transcript paddedWith:(Character space) to:10 base:2.     Transcript cr.
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1243
    "
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1244
!
5299
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  1245
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1246
printOn:aStream thousandsSeparator:thousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1247
    "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
  1248
     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
  1249
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1250
    |rest|
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1251
11594
5440d97af571 #printStringWithThousandsSeparator fix for non-integers
Stefan Vogel <sv@exept.de>
parents: 11526
diff changeset
  1252
    self >= 1000 ifTrue:[
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1253
        (self // 1000) printOn:aStream thousandsSeparator:thousandsSeparator.
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1254
        thousandsSeparator printOn:aStream.
11136
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1255
        rest := self \\ 1000.
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1256
        rest < 100 ifTrue:[
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1257
            aStream nextPut:$0.
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1258
            rest < 10 ifTrue:[
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1259
                aStream nextPut:$0.
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1260
            ].
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1261
        ].
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1262
        rest printOn:aStream.
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1263
        ^ self.
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1264
    ].
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1265
    self printOn:aStream.
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1266
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1267
    "
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1268
     swiss style:
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1269
     1000000 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1270
     12345678 printOn:Transcript thousandsSeparator:$'.     Transcript cr.  
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1271
     1234567 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1272
     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
  1273
     123056 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1274
     12345 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1275
     1234 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1276
     123 printOn:Transcript thousandsSeparator:$'.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1277
11136
ac25ee31e086 fix printOn:thousandsSeparator when there is a 0 behind a separator
Stefan Vogel <sv@exept.de>
parents: 11098
diff changeset
  1278
     (12345678.12 asFixedPoint:2) 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
  1279
     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
  1280
     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
  1281
     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
  1282
     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
  1283
     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
  1284
     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
  1285
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1286
     us style:
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1287
     1000000 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1288
     12345678 printOn:Transcript thousandsSeparator:$,.     Transcript cr.  
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1289
     1234567 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1290
     123456 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1291
     12345 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1292
     1234 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1293
     123 printOn:Transcript thousandsSeparator:$,.     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1294
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1295
     german (european ?) style
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1296
     1000000 printOn:Transcript thousandsSeparator:$..     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1297
     12345678 printOn:Transcript thousandsSeparator:$..     Transcript cr.  
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1298
     1234567 printOn:Transcript thousandsSeparator:$..     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1299
     123456 printOn:Transcript thousandsSeparator:$..     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1300
     12345 printOn:Transcript thousandsSeparator:$..     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1301
     1234 printOn:Transcript thousandsSeparator:$..     Transcript cr.
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1302
     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
  1303
    "
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1304
!
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1305
11660
62a726d91255 new: #printStringFormat:
Stefan Vogel <sv@exept.de>
parents: 11594
diff changeset
  1306
printStringFormat:formatString
62a726d91255 new: #printStringFormat:
Stefan Vogel <sv@exept.de>
parents: 11594
diff changeset
  1307
    ^ self printfPrintString:formatString
62a726d91255 new: #printStringFormat:
Stefan Vogel <sv@exept.de>
parents: 11594
diff changeset
  1308
!
62a726d91255 new: #printStringFormat:
Stefan Vogel <sv@exept.de>
parents: 11594
diff changeset
  1309
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1310
printStringRadix:radix
11098
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1311
    "only implemented for integers"
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1312
8301
74d9ee379019 decimalPointCharacter definition
werner
parents: 8203
diff changeset
  1313
    self subclassResponsibility
11098
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1314
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1315
    "
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1316
     100 printStringRadix:10.     
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1317
     100 printStringRadix:16.     
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1318
     100 printStringRadix:2.     
bfc609a33e11 comments
Claus Gittinger <cg@exept.de>
parents: 11097
diff changeset
  1319
    "
5299
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  1320
!
92b363dbd833 added #printOn:paddedWith:to:base:
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
  1321
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1322
printStringWithThousandsSeparator
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1323
    "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
  1324
     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
  1325
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1326
    ^ self printStringWithThousandsSeparator:$'.
11096
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1327
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1328
    "
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1329
     1000000 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1330
     12345678 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1331
     1234567 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1332
     123456 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1333
     12345 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1334
     1234 printStringWithThousandsSeparator
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1335
     123 printStringWithThousandsSeparator
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1336
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1337
     1000000 asFixedPoint printStringWithThousandsSeparator
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1338
     12345678 asFixedPoint printStringWithThousandsSeparator
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1339
     1234567 asFixedPoint printStringWithThousandsSeparator  
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1340
     123456 asFixedPoint printStringWithThousandsSeparator
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1341
     12345 asFixedPoint printStringWithThousandsSeparator 
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1342
     1234 asFixedPoint printStringWithThousandsSeparator 
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1343
     123 asFixedPoint printStringWithThousandsSeparator
11594
5440d97af571 #printStringWithThousandsSeparator fix for non-integers
Stefan Vogel <sv@exept.de>
parents: 11526
diff changeset
  1344
     ((9999999//10000) asFixedPoint:9) printStringWithThousandsSeparator 
11097
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1345
    "
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1346
!
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1347
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1348
printStringWithThousandsSeparator:thousandsSeparator
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1349
    "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
  1350
     Notice:
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1351
        americans use comma
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1352
        germans (europeans ?) use a dot
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1353
        swiss people (business people ?) use a single quote
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1354
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1355
     Caveat: Should use the separator from the locale here"
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1356
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1357
    ^ String streamContents:[:s | self printOn:s thousandsSeparator:thousandsSeparator].
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1358
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1359
    "
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1360
     Transcript showCR:(1000000 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1361
     Transcript showCR:(12345678 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1362
     Transcript showCR:(1234567 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1363
     Transcript showCR:(123456 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1364
     Transcript showCR:(12345 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1365
     Transcript showCR:(1234 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1366
     Transcript showCR:(123 printStringWithThousandsSeparator:$').
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1367
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1368
     Transcript showCR:(1000000 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1369
     Transcript showCR:(12345678 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1370
     Transcript showCR:(1234567 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1371
     Transcript showCR:(123456 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1372
     Transcript showCR:(12345 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1373
     Transcript showCR:(1234 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1374
     Transcript showCR:(123 printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1375
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1376
     Transcript showCR:((1000000 asFixedPoint:2) printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1377
     Transcript showCR:((12345678 asFixedPoint:2) printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1378
     Transcript showCR:((1234567 asFixedPoint:2) printStringWithThousandsSeparator:$,).  
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1379
     Transcript showCR:((123456 asFixedPoint:2) printStringWithThousandsSeparator:$,).
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1380
     Transcript showCR:((12345 asFixedPoint:2) printStringWithThousandsSeparator:$,). 
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1381
     Transcript showCR:((1234 asFixedPoint:2) printStringWithThousandsSeparator:$,). 
5e4961639e41 printStringWithThousandsSep comments and refactored
Claus Gittinger <cg@exept.de>
parents: 11096
diff changeset
  1382
     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
  1383
    "
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1384
!
19d6c993e67f printStringWithThousandsSep moved up (also valid for FixedPoint Decimals)
Claus Gittinger <cg@exept.de>
parents: 11008
diff changeset
  1385
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1386
storeOn:aStream
11460
146fb82b5523 comment
Claus Gittinger <cg@exept.de>
parents: 11458
diff changeset
  1387
    "append a string for storing the receiver onto the argument, aStream
146fb82b5523 comment
Claus Gittinger <cg@exept.de>
parents: 11458
diff changeset
  1388
     - since numbers are literals,they store as they print."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1389
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1390
    ^ self printOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1391
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1392
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1393
storeString
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1394
    "return a string for storing 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1395
     - since numbers are literals, they store as they print."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1396
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1397
    ^ self printString
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1398
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1399
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1400
!Number methodsFor:'taylor series'!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1401
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1402
arcSin_withAccuracy:epsilon
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1403
    "compute the arcSine of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1404
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1405
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1406
    "/                 1*x^3   1*3 * x^5   
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1407
    "/    arcSin = x + ----- + ---------- + ...
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1408
    "/                 2* 3    2*4 *  5    
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1409
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1410
    |x2 num numf den denf approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1411
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1412
    ((self < -1) or:[self > 1]) ifTrue:[ 
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1413
        ^ self class
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1414
            raise:#domainErrorSignal
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1415
            receiver:self
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1416
            selector:#arcSin
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1417
            arguments:#()
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1418
            errorString:'bad receiver in arcSin'
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1419
    ].
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1420
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1421
    x2 := self * self.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1422
    num := x2 * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1423
    approx := self + (num / 6).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1424
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1425
    numf := 3.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1426
    denf := 4.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1427
    den := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1428
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1429
    [
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1430
        num := (num * x2) * numf.   numf := numf + 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1431
        den := den * denf.          denf := denf + 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1432
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1433
        delta := num / (den * numf).
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1434
        approx := approx + delta.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1435
    ] doUntil:[delta abs <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1436
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1437
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1438
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1439
     0.5 arcSin                                    0.523599
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1440
     0.5q arcSin                        0.523598776
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1441
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1442
     0.5q arcSin_withAccuracy:1         0.520833333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1443
     0.5q arcSin_withAccuracy:0.1       0.520833333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1444
     0.5q arcSin_withAccuracy:0.01      0.523177083
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1445
     0.5q arcSin_withAccuracy:0.001     0.523525856
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1446
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1447
     0.5q arcSin_withAccuracy:1e-20     0.523598776
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1448
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1449
     0.5 asLargeFloat arcSin_withAccuracy:1e-30    -- not yet 
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1450
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1451
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1452
     0.1 arcSin                                    0.100167
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1453
     0.1q arcSin                        0.100167421
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1454
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1455
     0.1q arcSin_withAccuracy:1         0.100166667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1456
     0.1q arcSin_withAccuracy:0.1       0.100166667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1457
     0.1q arcSin_withAccuracy:0.01      0.100166667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1458
     0.1q arcSin_withAccuracy:0.001     0.100166667
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1459
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1460
     0.1q arcSin_withAccuracy:1e-20     0.100167421
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1461
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1462
     0.1 asLargeFloat arcSin_withAccuracy:1e-30    -- not yet 
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1463
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1464
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1465
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1466
arcTan_withAccuracy:epsilon
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1467
    "compute the arcTangent of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1468
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1469
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1470
    "/                 x^3   x^5   x^7
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1471
    "/ arcTan(x) = x - --- + --- - --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1472
    "/                  3     5    7
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1473
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1474
    |x2 num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1475
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1476
    x2 := self * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1477
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1478
    num := (x2 * self) negated.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1479
    den := 3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1480
    approx := self + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1481
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1482
    [
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1483
        den := den + 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1484
        num := (num * x2) negated.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1485
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1486
        delta := num / den.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1487
        approx := approx + delta.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1488
    ] doUntil:[delta abs <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1489
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1490
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1491
    "
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1492
     1.0 arcTan                       0.785398
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1493
     1q arcTan                        0.785398163
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1494
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1495
     1q arcTan_withAccuracy:1         0.666666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1496
     1q arcTan_withAccuracy:0.1       0.744011544
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1497
     1q arcTan_withAccuracy:0.01      0.790299653
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1498
     1q arcTan_withAccuracy:0.001     0.785897165
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1499
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1500
     1q arcTan_withAccuracy:1e-8      0.785398168     
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1501
     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
  1502
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1503
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1504
     0.5 arcTan                         0.463648
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1505
     0.5q arcTan                        0.463647609
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1506
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1507
     0.5q arcTan_withAccuracy:1         0.458333333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1508
     0.5q arcTan_withAccuracy:0.1       0.458333333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1509
     0.5q arcTan_withAccuracy:0.01      0.464583333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1510
     0.5q arcTan_withAccuracy:0.001     0.463684276
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1511
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1512
     0.5q arcTan_withAccuracy:1e-20     0.463647609
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1513
     0.5 asLargeFloat arcTan_withAccuracy:1e-30    -- not yet  
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1514
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1515
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1516
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1517
cos_withAccuracy:epsilon
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1518
    "compute the cosine of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1519
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1520
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1521
    "/               x^2   x^4   x^6
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1522
    "/  cos(x) = 1 - --- + --- - --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1523
    "/                2!!    4!!    6!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1524
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1525
    |x2 facN num den approx lastApprox|
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1526
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1527
    x2 := self * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1528
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1529
    num := x2 negated.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1530
    den := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1531
    facN := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1532
    approx := 1 + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1533
    lastApprox := 1.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1534
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1535
    [ (lastApprox - approx) abs > epsilon ] whileTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1536
        facN := facN + 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1537
        den := den * (facN - 1) * facN.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1538
        num := (num * x2) negated.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1539
        lastApprox := approx.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1540
        approx := approx + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1541
    ].
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1542
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1543
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1544
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1545
     1.0 cos                                    0.540302
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1546
     1.0 asLongFloat cos_withAccuracy:1         0.5
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1547
     1.0 asLongFloat cos_withAccuracy:0.1       0.541666667 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1548
     1.0 asLongFloat cos_withAccuracy:0.01      0.540277778
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1549
     1.0 asLongFloat cos_withAccuracy:0.001     0.540302579
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1550
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1551
     1.0 asLongFloat cos_withAccuracy:1e-40     0.540302306    
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1552
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1553
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1554
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1555
cosh_withAccuracy:epsilon
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1556
    "compute the hyperbolic cosine of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1557
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1558
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1559
    "/               x^2   x^4   x^6
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1560
    "/    cosh = x + --- + --- + --- ...
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1561
    "/                2!!    4!!    6!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1562
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1563
    |x2 facN num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1564
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1565
    x2 := self * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1566
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1567
    num := x2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1568
    den := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1569
    facN := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1570
    approx := self + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1571
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1572
    [
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1573
        facN := facN + 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1574
        den := den * (facN - 1) * facN.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1575
        num := num * x2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1576
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1577
        delta := num / den.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1578
        approx := approx + delta.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1579
    ] doUntil:[delta <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1580
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1581
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1582
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1583
     1.0 cosh                                    1.54308
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1584
     1.0q cosh_withAccuracy:1         1.5 
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1585
     1.0q cosh_withAccuracy:0.1       1.54308 
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1586
     1.0q cosh_withAccuracy:0.01      1.54308 
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1587
     1.0q cosh_withAccuracy:0.001     1.54308 
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1588
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1589
     1.0q cosh_withAccuracy:1e-40   -> 1.543080    
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1590
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1591
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1592
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  1593
epsilon
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  1594
    "return the maximum relative spacing of instances of mySelf 
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  1595
     (i.e. the value-delta of the least significant bit)"
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  1596
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  1597
    ^ self class epsilon
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  1598
!
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  1599
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1600
exp_withAccuracy:epsilon
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1601
    "compute e**x of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1602
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1603
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1604
    "/             x    x^2   x^3
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1605
    "/  e^x = 1 + --- + --- + --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1606
    "/             1!!    2!!    3!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1607
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1608
    |x2 facN num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1609
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1610
    x2 := self * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1611
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1612
    num := x2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1613
    den := 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1614
    facN := 2.
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1615
    approx := self + 1 + (num / den).
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1616
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1617
    [
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1618
        facN := facN + 1.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1619
        den := den * facN.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1620
        num := num * self.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1621
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1622
        delta := num / den.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1623
        approx := approx + delta.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1624
    ] doUntil:[delta abs <= epsilon].
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1625
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1626
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1627
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1628
    "
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1629
     -1 exp
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1630
     1.0 exp                                    2.71828
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1631
     1q exp                                     2.71828183
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1632
     2q exp                                     7.3890561                        
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1633
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1634
     1q exp_withAccuracy:1                      2.66666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1635
     1q exp_withAccuracy:0.1                    2.70833333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1636
     1q exp_withAccuracy:0.01                   2.71666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1637
     1q exp_withAccuracy:0.001                  2.71825397
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1638
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1639
     2q exp_withAccuracy:LongFloat epsilon      7.3890561
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1640
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1641
     1.0 asLongFloat exp_withAccuracy:1e-40     2.71828183 
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1642
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1643
     5 exp_withAccuracy:1e-40      
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1644
     (1 exp_withAccuracy:1e-100) asFixedPoint:100
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1645
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1646
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1647
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1648
ln_withAccuracy:epsilon
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1649
    "compute ln of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1650
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1651
    "uses taylor series:
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1652
                 u^2   u^3
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1653
        ln = u - --- + --- ...
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1654
                  2    3
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1655
      where:
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1656
             u = x - 1    and: x < 1
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1657
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1658
     Now we use modified taylor, which converges faster:
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1659
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1660
                   1+y        1   1       1
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1661
        ln(x) = ln --- = 2y ( - + - y^2 + - y^4 + ....)
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1662
                   1-y        1   3       5
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1663
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1664
        where y = (x-1) / (x+1)  and x > 0
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1665
    "
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1666
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1667
    |denominator approx y y2 exp delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1668
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1669
    self <= 0 ifTrue:[
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1670
        ^ self class
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1671
            raise:#domainErrorSignal
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1672
            receiver:self
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1673
            selector:#ln
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1674
            arguments:#()
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1675
            errorString:'bad receiver in ln'
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1676
    ].
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1677
        
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1678
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1679
    y := (self - 1)/(self + 1).
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1680
    exp := y2 := y * y.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1681
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1682
    approx := 1.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1683
    denominator := 3.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1684
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1685
    [
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1686
        delta := exp / denominator.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1687
        approx := approx + delta.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1688
        exp := exp * y2.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1689
        denominator := denominator + 2.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1690
    ] doUntil:[delta <= epsilon].
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1691
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1692
    ^ y * 2 * approx.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1693
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1694
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1695
    "
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1696
     2.0 ln                         0.693147
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1697
     2.0q ln                        0.693147181
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1698
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1699
     2.0q ln_withAccuracy:1         0.691358025     
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1700
     2.0q ln_withAccuracy:0.1       0.691358025       
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1701
     2.0q ln_withAccuracy:0.01      0.693004115    
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1702
     2.0q ln_withAccuracy:0.0000001 0.69314718    
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1703
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1704
     2.0q ln_withAccuracy:1e-10     
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1705
     2.0q ln_withAccuracy:1e-20     
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1706
     2.0q ln_withAccuracy:1e-40     0.693147181
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1707
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1708
     2 ln_withAccuracy:1e-40                   
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1709
     0 ln_withAccuracy:1e-40                   
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1710
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1711
     (2 ln_withAccuracy:1e-100) asFixedPoint:100
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1712
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1713
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1714
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1715
sin_withAccuracy:epsilon
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1716
    "compute the sine of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1717
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1718
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1719
    "/               x^3   x^5   x^7
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1720
    "/  sin(x) = x - --- + --- - --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1721
    "/                3!!    5!!    7!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1722
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1723
    |x2 facN num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1724
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1725
    x2 := self * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1726
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1727
    num := (x2 * self) negated.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1728
    den := 2*3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1729
    facN := 3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1730
    approx := self + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1731
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1732
    [
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1733
        facN := facN + 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1734
        den := den * (facN - 1) * facN.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1735
        num := (num * x2) negated.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1736
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1737
        delta := num / den.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1738
        approx := approx + delta.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1739
    ] doUntil:[delta abs <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1740
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1741
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1742
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1743
     1.0 sin                                    0.841471
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1744
     1.0q sin                        0.841470985
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1745
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1746
     1.0q sin_withAccuracy:1         0.833333333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1747
     1.0q sin_withAccuracy:0.1       0.841666667 
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1748
     1.0q sin_withAccuracy:0.01      0.841666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1749
     1.0q sin_withAccuracy:0.001     0.841468254
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1750
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1751
     1.0q sin_withAccuracy:1e-40     0.841470985
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1752
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1753
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1754
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1755
sinh_withAccuracy:epsilon
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1756
    "compute the hyperbolic sine of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1757
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1758
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1759
    "/               x^3   x^5   x^7
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1760
    "/ sinh(x) = x + --- + --- + --- ...
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1761
    "/                3!!    5!!    7!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1762
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1763
    |x2 facN num den approx delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1764
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1765
    x2 := self * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1766
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1767
    num := x2 * self.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1768
    den := 2*3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1769
    facN := 3.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1770
    approx := self + (num / den).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1771
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1772
    [
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1773
        facN := facN + 2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1774
        den := den * (facN - 1) * facN.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1775
        num := num * x2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1776
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1777
        delta := num / den.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1778
        approx := approx + delta.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1779
    ] doUntil:[delta abs <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1780
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1781
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1782
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1783
     1.0 sinh                                    1.1752
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1784
     1q sinh                        1.17520119
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1785
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1786
     1q sinh_withAccuracy:1         1.16666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1787
     1q sinh_withAccuracy:0.1       1.175 
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1788
     1q sinh_withAccuracy:0.01      1.175
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1789
     1q sinh_withAccuracy:0.001     1.17519841
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1790
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1791
     1q sinh_withAccuracy:1e-40     1.17520119 
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1792
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1793
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1794
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1795
sqrt_withAccuracy:epsilon 
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1796
    "compute square root of the receiver"
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1797
    "
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1798
      Use the Heron Algorithm:
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1799
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1800
                 x_n + (a / x_n)
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1801
        x_n+1 =  ---------------
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1802
                      2
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1803
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1804
        sqrt(a) = x_n
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1805
    "
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1806
    
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1807
    |approx|
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1808
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1809
    self <= 0 ifTrue:[
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1810
        self = 0 ifTrue:[
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1811
            ^ self
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1812
        ].
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1813
        ^ self class
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1814
            raise:#imaginaryResultSignal
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1815
            receiver:self
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1816
            selector:#sqrt
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1817
            arguments:#()
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1818
            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
  1819
    ].
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1820
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1821
    approx := 1.
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1822
    [
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1823
        |lastApprox|
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1824
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1825
        lastApprox := approx.
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1826
        approx := ((self / approx) + approx) / 2.
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1827
        (approx - lastApprox) abs > epsilon
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1828
    ] whileTrue.
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1829
    ^ approx
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1830
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1831
    "
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1832
     2 sqrt                                             1.41421
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1833
     2q sqrt_withAccuracy:0.01               1.41666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1834
     2q sqrt_withAccuracy:0.0001             1.41421569
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1835
     2q sqrt_withAccuracy:0.0000001          1.41421356
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1836
     2q sqrt_withAccuracy:0.0000000001       1.41421356
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1837
     2q sqrt_withAccuracy:0.000000000001     1.41421356
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1838
     2q sqrt_withAccuracy:LongFloat epsilon  1.41421356
7729
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1839
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1840
     (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
  1841
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1842
     MessageTally spyOn:[ |arg|
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1843
        arg := 2 asLongFloat.
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1844
        1000000 timesRepeat:[
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1845
             arg sqrt_withAccuracy:0.000000000001
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1846
        ]
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1847
     ]
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1848
     Time millisecondsToRun:[ |arg|
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1849
        arg := 2 asLongFloat.
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1850
        1000000 timesRepeat:[
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1851
             arg sqrt_withAccuracy:0.000000000001
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1852
        ]
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1853
     ]
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1854
    "
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1855
!
bbd20db09d1b Fix senders of #xxxx_withAccuracy: to use #epsilon instead of #precision.
Stefan Vogel <sv@exept.de>
parents: 7468
diff changeset
  1856
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1857
tan_withAccuracy:epsilon
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1858
    "compute the tangens of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1859
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1860
    "/ uses taylor series:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1861
    "/                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
  1862
    "/    tan = x + 1*--- + 2*--- + 17*--- + 62*----... ----------------------------------...
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1863
    "/                 3       15      315      2835                 (2n)!!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1864
    "/ where Bi is the ith bernoulli number.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1865
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1866
    |factors idx x2 num t approx lastApprox delta|
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1867
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1868
    "/    (1 to:20) collect:[:n| |num den|
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1869
    "/        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
  1870
    "/        den := (2*n) factorial.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1871
    "/        num / den
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1872
    "/    ]   
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1873
   factors := #(
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1874
        (1 3) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1875
        (2 15) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1876
        (17 315) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1877
        (62 2835)
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1878
        (1382 155925) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1879
        (21844 6081075) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1880
        (929569 638512875)
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1881
        (6404582 10854718875) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1882
        (443861162 1856156927625) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1883
        (18888466084 194896477400625) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1884
        (113927491862 2900518163668125) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1885
        (58870668456604 3698160658676859375) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1886
        (8374643517010684 1298054391195577640625) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1887
        (689005380505609448 263505041412702261046875) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1888
        (129848163681107301953 122529844256906551386796875) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1889
        (1736640792209901647222 4043484860477916195764296875) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1890
        (418781231495293038913922 2405873491984360136479756640625) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1891
        (56518638202982204522669764 801155872830791925447758961328125) 
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1892
        (32207686319158956594455462 1126482925555250126673224649609375)).
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1893
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  1894
    x2 := self * self.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1895
8203
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  1896
    num := x2 * self.               "/ =  x^3
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  1897
    approx := self + (num / 3).     "/ do the first iteration
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1898
    lastApprox := self.
8203
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  1899
    idx := 2.
666bfa7bcb97 Fix C cmpiler warnings.
Stefan Vogel <sv@exept.de>
parents: 7857
diff changeset
  1900
    [
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1901
        t := factors at:idx ifAbsent:[].
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1902
        t isNil ifTrue:[
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1903
            self error:'too many iterations'.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1904
"/ Not enough bernoulli numbers for now...
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1905
"/            |tempNum tempDen|
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1906
"/            tempNum := 2 raisedTo:(2*idx).
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1907
"/            tempNum := tempNum * (tempNum-1) * ((2*idx) bernoulli).
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1908
"/            tempDen := (2*idx) factorial.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1909
"/            t := Array with:tempNum with:tempDen.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1910
        ].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1911
        idx := idx + 1.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1912
        num := num * x2.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1913
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1914
        delta := num * t first / t second.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1915
        approx := approx + delta.
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1916
    ] doUntil:[delta abs <= epsilon].
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1917
    ^ approx
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1918
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1919
    "
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1920
     0.5 tan                         0.546302
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1921
     0.5q tan                        0.54630249
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1922
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1923
     0.5q tan_withAccuracy:1         0.541666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1924
     0.5q tan_withAccuracy:0.1       0.541666667
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1925
     0.5q tan_withAccuracy:0.01      0.545833333
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1926
     0.5q tan_withAccuracy:0.001     0.54625496
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1927
     0.5q tan_withAccuracy:1e-15     0.54630249
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1928
10556
fb4ea1df1f1d Fix/speed up taylor computations
Stefan Vogel <sv@exept.de>
parents: 10550
diff changeset
  1929
     0.5q tan_withAccuracy:1e-40     -- too many iterations
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1930
    "
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1931
! !
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1932
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1933
!Number methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1934
5360
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1935
isDivisibleBy:aNumber
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1936
    "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
  1937
     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
  1938
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1939
    aNumber = 0 ifTrue: [^ false].
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1940
    aNumber isInteger ifFalse: [^ false].
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1941
    ^ (self \\ aNumber) = 0
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1942
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1943
    "
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1944
     3 isDivisibleBy:2     
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1945
     4 isDivisibleBy:2
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1946
     4.0 isDivisibleBy:2   
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1947
     4.5 isDivisibleBy:4.5 
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1948
     4.5 isDivisibleBy:1.0 
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1949
    "
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1950
!
1aef297d3cbe added #isDivisibleBy:
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
  1951
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  1952
isNaN
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  1953
    "return true, if the receiver is an invalid float (NaN - not a number)."
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  1954
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  1955
    ^ false
6155
00eaf2fa55bc isReal comment
Claus Gittinger <cg@exept.de>
parents: 6154
diff changeset
  1956
00eaf2fa55bc isReal comment
Claus Gittinger <cg@exept.de>
parents: 6154
diff changeset
  1957
    "Created: / 5.11.2001 / 18:07:26 / cg"
6143
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  1958
!
695cc93a96b4 isNan, isInfinite and closeTo:
james
parents: 6087
diff changeset
  1959
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1960
isNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1961
    "return true, if the receiver is a kind of number"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1962
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1963
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1964
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1965
6087
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  1966
isReal
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  1967
    "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
  1968
     true is returned here - the method is redefined from Object."
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  1969
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  1970
    ^ true
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  1971
!
826b87eab740 moved isReal
Claus Gittinger <cg@exept.de>
parents: 6072
diff changeset
  1972
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1973
isZero
1557
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  1974
    "return true, if the receiver is zero"
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  1975
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1976
    ^ self = 0
1557
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  1977
2c3c301cf48f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  1978
    "Modified: 18.7.1996 / 12:40:49 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1979
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1980
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  1981
!Number methodsFor:'tracing'!
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  1982
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4659
diff changeset
  1983
traceInto:aRequestor level:level from:referrer
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  1984
    "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
  1985
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4659
diff changeset
  1986
    ^ aRequestor traceNumber:self level:level from:referrer
4659
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  1987
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  1988
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  1989
! !
cdf37afc0e26 moved isLiteral - some numbers are not.
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
  1990
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1991
!Number methodsFor:'trigonometric'!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1992
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1993
arcCos
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1994
    "return the arccosine of the receiver (in radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1995
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1996
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1997
    or:[self generality < 1.0 generality]) ifTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1998
        ^ self asFloat arcCos.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  1999
    ].
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2000
    ^ (self class pi / 2) - self arcSin
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2001
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2002
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2003
arcCosh
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2004
    "return the hyperbolic arccosine of the receiver."
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2005
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2006
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2007
    or:[self generality < 1.0 generality]) ifTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2008
        ^ self asFloat arcCosh.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2009
    ].
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2010
    ^ (self + (self*self-1) sqrt) ln.
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2011
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2012
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2013
arcSin
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2014
    "return the arcsine of the receiver (in radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2015
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2016
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2017
    or:[self generality < 1.0 generality]) ifTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2018
        ^ self asFloat arcSin.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2019
    ].
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2020
    ^ self arcSin_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2021
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2022
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2023
arcSinh
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2024
    "return the hyperbolic arcsine of the receiver."
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2025
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2026
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2027
    or:[self generality < 1.0 generality]) ifTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2028
        ^ self asFloat arcSinh.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2029
    ].
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2030
    ^ ( self + (self*self+1) sqrt ) ln
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2031
"/    ^ self arcSinh_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2032
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2033
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2034
arcTan
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2035
    "return the arctangent of the receiver (as radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2036
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2037
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2038
    or:[self generality < 1.0 generality]) ifTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2039
        ^ self asFloat arcTan.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2040
    ].
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2041
    ^ self arcTan_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2042
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2043
11488
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2044
arcTan2:x
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2045
    "return atan2(self,x) (as radians)"
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2046
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2047
    (self isLimitedPrecisionReal not
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2048
    or:[self generality < 1.0 generality]) ifTrue:[
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2049
        ^ self asFloat arcTan2:x.
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2050
    ].
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2051
    ^ self arcTan2_withAccuracy:self epsilon x:x
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2052
!
8d948de20326 +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 11460
diff changeset
  2053
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2054
arcTanh
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2055
    "return the hyperbolic arctangent of the receiver."
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2056
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2057
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2058
    or:[self generality < 1.0 generality]) ifTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2059
        ^ self asFloat arcTanh.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2060
    ].
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2061
    ^ ((self + 1) ln / 2) - ((1 - self) ln / 2)
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2062
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2063
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2064
cos
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2065
    "return the cosine of the receiver (interpreted as radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2066
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2067
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2068
    or:[self generality < 1.0 generality]) ifTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2069
        ^ self asFloat cos.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2070
    ].
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2071
    ^ self cos_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2072
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2073
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2074
cosh
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2075
    "return the hyperbolic cosine of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2076
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2077
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2078
    or:[self generality < 1.0 generality]) ifTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2079
        ^ self asFloat cosh.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2080
    ].
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2081
    ^ self cosh_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2082
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2083
8844
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2084
cot
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2085
    "return the cotangent of the receiver"
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2086
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2087
    ^ 1 / self tan
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2088
!
21e7c41e277e hyperbolic functions fixed
Claus Gittinger <cg@exept.de>
parents: 8830
diff changeset
  2089
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2090
sin
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2091
    "return the sine of the receiver (interpreted as radians)"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2092
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2093
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2094
    or:[self generality < 1.0 generality]) ifTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2095
        ^ self asFloat sin.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2096
    ].
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2097
    ^ self sin_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2098
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2099
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2100
sinh
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2101
    "return the hyperbolic sine of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2102
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2103
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2104
    or:[self generality < 1.0 generality]) ifTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2105
        ^ self asFloat sinh.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2106
    ].
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2107
    ^ self sinh_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2108
!
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2109
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2110
tan
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2111
    "return the tangens of the receiver (interpreted as radians)"
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 sin / self cos
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
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2116
tanh
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2117
    "return the hyperbolic tangens of the receiver"
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2118
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2119
    (self isLimitedPrecisionReal not
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2120
    or:[self generality < 1.0 generality]) ifTrue:[
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2121
        ^ self asFloat tanh.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2122
    ].
8634
2c838074e754 epsilon
Claus Gittinger <cg@exept.de>
parents: 8303
diff changeset
  2123
    ^ self tanh_withAccuracy:self epsilon
7449
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2124
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2125
"/ If a fast exp is available, the following might be better...
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2126
"/
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2127
"/    |exp nexp|
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2128
"/
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2129
"/    "/ tanh is:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2130
"/    "/      sinh(x)
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2131
"/    "/      -------
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2132
"/    "/      cosh(x)
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2133
"/    "/
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2134
"/    "/ which is:
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2135
"/    "/      (exp(x) - exp(-x)) / 2
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2136
"/    "/      ----------------------
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2137
"/    "/      (exp(x) + exp(-x)) / 2
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2138
"/    
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2139
"/    exp := self exp.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2140
"/    nexp := self negated exp.
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2141
"/
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2142
"/    ^ (exp - nexp) / (exp + nexp)
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2143
! !
192789c6e1c2 fallback code for trigonometric;
Claus Gittinger <cg@exept.de>
parents: 7388
diff changeset
  2144
5552
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5360
diff changeset
  2145
!Number methodsFor:'truncation & rounding'!
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2146
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2147
detentBy: detent atMultiplesOf: grid snap: snap
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2148
    "Map all values that are within detent/2 of any multiple of grid 
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2149
     to that multiple.  
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2150
     Otherwise, if snap is true, return self, meaning that the values 
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2151
     in the dead zone will never be returned.  
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2152
     If snap is false, then expand the range between dead zones
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2153
     so that it covers the range between multiples of the grid, 
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2154
     and scale the value by that factor."
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2155
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2156
    | r1 r2 |
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2157
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2158
    r1 := self roundTo: grid.                    "Nearest multiple of grid"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2159
    (self roundTo: detent) = r1 ifTrue: [^ r1].  "Snap to that multiple..."
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2160
    snap ifTrue: [^ self].                       "...or return self"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2161
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2162
    r2 := self < r1                               "Nearest end of dead zone"
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
  2163
	    ifTrue: [r1 - (detent asFloat/2)]
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
  2164
	    ifFalse: [r1 + (detent asFloat/2)].
4895
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2165
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2166
    "Scale values between dead zones to fill range between multiples"
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2167
    ^ r1 + ((self - r2) * grid asFloat / (grid - detent))
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2168
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2169
    "
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2170
     (170 to: 190 by: 2) collect: [:a | a detentBy: 10 atMultiplesOf: 90 snap: true]         
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2171
     (170 to: 190 by: 2) collect: [:a | a detentBy: 10 atMultiplesOf: 90 snap: false]
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2172
     (3.9 to: 4.1 by: 0.02) collect: [:a | a detentBy: 0.1 atMultiplesOf: 1.0 snap: true]    
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2173
     (-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
  2174
    "
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2175
!
cc546b082506 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
  2176
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2177
fractionPart
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2178
    "return a float with value from digits after the decimal point.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  2179
     i.e. the receiver minus its truncated value,
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  2180
     such that (self truncated + self fractionPart) = self"
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2181
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  2182
    ^ self - self truncated
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2183
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2184
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2185
     1234.56789 fractionPart
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2186
     1.2345e6 fractionPart  
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  2187
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  2188
     1.6 asLongFloat fractionPart + 1.6 asLongFloat truncated    
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  2189
     -1.6 asLongFloat fractionPart + -1.6 asLongFloat truncated    
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2190
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2191
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2192
    "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
  2193
    "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
  2194
!
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2195
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2196
integerPart
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2197
    "return a float with value from digits before the decimal point
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2198
     (i.e. the truncated value)"
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2199
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2200
    ^ self truncated asFloat
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2201
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2202
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2203
     1234.56789 integerPart 
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2204
     1.2345e6 integerPart   
6154
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  2205
     12.5 integerPart 
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  2206
     -12.5 integerPart 
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  2207
     (5/3) integerPart  
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  2208
     (-5/3) integerPart 
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  2209
     (5/3) truncated  
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  2210
     (-5/3) truncated  
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2211
    "
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2212
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2213
    "Created: / 28.10.1998 / 17:14:56 / cg"
6154
6cb999c5ace3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6143
diff changeset
  2214
    "Modified: / 5.11.2001 / 17:54:22 / cg"
3900
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2215
! !
c3bc76767cfc added generic implementations of #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3770
diff changeset
  2216
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  2217
!Number class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2218
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2219
version
17711
39faaaf888b4 Added branch jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11770
diff changeset
  2220
    ^ '$Id: Number.st 10448 2009-06-14 16:10:51Z vranyj1 $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  2221
! !