LimitedPrecisionReal.st
author Claus Gittinger <cg@exept.de>
Mon, 04 Feb 2002 15:31:14 +0100
changeset 6376 6a3ce5694cc9
parent 6195 9e60c38d1d61
child 6575 b07cd54c4375
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     1
"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
     3
	      All Rights Reserved
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     4
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    11
"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    12
5470
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
    13
"{ Package: 'stx:libbasic' }"
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
    14
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    15
Number subclass:#LimitedPrecisionReal
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    16
	instanceVariableNames:''
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    17
	classVariableNames:''
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    18
	poolDictionaries:''
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    19
	category:'Magnitude-Numbers'
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    20
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    22
!LimitedPrecisionReal class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    23
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
 COPYRIGHT (c) 1994 by Claus Gittinger
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
    27
	      All Rights Reserved
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    28
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
!
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    37
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
documentation
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    40
    Abstract superclass for single and double (and maybe more) 
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    41
    precision real numbers (i.e. Float and Double).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    42
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    43
    Due to historic reasons, ST/X's Floats are what Doubles are in ST-80.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    44
    This may change soon (implementing LPReal is a first step towards this).
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1201
diff changeset
    45
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1201
diff changeset
    46
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1201
diff changeset
    47
        Claus Gittinger
1893
c66af5c46272 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
    48
c66af5c46272 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
    49
    [see also:]
c66af5c46272 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
    50
        Fraction FixedPoint
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    51
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    52
! !
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    53
5989
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    54
!LimitedPrecisionReal class methodsFor:'initialization'!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    55
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    56
initialize
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    57
    "initialize ANSI compliant float globals"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    58
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    59
    Smalltalk at:#FloatE put:ShortFloat.
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    60
    Smalltalk at:#FloatD put:Float.
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    61
    Smalltalk at:#FloatQ put:LongFloat.
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    62
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    63
    "
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    64
     self initialize
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    65
    "
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    66
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    67
    "Created: / 7.9.2001 / 14:02:45 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    68
    "Modified: / 7.9.2001 / 14:02:54 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    69
! !
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    70
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    71
!LimitedPrecisionReal class methodsFor:'instance creation'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    72
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    73
new:aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    74
    "catch this message - not allowed for floats/doubles"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    75
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    76
    self error:'Floats/Doubles cannot be created with new:'
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    77
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    78
5989
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    79
!LimitedPrecisionReal class methodsFor:'constants & defaults'!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    80
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    81
e
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    82
    "return the closest approximation of the irrational number e"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    83
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    84
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    85
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    86
    "Modified: / 7.9.2001 / 14:05:02 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    87
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    88
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    89
emax
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    90
    "return the largest exponent"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    91
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    92
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    93
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    94
    "Created: / 7.9.2001 / 14:05:28 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    95
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    96
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    97
emin
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    98
    "return the smallest exponent"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    99
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   100
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   101
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   102
    "Created: / 7.9.2001 / 14:05:35 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   103
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   104
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   105
epsilon
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   106
    "return the maximum relative spacing"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   107
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   108
    ^ self radix raisedTo:(1- self precision)
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   109
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   110
    "Created: / 7.9.2001 / 14:06:41 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   111
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   112
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   113
fmax
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   114
    "return the largest value allowed"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   115
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   116
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   117
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   118
    "Created: / 7.9.2001 / 14:06:56 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   119
    "Modified: / 7.9.2001 / 14:07:15 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   120
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   121
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   122
fmin
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   123
    "return the minimum value allowed"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   124
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   125
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   126
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   127
    "Created: / 7.9.2001 / 14:07:06 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   128
    "Modified: / 7.9.2001 / 14:07:19 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   129
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   130
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   131
pi
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   132
    "return the closest approximation of the irrational number e"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   133
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   134
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   135
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   136
    "Modified: / 7.9.2001 / 14:05:02 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   137
    "Created: / 7.9.2001 / 14:07:35 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   138
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   139
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   140
precision
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   141
    "return the precision (the number of radix digits)"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   142
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   143
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   144
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   145
    "Modified: / 7.9.2001 / 14:05:02 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   146
    "Created: / 7.9.2001 / 14:07:58 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   147
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   148
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   149
radix
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   150
    "return the radix (base)"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   151
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   152
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   153
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   154
    "Modified: / 7.9.2001 / 14:05:02 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   155
    "Created: / 7.9.2001 / 14:08:20 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   156
! !
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   157
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   158
!LimitedPrecisionReal methodsFor:'accessing'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   159
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   160
at:index
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   161
    "redefined to prevent access to individual bytes in a real."
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   162
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   163
    self error:'not allowed for floats/doubles'
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   164
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   165
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   166
at:index put:aValue
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   167
    "redefined to prevent access to individual bytes in a real"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   168
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   169
    self error:'not allowed for floats/doubles'
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   170
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   171
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   172
!LimitedPrecisionReal methodsFor:'arithmetic'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   173
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   174
* aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   175
    "return the product of the receiver and the argument, aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   176
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   177
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   178
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   179
"/    ^ aNumber productFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   180
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   181
    ^ aNumber productFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   182
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   183
    "Modified: 17.4.1996 / 12:35:36 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   184
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   185
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   186
+ aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   187
    "return the sum of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   188
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   189
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   190
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   191
"/    ^ aNumber sumFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   192
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   193
    ^ aNumber sumFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   194
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   195
    "Modified: 17.4.1996 / 12:35:55 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   196
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   197
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   198
- aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   199
    "return the difference of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   200
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   201
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   202
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   203
"/    ^ aNumber differenceFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   204
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   205
    ^ aNumber differenceFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   206
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   207
    "Modified: 17.4.1996 / 12:36:07 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   208
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   209
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   210
/ aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   211
    "return the quotient of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   212
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   213
    ((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
5954
d706efecb134 ZeroDivide has a parameter
Claus Gittinger <cg@exept.de>
parents: 5883
diff changeset
   214
        ^ DivisionByZeroSignal raiseRequestWith:thisContext.
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   215
    ].
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   216
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   217
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   218
"/    ^ aNumber quotientFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   219
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   220
    ^ aNumber quotientFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   221
4455
2d31d0d986be Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 3898
diff changeset
   222
    "Modified: / 17.4.1996 / 12:36:21 / cg"
2d31d0d986be Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 3898
diff changeset
   223
    "Modified: / 26.7.1999 / 10:46:11 / stefan"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   224
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   225
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   226
// aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   227
    "return the integer quotient of dividing the receiver by aNumber with
1882
f5f8a2f201e5 fixed #//
Claus Gittinger <cg@exept.de>
parents: 1865
diff changeset
   228
     truncation towards negative infinity."
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   229
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   230
    ^ (self / aNumber) floor asInteger
1882
f5f8a2f201e5 fixed #//
Claus Gittinger <cg@exept.de>
parents: 1865
diff changeset
   231
f5f8a2f201e5 fixed #//
Claus Gittinger <cg@exept.de>
parents: 1865
diff changeset
   232
    "Modified: 5.11.1996 / 11:45:37 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   233
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   234
5238
f7a816a660a3 categories
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   235
!LimitedPrecisionReal methodsFor:'coercing & converting'!
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   236
2141
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   237
asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   238
    "return the receiver as fixedPoint number.
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   239
     Q: what should the scale be here ?"
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   240
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   241
    ^ self asFraction asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   242
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   243
    "
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   244
     0.3 asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   245
     0.5 asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   246
     (1/5) asFloat asFixedPoint 
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   247
     (1/3) asFloat asFixedPoint 
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   248
     (2/3) asFloat asFixedPoint 
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   249
     (1/8) asFloat asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   250
     3.14159 asFixedPoint
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   251
     0.0000001 asFraction
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   252
     0.0000001 asFixedPoint
2141
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   253
    "
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   254
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   255
    "Modified: / 25.10.1997 / 15:36:54 / cg"
2141
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   256
!
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   257
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   258
asFixedPoint:scale
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   259
    "return the receiver as fixedPoint number with the given
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   260
     number of post-decimal-digits."
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   261
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   262
    ^ self asFraction asFixedPoint:scale
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   263
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   264
    "
3732
bf041aa09cc4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3426
diff changeset
   265
     0.3 asFixedPoint:4     
2141
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   266
     0.3 asFixedPoint:3     
3732
bf041aa09cc4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3426
diff changeset
   267
     0.3 asFixedPoint:2     
bf041aa09cc4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3426
diff changeset
   268
     0.3 asFixedPoint:1     
bf041aa09cc4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3426
diff changeset
   269
     0.3 asFixedPoint:0
bf041aa09cc4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3426
diff changeset
   270
2141
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   271
     0.5 asFixedPoint:3     
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   272
     (1/5) asFloat asFixedPoint:1  
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   273
     (1/8) asFloat asFixedPoint:1  
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   274
     3.14159 asFixedPoint:2       
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   275
     3.14159 asFixedPoint:3       
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   276
     (3.14159 asFixedPoint:2) asFixedPoint:5  
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   277
    "
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   278
3732
bf041aa09cc4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3426
diff changeset
   279
    "Modified: / 5.8.1998 / 13:29:51 / cg"
2141
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   280
!
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   281
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   282
asFraction
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   283
    "Answer a rational number (Integer or Fraction) representing the receiver.
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   284
     This conversion uses the continued fraction method to approximate 
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   285
     a floating point number."
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   286
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   287
    |num1 denom1 num2 denom2 int frac newD temp limit|
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   288
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   289
    limit := (self class unity * 10) raisedTo:self defaultNumberOfDigits.
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   290
    num1 := self truncated. 
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   291
    denom1 := 1.            "The first of two alternating denominators"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   292
    num2 := 1.              "The second numerator"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   293
    denom2 := 0.            "The second denominator--will update"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   294
    int := num1.            "The integer part of self"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   295
    frac := self fractionPart.             
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   296
    [frac = 0] whileFalse:[                
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   297
        newD := 1.0 / frac.                   
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   298
        int := newD truncated.        
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   299
        frac := newD fractionPart.      "save the fractional part for next time"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   300
        temp := num2.                   "old numerator and save it"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   301
        num2 := num1.                         
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   302
        num1 := num1 * int + temp.      "Update first numerator"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   303
        temp := denom2.                 "old denominator and save it"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   304
        denom2 := denom1.                    
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   305
        denom1 := int * denom1 + temp.  "Update first denominator"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   306
        limit < denom1 ifTrue:[
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   307
            "Is ratio past float precision?  If so, pick which of the two ratios to use"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   308
            num2 = 0.0 ifTrue:[
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   309
                "Is second denominator 0?"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   310
                ^ Fraction numerator:num1 denominator:denom1
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   311
            ].
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   312
            ^ Fraction numerator:num2 denominator:denom2
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   313
        ]
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   314
    ].
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   315
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   316
    "If fractional part is zero, return the first ratio"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   317
    denom1 = 1 ifTrue:[
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   318
        "Am i really an Integer?"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   319
        ^ num1 "Yes, return Integer result"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   320
    ].
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   321
    "Otherwise return Fraction result"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   322
    ^ Fraction numerator:num1 denominator:denom1
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   323
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   324
    "
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   325
     1.1 asFraction      
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   326
     1.2 asFraction      
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   327
     0.3 asFraction   
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   328
     0.5 asFraction 
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   329
     (1/5) asFloat asFraction
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   330
     (1/8) asFloat asFraction  
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   331
     (1/13) asFloat asFraction 
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   332
     3.14159 asFraction        
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   333
     3.14159 asFraction asFloat       
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   334
     1.3 asFraction  
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   335
     1.0 asFraction  
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   336
    "
2793
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2388
diff changeset
   337
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   338
    "Modified: / 25.10.1997 / 16:41:19 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   339
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   340
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   341
asInteger
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   342
    "return an integer with same value - might truncate"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   343
3185
1c7bd090a822 removed unused local vars
Claus Gittinger <cg@exept.de>
parents: 3148
diff changeset
   344
    |max maxF|
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   345
2388
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   346
    self isNaN ifTrue:[
3395
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   347
        ^ self class
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   348
            raise:#domainErrorSignal
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   349
            receiver:self
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   350
            selector:#asInteger
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6185
diff changeset
   351
            arguments:#()
3395
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   352
            errorString:'receiver is NaN in #asInteger'
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   353
2388
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   354
    ].
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   355
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   356
    self abs < 2e16 ifTrue:[
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   357
        "/ NOTICE: this must be redefined in float
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   358
        "/ subclasses to handle the smallinteger range;
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   359
        "/ i.e. this may only be invoked for reals
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   360
        "/ which are NOT within the smallInt range.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   361
        "/ otherwise, endless recursion is the consequence.
3426
a648de89ac72 comment
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
   362
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   363
        max := SmallInteger maxVal // 2 + 1.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   364
        maxF := max asFloat.
3426
a648de89ac72 comment
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
   365
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   366
        ^ (self quo:maxF) * max + (self rem:maxF) truncated
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   367
    ].
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   368
    ^ self asTrueFraction
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   369
3137
f334b17f0347 bif speedup in asInteger with large floats
ca
parents: 3060
diff changeset
   370
    "
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   371
     12345.0 asInteger     
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   372
     1e15 asInteger        
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   373
     1e33 asInteger asFloat
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   374
     1e303 asInteger asFloat
3137
f334b17f0347 bif speedup in asInteger with large floats
ca
parents: 3060
diff changeset
   375
    "
2388
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   376
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6185
diff changeset
   377
    "Modified: / 16.11.2001 / 14:15:33 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   378
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   379
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   380
asRational
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   381
    "Answer a Rational number--Integer or Fraction--representing the receiver.
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   382
     Same as asFraction fro st-80 compatibility."
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   383
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   384
    ^ self asFraction
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   385
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   386
    "
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   387
     1.1 asRational      
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   388
     1.2 asRational      
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   389
     0.3 asRational   
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   390
     0.5 asRational 
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   391
     (1/5) asFloat asRational
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   392
     (1/8) asFloat asRational  
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   393
     (1/13) asFloat asRational 
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   394
     3.14159 asRational        
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   395
     3.14159 asRational asFloat       
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   396
     1.3 asRational  
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   397
     1.0 asRational  
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   398
    "
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   399
!
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   400
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   401
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   402
    "return aNumber converted into receivers type"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   403
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   404
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   405
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   406
"/    ^ aNumber asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   407
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   408
    ^ aNumber asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   409
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   410
    "Modified: 17.4.1996 / 12:36:46 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   411
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   412
3898
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   413
fractionalPart
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   414
    "This has been renamed to #fractionPart for ST80 compatibility.
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   415
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   416
     extract the after-decimal fraction part.
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   417
     the floats value is 
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   418
        float truncated + float fractionalPart"
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   419
5868
d497030b1df7 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
   420
    <resource:#obsolete>
d497030b1df7 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
   421
3898
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   422
    self obsoleteMethodWarning:'please use #fractionPart'.
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   423
    ^ self fractionPart
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   424
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   425
    "Modified: / 28.10.1998 / 17:10:12 / cg"
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   426
    "Created: / 28.10.1998 / 17:10:32 / cg"
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   427
!
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   428
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   429
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   430
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   431
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   432
    ^ 80
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   433
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   434
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   435
!LimitedPrecisionReal methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   436
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   437
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   438
    "return true, if the argument is greater"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   439
1201
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   440
"/ as soon as Float are float & Double are doubles,
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   441
"/ use:
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   442
"/    ^ aNumber lessFromDouble:self asDouble
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   443
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   444
    ^ aNumber lessFromFloat:self asFloat
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   445
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   446
    "Modified: 17.4.1996 / 13:34:50 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   447
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   448
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   449
<= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   450
    "return true, if the argument is greater or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   451
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   452
    ^ self retry:#<= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   453
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   454
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   455
= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   456
    "return true, if the arguments value are equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   457
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   458
    ^ self retry:#= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   459
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   460
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   461
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   462
    "return true, if the argument is less"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   463
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   464
    ^ self retry:#> coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   465
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   466
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   467
>= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   468
    "return true, if the argument is less or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   469
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   470
    ^ self retry:#>= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   471
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   472
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   473
~= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   474
    "return true, if the arguments value are not equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   475
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   476
    ^ self retry:#~= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   477
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   478
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   479
!LimitedPrecisionReal methodsFor:'copying'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   480
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   481
deepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   482
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   483
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   484
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   485
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   486
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   487
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   488
deepCopyUsing:aDictionary
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   489
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   490
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   491
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   492
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   493
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   494
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   495
shallowCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   496
    "return a shallow copy of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   497
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   498
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   499
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   500
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   501
simpleDeepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   502
    "return a deep copy of the receiver
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   503
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   504
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   505
    ^ self
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   506
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   507
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   508
!LimitedPrecisionReal methodsFor:'double dispatching'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   509
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   510
differenceFromFraction:aFraction
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   511
    "sent when a fraction does not know how to subtract the receiver, a float"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   512
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   513
    |d|
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   514
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   515
    d := aFraction denominator.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   516
    ^ (aFraction numerator - (self * d)) / d
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   517
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   518
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   519
productFromFraction:aFraction
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   520
    "sent when a fraction does not know how to multiply the receiver, a float"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   521
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   522
    ^ self * aFraction numerator / aFraction denominator
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   523
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   524
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   525
quotientFromFraction:aFraction
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   526
    "sent when a fraction does not know how to divide by the receiver, a float"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   527
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   528
    ^ aFraction numerator / (self * aFraction denominator)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   529
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   530
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   531
sumFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   532
    "sent when a fraction does not know how to add the receiver, a float"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   533
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   534
    |d|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   535
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   536
    d := aFraction denominator.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   537
    ^ (self * d + aFraction numerator) / d
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   538
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   539
5470
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   540
!LimitedPrecisionReal methodsFor:'encoding'!
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   541
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   542
encodeOn:anEncoder with:aParameter
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   543
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   544
    anEncoder encodeFloat:self with:aParameter
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   545
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   546
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   547
! !
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   548
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   549
!LimitedPrecisionReal methodsFor:'printing & storing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   550
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   551
printOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   552
    "append a printed representation of the receiver to
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   553
     the argument, aStream.
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   554
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   555
     LimitedPrecisonReal and its subclasses use #printString instead of
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   556
     #printOn: as basic print mechanism."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   557
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   558
    aStream nextPutAll:self printString
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   559
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   560
    "Modified: / 20.1.1998 / 14:10:46 / stefan"
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   561
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   562
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   563
printString
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   564
    "return a printed representation of the receiver
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   565
     LimitedPrecisonReal and its subclasses use #printString instead of
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   566
     #printOn: as basic print mechanism."
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   567
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   568
    ^ self subclassResponsibility
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   569
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   570
    "Created: / 17.4.1996 / 12:12:20 / cg"
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   571
    "Modified: / 20.1.1998 / 14:10:47 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   572
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   573
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   574
!LimitedPrecisionReal methodsFor:'queries'!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   575
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   576
defaultNumberOfDigits
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   577
    self subclassResponsibility
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   578
!
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   579
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   580
size
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   581
   "redefined since reals are kludgy (ByteArry)"
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   582
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   583
   ^ 0
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   584
! !
5470
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   585
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   586
!LimitedPrecisionReal methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   587
3148
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   588
isFinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   589
   ^ self subclassResponsibility
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   590
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   591
    "Created: / 7.1.1998 / 12:02:06 / stefan"
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   592
!
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   593
6185
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   594
isFloat
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   595
    "return true, if the receiver is some kind of floating point number;
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   596
     false is returned here.
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   597
     Same as #isLimitedPrecisionReal, but a better name ;-)"
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   598
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   599
    ^ true
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   600
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   601
    "Created: / 14.11.2001 / 14:57:55 / cg"
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   602
!
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   603
3148
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   604
isInfinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   605
    "return true, if the receiver is an infinite float (Inf).
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   606
     These are not created by ST/X float operations (they raise an exception);
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   607
     however, inline C-code could produce them ..."
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   608
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   609
    ^ (self isFinite or:[self isNaN]) not.
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   610
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   611
    "
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   612
        1.0 isInfinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   613
        (0.0 uncheckedDivide: 0.0) isInfinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   614
        (1.0 uncheckedDivide: 0.0) isInfinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   615
    "
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   616
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   617
    "Modified: / 7.1.1998 / 12:01:30 / stefan"
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   618
!
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   619
6086
0bd476397581 added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents: 5989
diff changeset
   620
isLimitedPrecisionReal
0bd476397581 added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents: 5989
diff changeset
   621
    "return true, if the receiver is some kind of limited precision real (i.e. floating point) number;
0bd476397581 added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents: 5989
diff changeset
   622
     true is returned here - the method is redefined from Object."
0bd476397581 added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents: 5989
diff changeset
   623
0bd476397581 added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents: 5989
diff changeset
   624
    ^ true
0bd476397581 added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents: 5989
diff changeset
   625
!
0bd476397581 added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents: 5989
diff changeset
   626
2388
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   627
isNaN
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   628
   ^ self subclassResponsibility
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   629
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   630
    "Modified: 12.2.1997 / 16:45:27 / cg"
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   631
!
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   632
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   633
negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   634
    "return true if the receiver is less than zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   635
1201
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   636
"/ as soon as Float are float & Double are doubles,
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   637
"/ use:
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   638
"/    ^ self asDouble negative
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   639
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   640
    ^ self asFloat negative
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   641
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   642
    "Modified: 17.4.1996 / 13:35:00 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   643
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   644
5357
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   645
numberOfBits
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   646
    "return the size (in bits) of the real;
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   647
     typically, this is 64 for Floats and 32 for ShortFloats,
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   648
     but who knows ..."
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   649
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   650
    self subclassResponsibility
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   651
!
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   652
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   653
positive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   654
    "return true if the receiver is greater or equal to zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   655
1201
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   656
"/ as soon as Float are float & Double are doubles,
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   657
"/ use:
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   658
"/    ^ self asDouble positive
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   659
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   660
    ^ self asFloat positive
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   661
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   662
    "Modified: 17.4.1996 / 13:35:10 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   663
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   664
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   665
!LimitedPrecisionReal class methodsFor:'documentation'!
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   666
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   667
version
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6185
diff changeset
   668
    ^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.43 2001-11-16 13:21:26 cg Exp $'
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   669
! !
5989
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   670
LimitedPrecisionReal initialize!