ShortFloat.st
author Claus Gittinger <cg@exept.de>
Sun, 01 Dec 2019 05:28:03 +0100
changeset 25016 cbd04064b803
parent 25003 18856dfc86e4
child 25020 24168eb5923a
permissions -rw-r--r--
#FEATURE by exept class: ShortFloat changed: #mantissa #printfPrintString: class: ShortFloat class comment/format in: #coerce: #emax #emin #fmax #numBitsInMantissa changed: #fmin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1996 by Claus Gittinger
3158
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
     3
	      All Rights Reserved
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
5411
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
    12
"{ Package: 'stx:libbasic' }"
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
    13
17382
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
    14
"{ NameSpace: Smalltalk }"
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
    15
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
LimitedPrecisionReal variableByteSubclass:#ShortFloat
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:''
21872
873afa36c013 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
    18
	classVariableNames:'DefaultPrintFormat DefaultPrintfFormat Pi E Epsilon Ln10 NaN
24949
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
    19
		PositiveInfinity NegativeInfinity Phi Ln2'
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	poolDictionaries:''
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	category:'Magnitude-Numbers'
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
2394
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    24
!ShortFloat primitiveDefinitions!
24951
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    25
%{
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    26
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    27
#include <stdio.h>
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    28
#include <errno.h>
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    29
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    30
#ifndef __OPTIMIZE__
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    31
# define __OPTIMIZE__
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    32
#endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    33
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    34
#define __USE_ISOC9X 1
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    35
#define __USE_ISOC99 1
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    36
#include <math.h>
25003
18856dfc86e4 fmin/fmax
Claus Gittinger <cg@exept.de>
parents: 24986
diff changeset
    37
#include <float.h>
24951
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    38
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    39
#ifndef INT32
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    40
# define INT32 int
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    41
#endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    42
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    43
/*
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    44
 * on some systems errno is a macro ... check for it here
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    45
 */
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    46
#ifndef errno
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    47
 extern errno;
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    48
#endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    49
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    50
#if !defined (__win32__)
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    51
# include <locale.h>
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    52
#endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    53
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    54
#if defined (__aix__)
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    55
# include <float.h>
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    56
#endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    57
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    58
#if defined(__irix__)
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    59
# include <nan.h>
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    60
#endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    61
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    62
#if defined(__linux__)
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    63
# ifndef NAN
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    64
#  include <bits/nan.h>
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    65
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    66
#endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    67
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    68
#if defined(__solaris__) || defined(__sunos__)
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    69
# include <nan.h>
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    70
#endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    71
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    72
#ifdef __win32__
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    73
/*
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    74
 * no finite(x) ?
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    75
 * no isnan(x) ?
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    76
 */
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    77
# ifndef isnan
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    78
#  define isnan(x)      \
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    79
	((((unsigned int *)(&x))[0] == 0x00000000) && \
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    80
	 (((unsigned int *)(&x))[1] == 0xFFF80000))
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    81
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    82
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    83
# ifndef isPositiveInfinity
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    84
#  define isPositiveInfinity(x) \
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    85
	((((unsigned int *)(&x))[0] == 0x00000000) && \
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    86
	 (((unsigned int *)(&x))[1] == 0x7FF00000))
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    87
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    88
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    89
# ifndef isNegativeInfinity
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    90
#  define isNegativeInfinity(x) \
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    91
	((((unsigned int *)(&x))[0] == 0x00000000) && \
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    92
	 (((unsigned int *)(&x))[1] == 0xFFF00000))
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    93
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    94
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    95
# ifndef isinf
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    96
#  define isinf(x) \
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    97
	((((unsigned int *)(&x))[0] == 0x00000000) && \
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    98
	 ((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000))
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
    99
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   100
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   101
# ifndef isfinite
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   102
#  define isfinite(x) (!isinf(x) && !isnan(x))
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   103
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   104
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   105
# ifndef isnanf
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   106
#  define isnanf(x)      \
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   107
	(((unsigned int *)(&x))[0] == 0xFFC00000)
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   108
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   109
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   110
# ifndef isPositiveInfinityf
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   111
#  define isPositiveInfinityf(x)      \
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   112
	(((unsigned int *)(&x))[0] == 0x7F800000)
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   113
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   114
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   115
# ifndef isNegativeInfinityf
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   116
#  define isNegativeInfinityf(x)      \
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   117
	(((unsigned int *)(&x))[0] == 0xFF800000)
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   118
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   119
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   120
# ifndef isinff
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   121
#  define isinff(x)      \
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   122
	((((unsigned int *)(&x))[0] & 0x7FFFFFFF) == 0x7F800000)
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   123
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   124
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   125
# ifndef isfinitef
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   126
#  define isfinitef(x) (!isinff(x) && !isnanf(x))
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   127
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   128
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   129
# define NO_ASINH
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   130
# define NO_ACOSH
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   131
# define NO_ATANH
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   132
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   133
# ifdef __BORLANDC__
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   134
#  define NO_FMODF
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   135
#  define NO_MODFF
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   136
#  define NO_LOG10F
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   137
#  define NO_LOGF
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   138
#  define NO_ABSF
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   139
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   140
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   141
# ifdef __MINGW__
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   142
#  ifndef _STRING_H_INCLUDED_
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   143
#   include <string.h>
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   144
#   define _STRING_H_INCLUDED_
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   145
#  endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   146
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   147
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   148
#endif /* __win32__ */
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   149
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   150
#ifdef __solaris__
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   151
# ifndef isfinite
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   152
#  define isfinite(f) finite((double)(f))
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   153
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   154
#endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   155
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   156
#ifdef __realIX__
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   157
# ifndef isfinite
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   158
#  define isfinite(x)     1
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   159
# endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   160
#endif /* realIX */
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   161
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   162
#ifndef isfinitef
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   163
# define isfinitef(x) isfinite(x)
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   164
#endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   165
#ifndef isnanf
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   166
# define isnanf(x) isnan(x)
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   167
#endif
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   168
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   169
%}
Claus Gittinger <cg@exept.de>
parents: 24949
diff changeset
   170
! !
2394
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
   171
1880
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   172
!ShortFloat class methodsFor:'documentation'!
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
copyright
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
 COPYRIGHT (c) 1996 by Claus Gittinger
3158
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   177
	      All Rights Reserved
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
 This software is furnished under a license and may be used
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
 only in accordance with the terms of that license and with the
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
 inclusion of the above copyright notice.   This software may not
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
 be provided or otherwise made available to, or used by, any
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
 other person.  No title to or ownership of the software is
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
 hereby transferred.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
documentation
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
"
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   192
    ShortFloats represent rational numbers with limited precision.
22785
1d67d6adbbe5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   193
    They use the C-compiler's 'float' format, which is usually the IEEE single float format.
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   194
24459
d465826db5b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24458
diff changeset
   195
    In contrast to Floats (which use the C-compiler's 64bit 'double' format),
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   196
    ShortFloats give you 32 bit floats.
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    Notice, that ST/X Floats are what Doubles are in ST-80 and ShortFloats are
14719
a354c1ef4a56 comment
Claus Gittinger <cg@exept.de>
parents: 14718
diff changeset
   199
    ST-80's Floats respectively. The reason was to make ST/X's floats compatible
24459
d465826db5b5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24458
diff changeset
   200
    to bothe VisualWorks and other Smalltalks, which use C-doubles for the Float class
22785
1d67d6adbbe5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   201
    (i.e. VisualST and V'Age).
14719
a354c1ef4a56 comment
Claus Gittinger <cg@exept.de>
parents: 14718
diff changeset
   202
    Thus, STX's Float precision is not worse than that of other ST's.
a354c1ef4a56 comment
Claus Gittinger <cg@exept.de>
parents: 14718
diff changeset
   203
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
    WARNING:
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   205
	The layout of shortFloat instances is known by the runtime system and the compiler;
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   206
	you may not add instance variables here.
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   207
	Also, subclassing is complicated by the fact, that the VM creates floats/shortFloats,
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   208
	and does some of its float-checks by an identity compare with the ShortFloat-class.
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   209
	(i.e. your subclasses instances may not be recognized as float-like objects,
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   210
	 thus mixed mode arithmetic will always coerce them, effectively slowing things down).
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   211
	This may be changed, to use a flag bit in the class.
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   213
    Mixed mode arithmetic:
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   214
	shortFloat op shortFloat   -> shortFloat
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   215
	shortFloat op fix         -> shortFloat
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   216
	shortFloat op fraction    -> shortFloat
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   217
	shortFloat op integer     -> shortFloat
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   218
	shortFloat op longFloat   -> longFloat
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   219
	shortFloat op float       -> float
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   220
	shortFloat op complex     -> complex
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   221
7405
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
   222
    Representation:
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   223
	    32bit single precision IEEE floats
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   224
	    23 bit mantissa + 1 hidden bit, providing a precision of 24bits,
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   225
	    8 bit exponent,
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   226
	    6 decimal digits (approx.)
7405
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
   227
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
   228
    Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
   229
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   230
    [author:]
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   231
	Claus Gittinger
1556
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   232
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   233
    [see also:]
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   234
	Number
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   235
	Float LongFloat Fraction FixedPoint Integer Complex
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   236
	FloatArray DoubleArray
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
1880
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   240
!ShortFloat class methodsFor:'instance creation'!
1207
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   241
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   242
basicNew
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   243
    "return a new shortFloat - here we return 0.0
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   244
     - shortFloats are usually NOT created this way ...
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   245
     Its implemented here to allow things like binary store & load
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   246
     of shortFloats. (but even this support will go away eventually, its not
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   247
     a good idea to store the bits of a float - the reader might have a
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   248
     totally different representation - so floats will eventually be
1207
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   249
     binary stored in a device independent format."
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   250
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   251
%{  /* NOCONTEXT */
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   252
    OBJ newFloat;
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   253
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   254
    __qMKSFLOAT(newFloat, 0.0);
1207
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   255
    RETURN (newFloat);
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   256
%}
3158
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   257
!
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   258
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   259
fastFromString:aString at:startIndex
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   260
    "return the next ShortFloat from the string starting at startIndex.
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   261
     No spaces are skipped.
23478
33cb7a201308 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23475
diff changeset
   262
     Raises an exception, if the startIndex is not valid.
33cb7a201308 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23475
diff changeset
   263
     Returns garbage if the argument string is not a valid float number.
33cb7a201308 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23475
diff changeset
   264
33cb7a201308 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23475
diff changeset
   265
     This is a specially tuned entry (using a low-level C-call to atof).
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   266
     It has been added to allow high speed string decomposition
23478
33cb7a201308 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23475
diff changeset
   267
     into numbers, especially for mass-data (reading millions of floats)."
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   268
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   269
%{   /* NOCONTEXT */
12486
f1ef886832f1 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11945
diff changeset
   270
     if (__isStringLike(aString) && __isSmallInteger(startIndex)) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   271
	char *cp = (char *)(__stringVal(aString));
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   272
	int idx = __intVal(startIndex) - 1;
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   273
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   274
	if ((unsigned)idx < __stringSize(aString)) {
24975
fdf3a5b2f6b6 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24964
diff changeset
   275
#ifndef NO_STRTOF
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   276
	    float strtof(const char *, char**);
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   277
	    float val = strtof(cp+idx, NULL);
24975
fdf3a5b2f6b6 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24964
diff changeset
   278
#else
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   279
# ifndef NO_STRTOD
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   280
	    double strtod(const char *, char**);
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   281
	    double val = strtod(cp+idx, NULL);
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   282
# else
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   283
	    double atof(const char *);
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   284
	    double val = atof(cp + idx);
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   285
# endif
24975
fdf3a5b2f6b6 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24964
diff changeset
   286
#endif
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   287
	    RETURN (__MKSFLOAT(val));
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   288
	}
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   289
     }
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   290
%}.
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   291
     self primitiveFailed.
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   292
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   293
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   294
     ShortFloat fastFromString:'123.45' at:1
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   295
     ShortFloat fastFromString:'123.45' at:2
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   296
     ShortFloat fastFromString:'123.45E4' at:1
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   297
     ShortFloat fastFromString:'hello123.45E4' at:6
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   298
     ShortFloat fastFromString:'12345' at:1
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   299
     ShortFloat fastFromString:'12345' at:2
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   300
     ShortFloat fastFromString:'12345' at:3
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   301
     ShortFloat fastFromString:'12345' at:4
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   302
     ShortFloat fastFromString:'12345' at:5
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   303
     ShortFloat fastFromString:'12345' at:6
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   304
     ShortFloat fastFromString:'12345' at:0
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   305
     ShortFloat fastFromString:'hello123.45E4' at:1
23478
33cb7a201308 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23475
diff changeset
   306
    "
33cb7a201308 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23475
diff changeset
   307
33cb7a201308 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23475
diff changeset
   308
    "
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   309
     Time millisecondsToRun:[
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   310
	1000000 timesRepeat:[
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   311
	    ShortFloat readFrom:'123.45'
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   312
	]
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   313
     ]
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   314
    "
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   315
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   316
    "
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   317
     Time millisecondsToRun:[
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   318
	1000000 timesRepeat:[
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   319
	    ShortFloat fastFromString:'123.45' at:1
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   320
	]
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   321
     ]
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   322
    "
23475
a7369668089d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22922
diff changeset
   323
23478
33cb7a201308 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23475
diff changeset
   324
    "Modified (comment): / 27-10-2018 / 08:58:13 / Claus Gittinger"
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   325
!
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   326
15015
b86b7390d9ed class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 15014
diff changeset
   327
fromIEEE32Bit: anInteger
b86b7390d9ed class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 15014
diff changeset
   328
    "creates a float, given the four native float bytes as an integer"
b86b7390d9ed class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 15014
diff changeset
   329
b86b7390d9ed class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 15014
diff changeset
   330
%{  /* NOCONTEXT */
b86b7390d9ed class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 15014
diff changeset
   331
b86b7390d9ed class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 15014
diff changeset
   332
    REGISTER union {
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
   333
	unsigned int    i;
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
   334
	float           f;
15015
b86b7390d9ed class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 15014
diff changeset
   335
    } r;
b86b7390d9ed class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 15014
diff changeset
   336
b86b7390d9ed class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 15014
diff changeset
   337
    r.i = __unsignedLongIntVal( anInteger );
15019
63c17b702b7c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 15018
diff changeset
   338
    RETURN( __MKSFLOAT(r.f) );
15015
b86b7390d9ed class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 15014
diff changeset
   339
%}
17220
614c3a1d3c73 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16670
diff changeset
   340
614c3a1d3c73 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16670
diff changeset
   341
    "
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
   342
	ShortFloat fromIEEE32Bit:(#[64 73 15 219] asInteger)
17220
614c3a1d3c73 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16670
diff changeset
   343
    "
1207
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   344
! !
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   345
12915
d80685e8f20e #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12629
diff changeset
   346
!ShortFloat class methodsFor:'accessing'!
d80685e8f20e #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12629
diff changeset
   347
d80685e8f20e #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12629
diff changeset
   348
defaultPrintFormat
24953
13bc1e8b12ab #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24951
diff changeset
   349
    "/ by default, I will print 7 digits
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   350
    "/  ShortFloat pi   -> 3.141593
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   351
    "/  Float pi        -> 3.14159265358979
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   352
    "/  LongFloat pi    -> 3.141592653589793239
24953
13bc1e8b12ab #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24951
diff changeset
   353
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
   354
    ^ DefaultPrintFormat
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
   355
!
12915
d80685e8f20e #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12629
diff changeset
   356
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
   357
defaultPrintFormat:aString
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
   358
    DefaultPrintFormat := aString.
12915
d80685e8f20e #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12629
diff changeset
   359
! !
d80685e8f20e #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12629
diff changeset
   360
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   361
!ShortFloat class methodsFor:'binary storage'!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   362
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   363
readBinaryIEEESingleFrom:aStream
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   364
    "read a float value from the binary stream, aStream,
14924
7115c6830ed8 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14922
diff changeset
   365
     interpreting the next bytes as an IEEE formatted 4-byte float.
7115c6830ed8 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14922
diff changeset
   366
     The bytes are read in the native byte order (i.e.lsb on intel)"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   368
    |f|
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
21878
316b3400a392 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21872
diff changeset
   370
    f := self basicNew.
15012
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   371
    self readBinaryIEEESingleFrom:aStream into:f MSB:(UninterpretedBytes isBigEndian).
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   372
    ^ f
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   373
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   374
    "not part of libboss, as this is also used by others (TIFFReader)"
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   375
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   376
    "Created: / 16-04-1996 / 21:00:35 / cg"
21878
316b3400a392 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21872
diff changeset
   377
    "Modified: / 21-06-2017 / 10:38:31 / cg"
15012
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   378
!
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   379
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   380
readBinaryIEEESingleFrom:aStream MSB:msbFirst
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   381
    "read a float value from the binary stream, aStream,
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   382
     interpreting the next bytes as an IEEE formatted 4-byte float.
15014
f3fb1faff91f class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 15012
diff changeset
   383
     The bytes are read in the soecified byte order"
15012
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   384
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   385
    |f|
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   386
21878
316b3400a392 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21872
diff changeset
   387
    f := self basicNew.
15012
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   388
    self readBinaryIEEESingleFrom:aStream into:f MSB:msbFirst.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   389
    ^ f
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
9636
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   391
    "not part of libboss, as this is also used by others (TIFFReader)"
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   392
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   393
    "Created: / 16-04-1996 / 21:00:35 / cg"
21878
316b3400a392 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21872
diff changeset
   394
    "Modified: / 21-06-2017 / 10:38:35 / cg"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
19617
9ba857aed07d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19570
diff changeset
   397
readBinaryIEEESingleFrom:aStream into:aBasicNewShortFloat
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   398
    "read a float value from the binary stream, aStream,
14922
30546dbb18c6 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14920
diff changeset
   399
     interpreting the next bytes as an IEEE formatted 4-byte float.
14924
7115c6830ed8 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14922
diff changeset
   400
     The bytes are read in the native byte order (i.e.lsb on intel)"
14922
30546dbb18c6 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14920
diff changeset
   401
19617
9ba857aed07d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19570
diff changeset
   402
    ^ self readBinaryIEEESingleFrom:aStream into:aBasicNewShortFloat MSB:(UninterpretedBytes isBigEndian)
14922
30546dbb18c6 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14920
diff changeset
   403
30546dbb18c6 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14920
diff changeset
   404
    "Modified: / 23-08-2006 / 16:01:52 / cg"
30546dbb18c6 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14920
diff changeset
   405
!
30546dbb18c6 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14920
diff changeset
   406
19617
9ba857aed07d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19570
diff changeset
   407
readBinaryIEEESingleFrom:aStream into:aBasicNewShortFloat MSB:msb
14922
30546dbb18c6 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14920
diff changeset
   408
    "read a float value from the binary stream, aStream,
30546dbb18c6 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14920
diff changeset
   409
     interpreting the next bytes as an IEEE formatted 4-byte float.
30546dbb18c6 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14920
diff changeset
   410
     If msb is true, the stream bytes are most-significant-first."
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   411
21878
316b3400a392 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21872
diff changeset
   412
    aBasicNewShortFloat class == self ifFalse:[self error:'not a ShortFloat'].
6574
788f5a36dcb1 Define #precision, #radix
Stefan Vogel <sv@exept.de>
parents: 6063
diff changeset
   413
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   414
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   415
     this implementation is wrong: does not work on non-IEEE machines
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   416
     (to date all machines where ST/X is running on use
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   417
      IEEE float format. Need more here, when porting ST/X to 370's)
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   418
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   419
    self isIEEEFormat ifFalse:[self error:'unsupported operation'].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   420
14922
30546dbb18c6 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14920
diff changeset
   421
    (UninterpretedBytes isBigEndian == msb) ifFalse:[
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
   422
	"swap the bytes"
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
   423
	4 to:1 by:-1 do:[:i |
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
   424
	    aBasicNewShortFloat basicAt:i put:(aStream next)
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
   425
	].
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
   426
	^ self
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   427
    ].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   428
    1 to:4 do:[:i |
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
   429
	aBasicNewShortFloat basicAt:i put:aStream next
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   430
    ]
9636
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   431
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   432
    "not part of libboss, as this is also used by others (TIFFReader)"
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   433
21878
316b3400a392 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21872
diff changeset
   434
    "Modified: / 21-06-2017 / 10:36:28 / cg"
6574
788f5a36dcb1 Define #precision, #radix
Stefan Vogel <sv@exept.de>
parents: 6063
diff changeset
   435
!
788f5a36dcb1 Define #precision, #radix
Stefan Vogel <sv@exept.de>
parents: 6063
diff changeset
   436
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   437
storeBinaryIEEESingle:aFloat on:aStream
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   438
    "store aFloat as an IEEE formatted 4-byte float
14924
7115c6830ed8 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14922
diff changeset
   439
     onto the binary stream, aStream.
7115c6830ed8 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14922
diff changeset
   440
     The bytes are written in the native byte order (i.e.lsb on intel)"
7115c6830ed8 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14922
diff changeset
   441
7115c6830ed8 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14922
diff changeset
   442
    self storeBinaryIEEESingle:aFloat on:aStream MSB:(UninterpretedBytes isBigEndian).
7115c6830ed8 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14922
diff changeset
   443
!
7115c6830ed8 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14922
diff changeset
   444
7115c6830ed8 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14922
diff changeset
   445
storeBinaryIEEESingle:aFloat on:aStream MSB:msb
7115c6830ed8 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14922
diff changeset
   446
    "store aFloat as an IEEE formatted 4-byte float
7115c6830ed8 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14922
diff changeset
   447
     onto the binary stream, aStream.
7115c6830ed8 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14922
diff changeset
   448
     If msb is true, the stream bytes are written most-significant-first."
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   449
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   450
    |float|
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   451
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   452
    float := aFloat asShortFloat.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   453
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   454
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   455
     this implementation is wrong: does not work on non-IEEE machines
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   456
     (to date all machines where ST/X is running on use
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   457
      IEEE float format. Need more here, when porting ST/X to 370's)
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   458
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   459
    self isIEEEFormat ifFalse:[self error:'unsupported operation'].
6574
788f5a36dcb1 Define #precision, #radix
Stefan Vogel <sv@exept.de>
parents: 6063
diff changeset
   460
14924
7115c6830ed8 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14922
diff changeset
   461
    (UninterpretedBytes isBigEndian == msb) ifFalse:[
14931
0de2fc03f23a mingw fixes
Claus Gittinger <cg@exept.de>
parents: 14924
diff changeset
   462
	"swap the bytes"
0de2fc03f23a mingw fixes
Claus Gittinger <cg@exept.de>
parents: 14924
diff changeset
   463
	4 to:1 by:-1 do:[:i |
0de2fc03f23a mingw fixes
Claus Gittinger <cg@exept.de>
parents: 14924
diff changeset
   464
	    aStream nextPut:(float basicAt:i).
0de2fc03f23a mingw fixes
Claus Gittinger <cg@exept.de>
parents: 14924
diff changeset
   465
	].
0de2fc03f23a mingw fixes
Claus Gittinger <cg@exept.de>
parents: 14924
diff changeset
   466
	^ self
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   467
    ].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   468
    1 to:4 do:[:i |
14931
0de2fc03f23a mingw fixes
Claus Gittinger <cg@exept.de>
parents: 14924
diff changeset
   469
	aStream nextPut:(float basicAt:i).
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   470
    ]
9636
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   471
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   472
    "not part of libboss, as this is also used by others (TIFFReader)"
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   473
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   474
    "Modified: / 23-08-2006 / 16:01:55 / cg"
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   475
! !
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   476
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
   477
!ShortFloat class methodsFor:'class initialization'!
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
   478
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
   479
initialize
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
   480
    DefaultPrintFormat := '.7'.  "/ print 7 valid digits
21868
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21858
diff changeset
   481
    DefaultPrintfFormat := '%7f'.
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
   482
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
   483
    "
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
   484
     self initialize
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
   485
    "
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
   486
! !
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
   487
21872
873afa36c013 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   488
!ShortFloat class methodsFor:'coercing & converting'!
873afa36c013 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   489
873afa36c013 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   490
coerce:aNumber
25016
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   491
    "convert the argument aNumber into an instance of the receiver (class) and return it."
21872
873afa36c013 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   492
873afa36c013 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   493
    ^ aNumber asShortFloat.
873afa36c013 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   494
! !
873afa36c013 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   495
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   496
!ShortFloat class methodsFor:'constants'!
6574
788f5a36dcb1 Define #precision, #radix
Stefan Vogel <sv@exept.de>
parents: 6063
diff changeset
   497
21858
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   498
NaN
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   499
    "return a shortFloat which represents not-a-Number (i.e. an invalid number)"
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   500
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   501
    NaN isNil ifTrue:[
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   502
	NaN := super NaN
21858
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   503
    ].
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   504
    ^ NaN
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   505
24261
471fee9a83c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24204
diff changeset
   506
    "
471fee9a83c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24204
diff changeset
   507
     self NaN
471fee9a83c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24204
diff changeset
   508
    "
471fee9a83c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24204
diff changeset
   509
21858
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   510
    "Created: / 20-06-2017 / 13:44:12 / cg"
24261
471fee9a83c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24204
diff changeset
   511
    "Modified (comment): / 06-06-2019 / 16:53:34 / Claus Gittinger"
21858
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   512
!
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   513
7392
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   514
e
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   515
    "return the constant e as ShortFloat"
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   516
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
   517
    E isNil ifTrue:[
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
   518
	E := Float e asShortFloat
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
   519
    ].
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
   520
    ^ E
7392
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   521
!
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   522
24964
0236232a98e1 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24953
diff changeset
   523
eBias
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   524
    "Answer the exponent's bias;
24964
0236232a98e1 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24953
diff changeset
   525
     that is the offset of the zero exponent when stored"
0236232a98e1 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24953
diff changeset
   526
0236232a98e1 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24953
diff changeset
   527
    ^ 127
0236232a98e1 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24953
diff changeset
   528
!
0236232a98e1 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24953
diff changeset
   529
21858
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   530
infinity
24293
758f8a1703cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24284
diff changeset
   531
    "return a shortFloat which represents positive infinity (for my instances)"
21858
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   532
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   533
    PositiveInfinity isNil ifTrue:[
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   534
	PositiveInfinity := Float infinity asShortFloat
21858
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   535
    ].
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   536
    ^ PositiveInfinity
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   537
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   538
    "Created: / 20-06-2017 / 13:44:45 / cg"
24293
758f8a1703cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24284
diff changeset
   539
    "Modified (comment): / 08-06-2019 / 14:32:27 / Claus Gittinger"
21858
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   540
!
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   541
21829
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   542
ln10
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   543
    "return the natural logarithm of 10 as a shortFloat"
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   544
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   545
    Ln10 isNil ifTrue:[
21834
1fe471f18a2e oops - no log10f under win32
Claus Gittinger <cg@exept.de>
parents: 21829
diff changeset
   546
	Ln10 := Float ln10 asShortFloat
21829
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   547
    ].
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   548
    ^ Ln10
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   549
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   550
    "
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   551
     self ln10
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   552
    "
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   553
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   554
    "Created: / 16-06-2017 / 11:09:37 / cg"
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   555
!
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   556
24949
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
   557
ln2
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
   558
    "return the natural logarithm of 2 as a shortFloat"
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
   559
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
   560
    Ln2 isNil ifTrue:[
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   561
	Ln2 := Float ln2 asShortFloat
24949
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
   562
    ].
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
   563
    ^ Ln2
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
   564
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
   565
    "
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
   566
     self ln2
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
   567
    "
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
   568
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
   569
    "Created: / 16-06-2017 / 11:09:37 / cg"
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
   570
!
e83292eea636 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24947
diff changeset
   571
21858
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   572
negativeInfinity
24303
8a479a66cb74 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24293
diff changeset
   573
    "return a shortFloat which represents negative infinity (for my instances).
8a479a66cb74 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24293
diff changeset
   574
     Warning: do not compare equal against infinities;
8a479a66cb74 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24293
diff changeset
   575
     instead, check using isFinite or isInfinite"
21858
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   576
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   577
    NegativeInfinity isNil ifTrue:[
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   578
	NegativeInfinity := Float negativeInfinity asShortFloat
21858
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   579
    ].
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   580
    ^ NegativeInfinity
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   581
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   582
    "Created: / 20-06-2017 / 13:45:08 / cg"
24303
8a479a66cb74 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24293
diff changeset
   583
    "Modified (comment): / 09-06-2019 / 12:57:11 / Claus Gittinger"
21858
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   584
!
5ae229caf43e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21850
diff changeset
   585
24933
13f40732617d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24701
diff changeset
   586
phi
13f40732617d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24701
diff changeset
   587
    "return the constant phi as ShortFloat"
13f40732617d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24701
diff changeset
   588
13f40732617d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24701
diff changeset
   589
    Phi isNil ifTrue:[
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   590
	Phi := Float phi asShortFloat
24933
13f40732617d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24701
diff changeset
   591
    ].
13f40732617d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24701
diff changeset
   592
    ^ Phi
13f40732617d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24701
diff changeset
   593
!
13f40732617d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24701
diff changeset
   594
7392
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   595
pi
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   596
    "return the constant pi as ShortFloat"
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   597
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
   598
    Pi isNil ifTrue:[
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
   599
	Pi := Float pi asShortFloat
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
   600
    ].
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
   601
    ^ Pi
7392
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   602
!
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   603
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   604
unity
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1207
diff changeset
   605
    "return the neutral element for multiplication (1.0) as ShortFloat"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   606
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   607
    ^ 1.0 asShortFloat
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   608
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1207
diff changeset
   609
    "Modified: 23.4.1996 / 09:26:51 / cg"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   610
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   611
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   612
zero
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1207
diff changeset
   613
    "return the neutral element for addition (0.0) as ShortFloat"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   614
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   615
    ^ 0.0 asShortFloat
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   616
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1207
diff changeset
   617
    "Modified: 23.4.1996 / 09:26:45 / cg"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   618
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   619
21829
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   620
!ShortFloat class methodsFor:'queries'!
21149
b8ceb5aff633 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20706
diff changeset
   621
21829
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   622
defaultPrintPrecision
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   623
    "return the number of decimal digits printed by default"
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   624
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   625
    ^ 5
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   626
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   627
    "
21834
1fe471f18a2e oops - no log10f under win32
Claus Gittinger <cg@exept.de>
parents: 21829
diff changeset
   628
     ShortFloat defaultPrintPrecision
1fe471f18a2e oops - no log10f under win32
Claus Gittinger <cg@exept.de>
parents: 21829
diff changeset
   629
     Float defaultPrintPrecision
1fe471f18a2e oops - no log10f under win32
Claus Gittinger <cg@exept.de>
parents: 21829
diff changeset
   630
     LongFloat defaultPrintPrecision
21829
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   631
    "
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   632
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   633
    "Created: / 17-06-2017 / 02:59:31 / cg"
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
   634
!
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   635
25016
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   636
emax
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   637
    "The largest exponent value allowed by instances of this class."
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   638
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   639
%{  /* NOCONTEXT */
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   640
#include <float.h>
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   641
#if defined(FLT_MAX_EXP)
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   642
    RETURN(__MKSMALLINT(FLT_MAX_EXP));
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   643
#endif
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   644
%}.
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   645
    ^ super emax
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   646
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   647
    "
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   648
     1.0 asShortFloat fmax  -> 1.189731495357231765E+4932
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   649
     1.0 asShortFloat fmin  -> 3.362103143112093506E-4932
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   650
     1.0 asShortFloat emin  -> -16381
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   651
     1.0 asShortFloat emax  -> 128
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   652
    "
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   653
!
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   654
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   655
emin
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   656
    "The largest exponent value allowed by instances of this class."
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   657
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   658
%{  /* NOCONTEXT */
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   659
#include <float.h>
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   660
#if defined(FLT_MIN_EXP)
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   661
    RETURN(__MKSMALLINT(FLT_MIN_EXP));
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   662
#endif
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   663
%}.
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   664
    ^ super emin
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   665
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   666
    "
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   667
     1.0 asShortFloat fmax  -> 1.189731495357231765E+4932
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   668
     1.0 asShortFloat fmin  -> 3.362103143112093506E-4932
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   669
     1.0 asShortFloat emin  -> -125
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   670
     1.0 asShortFloat emax  -> 128
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   671
    "
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   672
!
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   673
24323
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   674
epsilon
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   675
    "return the maximum relative spacing of instances of mySelf
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   676
     (i.e. the value-delta of the least significant bit)"
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   677
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   678
    Epsilon isNil ifTrue:[
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   679
	Epsilon := self computeEpsilon.
24323
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   680
    ].
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   681
    ^ Epsilon
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   682
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   683
    "
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   684
     self epsilon
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   685
    "
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   686
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   687
    "Modified (comment): / 21-06-2017 / 13:56:47 / cg"
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   688
    "Modified (comment): / 10-05-2018 / 01:09:13 / stefan"
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   689
    "Modified (comment): / 10-06-2019 / 21:22:03 / Claus Gittinger"
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   690
!
e42ad2030cf5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24303
diff changeset
   691
6898
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   692
exponentCharacter
24324
cbecbcd80faf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24323
diff changeset
   693
    "return the character used to print between mantissa an exponent.
cbecbcd80faf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24323
diff changeset
   694
     Also used by the scanner when reading numbers."
cbecbcd80faf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24323
diff changeset
   695
6898
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   696
    ^ $e
24324
cbecbcd80faf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24323
diff changeset
   697
cbecbcd80faf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24323
diff changeset
   698
    "Modified (comment): / 10-06-2019 / 21:27:52 / Claus Gittinger"
6898
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   699
!
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   700
25016
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   701
fmax
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   702
    "The largest exponent value allowed by instances of this class."
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   703
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   704
%{  /* NOCONTEXT */
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   705
#include <float.h>
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   706
#if defined(FLT_MAX)
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   707
    RETURN(__MKSFLOAT(FLT_MAX));
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   708
#endif
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   709
%}.
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   710
    ^ super fmax
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   711
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   712
    "
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   713
     1.0 asShortFloat fmax  -> 3.402823e+38
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   714
     1.0 asShortFloat fmin  -> 1.175494e-38
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   715
     1.0 asShortFloat emin  -> -125
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   716
     1.0 asShortFloat emax  -> 128
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   717
    "
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   718
!
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   719
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   720
fmin
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   721
    "The largest exponent value allowed by instances of this class."
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   722
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   723
%{  /* NOCONTEXT */
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   724
#include <float.h>
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   725
#if defined(FLT_MIN)
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   726
    RETURN(__MKSFLOAT(FLT_MIN));
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   727
#endif
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   728
%}.
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   729
    ^ super fmin
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   730
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   731
    "
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   732
     1.0 asShortFloat fmax  -> 3.40282346638529E+38
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   733
     1.0 asShortFloat fmin  -> 1.175494e-38
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   734
     1.0 asShortFloat emin  -> -125
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   735
     1.0 asShortFloat emax  -> 128
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   736
    "
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   737
!
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   738
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   739
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   740
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   741
     Here, true is returned for myself, false for subclasses."
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   742
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   743
    ^ self == ShortFloat
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   744
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   745
    "Modified: 23.4.1996 / 16:00:23 / cg"
3427
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   746
!
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   747
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   748
numBitsInExponent
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   749
    "answer the number of bits in the exponent
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   750
     This is an IEEE float, where 8 bits are available:
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
   751
	seeeeeee emmmmmmm mmmmmmmm mmmmmmmm
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   752
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   753
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   754
    ^ 8
24204
673f36f5844d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24189
diff changeset
   755
673f36f5844d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24189
diff changeset
   756
    "
673f36f5844d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24189
diff changeset
   757
     1.0 asShortFloat numBitsInExponent
673f36f5844d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24189
diff changeset
   758
    "
673f36f5844d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24189
diff changeset
   759
673f36f5844d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24189
diff changeset
   760
    "Modified (comment): / 28-05-2019 / 08:55:35 / Claus Gittinger"
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   761
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   762
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   763
numBitsInMantissa
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   764
    "answer the number of bits in the mantissa.
25016
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   765
     This is an IEEE float, where 23 bits are available 
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   766
     (the hidden bit is not counted here):
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   767
        seeeeeee emmmmmmm mmmmmmmm mmmmmmmm
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   768
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   769
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   770
    ^ 23
25016
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   771
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   772
    "
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   773
     1.0 asShortFloat numBitsInExponent 8
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   774
     1.0 asShortFloat numBitsInMantissa 23
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   775
     1.0 asShortFloat precision         24
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   776
     1.0 asShortFloat decimalPrecision  7
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   777
     1.0 asShortFloat eBias             127
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   778
     1.0 asShortFloat emin              -126
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   779
     1.0 asShortFloat emax              127
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   780
     1.0 asShortFloat fmin              1.17549435082229E-38
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   781
     1.0 asShortFloat fmax              3.40282346638529E+38
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
   782
    "
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   783
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   784
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   785
precision
24261
471fee9a83c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24204
diff changeset
   786
    "answer the precision (the number of bits in the mantissa) of a ShortFloat (in bits)
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   787
     This is an IEEE float, where only the fraction from the normalized mantissa is stored
9149
3fb15c4d83d8 comment
Claus Gittinger <cg@exept.de>
parents: 9121
diff changeset
   788
     and so there is a hidden bit and the mantissa is actually represented by 24 binary digits
3fb15c4d83d8 comment
Claus Gittinger <cg@exept.de>
parents: 9121
diff changeset
   789
     (although only 23 are needed in the binary representation)"
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   790
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   791
    ^  24
19325
a7285364ffb1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18852
diff changeset
   792
a7285364ffb1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18852
diff changeset
   793
    "
a7285364ffb1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18852
diff changeset
   794
     self numBitsInMantissa + 1
a7285364ffb1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18852
diff changeset
   795
     self precision
a7285364ffb1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18852
diff changeset
   796
    "
24261
471fee9a83c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24204
diff changeset
   797
471fee9a83c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24204
diff changeset
   798
    "Modified (comment): / 06-06-2019 / 13:23:53 / Claus Gittinger"
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   799
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   800
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   801
radix
24439
2701503c110a #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24330
diff changeset
   802
    "answer the radix of a ShortFloat's exponent
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   803
     This is an IEEE float, which is represented as binary"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   804
9149
3fb15c4d83d8 comment
Claus Gittinger <cg@exept.de>
parents: 9121
diff changeset
   805
    ^ 2 "must be careful here, whenever ST/X is used on a VAX or a 370"
24439
2701503c110a #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24330
diff changeset
   806
2701503c110a #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24330
diff changeset
   807
    "Modified (comment): / 19-07-2019 / 17:28:40 / Claus Gittinger"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   808
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   809
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   810
!ShortFloat methodsFor:'arithmetic'!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   812
* aNumber
11730
eabe6364c89b comment
Claus Gittinger <cg@exept.de>
parents: 11720
diff changeset
   813
    "return the product of the receiver and the argument."
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   814
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   815
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   816
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   817
    OBJ newFloat;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   818
    float result;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   819
    double dResult;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   820
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   821
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   822
	result = __shortFloatVal(self) * (float)(__intVal(aNumber));
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   823
retResult:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   824
	__qMKSFLOAT(newFloat, result);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   825
	RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   826
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   827
    if (__isShortFloat(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   828
	result = __shortFloatVal(self) * __shortFloatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   829
	goto retResult;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   830
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   831
    if (__isFloatLike(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   832
	dResult = (double) __shortFloatVal(self)* __floatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   833
	__qMKFLOAT(newFloat, dResult);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   834
	RETURN ( newFloat );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   835
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   836
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   837
    ^ aNumber productFromShortFloat:self
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   838
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   839
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   840
+ aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   841
    "return the sum of the receiver and the argument, aNumber"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   842
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   843
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   844
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   845
    OBJ newFloat;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   846
    float result;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   847
    double dResult;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   848
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   849
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   850
	result = __shortFloatVal(self) + (float)(__intVal(aNumber));
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   851
retResult:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   852
	__qMKSFLOAT(newFloat, result);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   853
	RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   854
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   855
    if (__isShortFloat(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   856
	result = __shortFloatVal(self) + __shortFloatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   857
	goto retResult;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   858
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   859
    if (__isFloatLike(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   860
	dResult = (double) __shortFloatVal(self) + __floatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   861
	__qMKFLOAT(newFloat, dResult);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   862
	RETURN ( newFloat );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   863
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   864
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   865
    ^ aNumber sumFromShortFloat:self
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   866
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   867
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   868
- aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   869
    "return the difference of the receiver and the argument, aNumber"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   870
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   871
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   872
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   873
    OBJ newFloat;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   874
    float result;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   875
    double dResult;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   876
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   877
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   878
	result = __shortFloatVal(self) - (float)(__intVal(aNumber));
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   879
retResult:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   880
	__qMKSFLOAT(newFloat, result);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   881
	RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   882
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   883
    if (__isShortFloat(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   884
	result = __shortFloatVal(self) - __shortFloatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   885
	goto retResult;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   886
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   887
    if (__isFloatLike(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   888
	dResult = (double) __shortFloatVal(self) - __floatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   889
	__qMKFLOAT(newFloat, dResult);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   890
	RETURN ( newFloat );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   891
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   892
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   893
    ^ aNumber differenceFromShortFloat:self
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   894
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   895
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   896
/ aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   897
    "return the quotient of the receiver and the argument, aNumber"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   898
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   899
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   900
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   901
    OBJ newFloat;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   902
    float result, val;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   903
    double dResult, dVal;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   904
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   905
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   906
	if (aNumber != __mkSmallInteger(0)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   907
	    result = __shortFloatVal(self) / (float)(__intVal(aNumber));
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   908
retResult:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   909
	    __qMKSFLOAT(newFloat, result);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   910
	    RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   911
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   912
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   913
    if (__isShortFloat(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   914
	val = __shortFloatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   915
	if (val != 0.0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   916
	    result = __shortFloatVal(self) / val;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   917
	    goto retResult;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   918
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   919
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   920
    if (__isFloatLike(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   921
	dVal = __floatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   922
	if (dVal != 0.0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   923
	    dResult = (double) __shortFloatVal(self) / dVal;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   924
	    __qMKFLOAT(newFloat, dResult);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   925
	    RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   926
	}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   927
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   928
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   929
    ((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   930
	"
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   931
	 No, you shalt not divide by zero
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   932
	"
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   933
	^ ZeroDivide raiseRequestWith:thisContext.
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   934
    ].
4166
5730ad6b744b oops - from coercion in quotient / uncheckedQuotient
Claus Gittinger <cg@exept.de>
parents: 4100
diff changeset
   935
    ^ aNumber quotientFromShortFloat:self
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   936
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   937
14710
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   938
abs
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   939
    "return the absolute value of the receiver
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   940
     reimplemented here for speed"
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   941
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   942
%{  /* NOCONTEXT */
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   943
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   944
    OBJ newFloat;
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   945
    float val = __shortFloatVal(self);
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   946
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   947
    if (val < 0.0) {
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   948
	__qMKSFLOAT(newFloat, -val);
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   949
	RETURN ( newFloat );
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   950
    }
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   951
    RETURN (self);
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   952
%}.
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   953
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   954
    "
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   955
     3.0 asShortFloat abs
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   956
     -3.0 asShortFloat abs
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   957
    "
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   958
!
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   959
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   960
negated
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   961
    "return myself negated"
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   962
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   963
%{  /* NOCONTEXT */
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   964
    OBJ newFloat;
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   965
    float rslt = - __shortFloatVal(self);
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   966
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   967
    __qMKSFLOAT(newFloat, rslt);
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   968
    RETURN ( newFloat );
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   969
%}.
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   970
    ^ 0.0 - self
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   971
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   972
!
db1edb5f0b67 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14709
diff changeset
   973
14690
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   974
rem: aNumber
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   975
    "return the floating point remainder of the receiver and the argument, aNumber"
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   976
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   977
%{  /* NOCONTEXT */
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   978
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   979
    /*
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   980
     * notice:
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   981
     * the following inline code handles some common cases,
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   982
     * and exists as an optimization, to speed up those cases.
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   983
     *
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   984
     * Conceptionally, (and for most other argument types),
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   985
     * mixed arithmetic is implemented by double dispatching
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   986
     * (see the message send at the bottom)
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   987
     */
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   988
    OBJ newFloat;
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   989
    float result, val;
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   990
    double dResult, dVal;
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   991
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   992
    if (__isSmallInteger(aNumber)) {
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   993
	if (aNumber != __mkSmallInteger(0)) {
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   994
	    val = (float)__intVal(aNumber);
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
   995
computeResult:
14709
9ba9a2c9e132 ouch: fmodf is not avail with borland
Claus Gittinger <cg@exept.de>
parents: 14690
diff changeset
   996
#ifdef NO_FMODF
9ba9a2c9e132 ouch: fmodf is not avail with borland
Claus Gittinger <cg@exept.de>
parents: 14690
diff changeset
   997
	    dResult = fmod((double)__shortFloatVal(self), (double)val) ;
9ba9a2c9e132 ouch: fmodf is not avail with borland
Claus Gittinger <cg@exept.de>
parents: 14690
diff changeset
   998
	    result = (float)dResult;
9ba9a2c9e132 ouch: fmodf is not avail with borland
Claus Gittinger <cg@exept.de>
parents: 14690
diff changeset
   999
#else
14690
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1000
	    result = fmodf(__shortFloatVal(self), val) ;
14709
9ba9a2c9e132 ouch: fmodf is not avail with borland
Claus Gittinger <cg@exept.de>
parents: 14690
diff changeset
  1001
#endif
14690
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1002
	    __qMKSFLOAT(newFloat, result);
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1003
	    RETURN ( newFloat );
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1004
	}
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1005
    } else if (__isFloatLike(aNumber)) {
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1006
	dVal = __floatVal(aNumber);
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1007
	if (dVal != 0.0) {
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1008
	    dResult = fmod((double)(__shortFloatVal(self)), dVal) ;
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1009
	    __qMKFLOAT(newFloat, dResult);
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1010
	    RETURN ( newFloat );
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1011
	}
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1012
    } else if (__isShortFloat(aNumber)) {
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1013
	val = __shortFloatVal(aNumber);
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1014
	if (val != 0.0) {
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1015
	    goto computeResult;
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1016
	}
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1017
    }
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1018
%}.
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1019
    ((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1020
	"
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1021
	 No, you shalt not divide by zero
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1022
	"
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1023
	^ ZeroDivide raiseRequestWith:thisContext.
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1024
    ].
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1025
    ^ aNumber remainderFromShortFloat:self
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1026
!
5934219d333a added rem:
Claus Gittinger <cg@exept.de>
parents: 14673
diff changeset
  1027
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1028
uncheckedDivide:aNumber
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1029
    "return the quotient of the receiver and the argument, aNumber.
7471
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7437
diff changeset
  1030
     Do not check for divide by zero (return NaN or Infinity).
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1031
     This operation is provided for emulators of other languages/semantics,
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1032
     where no exception is raised for these results (i.e. Java).
18841
0578521d1cea #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18139
diff changeset
  1033
     It is only defined if the argument's type is the same as the receiver's."
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1034
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1035
%{  /* NOCONTEXT */
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1036
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1037
    OBJ newFloat;
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1038
    float result, val;
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1039
    double dResult, dVal;
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1040
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1041
    if (__isSmallInteger(aNumber)) {
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1042
	result = __shortFloatVal(self) / (float)(__intVal(aNumber));
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1043
retResult:
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1044
	__qMKSFLOAT(newFloat, result);
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1045
	RETURN ( newFloat );
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1046
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1047
    if (__isShortFloat(aNumber)) {
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1048
	val = __shortFloatVal(aNumber);
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1049
	result = __shortFloatVal(self) / val;
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1050
	goto retResult;
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1051
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1052
    if (__isFloatLike(aNumber)) {
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1053
	dVal = __floatVal(aNumber);
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1054
	dResult = (double) __shortFloatVal(self) / dVal;
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1055
	__qMKFLOAT(newFloat, dResult);
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1056
	RETURN ( newFloat );
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1057
    }
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1058
%}.
4166
5730ad6b744b oops - from coercion in quotient / uncheckedQuotient
Claus Gittinger <cg@exept.de>
parents: 4100
diff changeset
  1059
    ^ aNumber quotientFromShortFloat:self
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1060
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1061
    "
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1062
      0.0 asShortFloat uncheckedDivide:0
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1063
      1.0 asShortFloat uncheckedDivide:0.0
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1064
    "
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1065
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1066
5257
a90fd9cb3c18 category rename
Claus Gittinger <cg@exept.de>
parents: 5120
diff changeset
  1067
!ShortFloat methodsFor:'coercing & converting'!
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1068
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1069
asFloat
11238
f321de80643a comment
Claus Gittinger <cg@exept.de>
parents: 9896
diff changeset
  1070
    "return a Float with same value as the receiver.
f321de80643a comment
Claus Gittinger <cg@exept.de>
parents: 9896
diff changeset
  1071
     Redefined for performance (machine can do it faster)"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1072
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1073
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1074
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1075
    OBJ newFloat;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1076
    double dVal = (double)__shortFloatVal(self);
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1077
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
  1078
    __qMKFLOAT(newFloat, dVal);
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1079
    RETURN ( newFloat );
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1080
%}
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1081
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1082
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1083
     1.0 asShortFloat asFloat
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1084
    "
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1085
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1086
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1087
asInteger
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1088
    "return an integer with same value - might truncate"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1089
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1090
%{  /* NOCONTEXT */
1670
55cde0b3ee8e slightly faster asInteger
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1091
    float fVal;
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1092
1670
55cde0b3ee8e slightly faster asInteger
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1093
    fVal = __shortFloatVal(self);
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19617
diff changeset
  1094
#ifdef __win32__
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1095
    if (! isnanf(fVal))
7419
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
  1096
#endif
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
  1097
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1098
	if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1099
	    RETURN ( __mkSmallInteger( (INT)fVal) );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1100
	}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1101
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1102
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1103
    ^ super asInteger
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1104
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1105
    "
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1106
     12345.0 asShortFloat asInteger
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1107
     1e15 asShortFloat asInteger
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1108
    "
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1109
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1110
7437
834ea4d6cdbc oops - printString of NaN/INF where wrong;
Claus Gittinger <cg@exept.de>
parents: 7419
diff changeset
  1111
asLongFloat
21891
e697cc4bbc7c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21878
diff changeset
  1112
    "return a LongFloat with same value as the receiver"
e697cc4bbc7c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21878
diff changeset
  1113
7437
834ea4d6cdbc oops - printString of NaN/INF where wrong;
Claus Gittinger <cg@exept.de>
parents: 7419
diff changeset
  1114
    ^ LongFloat fromShortFloat:self
21891
e697cc4bbc7c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21878
diff changeset
  1115
e697cc4bbc7c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21878
diff changeset
  1116
    "Modified (comment): / 21-06-2017 / 13:59:41 / cg"
7437
834ea4d6cdbc oops - printString of NaN/INF where wrong;
Claus Gittinger <cg@exept.de>
parents: 7419
diff changeset
  1117
!
834ea4d6cdbc oops - printString of NaN/INF where wrong;
Claus Gittinger <cg@exept.de>
parents: 7419
diff changeset
  1118
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1119
asShortFloat
15022
4db3a134deb9 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 15019
diff changeset
  1120
    "return a ShortFloat with same value as the receiver - that's me"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1121
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1122
    ^ self
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  1123
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  1124
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1125
coerce:aNumber
18841
0578521d1cea #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18139
diff changeset
  1126
    "convert the argument aNumber into an instance of the receiver's class and return it."
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1127
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1128
    ^ aNumber asShortFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1129
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1130
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  1131
generality
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  1132
    "return the generality value - see ArithmeticValue>>retry:coercing:"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  1133
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  1134
    ^ 70
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  1135
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  1136
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1137
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1138
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1139
!ShortFloat methodsFor:'comparing'!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1140
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1141
< aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1142
    "return true, if the argument is greater"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1143
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1144
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1145
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1146
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1147
	RETURN ( (__shortFloatVal(self) < (float)(__intVal(aNumber))) ? true : false );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1148
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1149
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1150
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1151
	    RETURN ( (double)(__shortFloatVal(self) < __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1152
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1153
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1154
	    RETURN ( (__shortFloatVal(self) < __shortFloatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1155
	}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1156
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1157
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1158
    ^ aNumber lessFromShortFloat:self
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1159
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  1160
    "
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  1161
     1.0 asShortFloat > (1/3)
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  1162
    "
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1163
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1164
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1165
<= aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1166
    "return true, if the argument is greater or equal"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1167
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1168
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1169
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1170
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1171
	RETURN ( (__shortFloatVal(self) <= (float)(__intVal(aNumber))) ? true : false );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1172
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1173
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1174
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1175
	    RETURN ( (double)(__shortFloatVal(self) <= __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1176
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1177
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1178
	    RETURN ( (__shortFloatVal(self) <= __shortFloatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1179
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1180
    }
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1181
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1182
    ^ self retry:#<= coercing:aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1183
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1184
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1185
= aNumber
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1186
    "return true, if the argument represents the same numeric value
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1187
     as the receiver, false otherwise"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1188
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1189
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1190
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1191
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1192
	RETURN ( (__shortFloatVal(self) == (float)(__intVal(aNumber))) ? true : false );
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1193
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1194
    if (aNumber == nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1195
	RETURN (false);
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1196
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1197
    if (__qIsFloatLike(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1198
	RETURN ( (double)(__shortFloatVal(self) == __floatVal(aNumber)) ? true : false );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1199
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1200
    if (__qIsShortFloat(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1201
	RETURN ( (__shortFloatVal(self) == __shortFloatVal(aNumber)) ? true : false );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1202
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1203
%}.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1204
    ^ aNumber equalFromShortFloat:self
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1205
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1206
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1207
> aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1208
    "return true, if the argument is less"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1209
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1210
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1211
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1212
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1213
	RETURN ( (__shortFloatVal(self) > (float)(__intVal(aNumber))) ? true : false );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1214
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1215
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1216
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1217
	    RETURN ( (double)(__shortFloatVal(self) > __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1218
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1219
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1220
	    RETURN ( (__shortFloatVal(self) > __shortFloatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1221
	}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1222
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1223
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1224
    ^ self retry:#> coercing:aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1225
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1226
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1227
>= aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1228
    "return true, if the argument is less or equal"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1229
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1230
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1231
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1232
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1233
	RETURN ( (__shortFloatVal(self) >= (float)(__intVal(aNumber))) ? true : false );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1234
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1235
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1236
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1237
	    RETURN ( (double)(__shortFloatVal(self) >= __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1238
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1239
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1240
	    RETURN ( (__shortFloatVal(self) >= __shortFloatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1241
	}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1242
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1243
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1244
    ^ self retry:#>= coercing:aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1245
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1246
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1247
hash
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1248
    "return a number for hashing; redefined, since floats compare
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1249
     by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same
4594
eb09f567a3bc float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents: 4593
diff changeset
  1250
     as 3 hash."
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1251
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1252
    |i|
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1253
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1254
    (self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1255
	i := self asInteger.
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1256
	self = i ifTrue:[
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1257
	    ^ i hash
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1258
	].
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1259
    ].
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1260
4594
eb09f567a3bc float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents: 4593
diff changeset
  1261
    ^ self asFloat hash
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1262
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1263
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1264
     1.2345 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1265
     1.2345 asShortFloat hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1266
     1.0 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1267
     1.0 asShortFloat hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1268
     0.5 asShortFloat hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1269
     0.25 asShortFloat hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1270
     0.5 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1271
     0.25 hash
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1272
    "
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1273
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1274
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1275
isAlmostEqualTo:aNumber nEpsilon:nE
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1276
    "return true, if the argument, aNumber represents almost the same numeric value
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1277
     as the receiver, false otherwise.
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1278
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1279
     nE is the number of minimal float distances, that the numbers may differ and
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1280
     still be considered equal.
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1281
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1282
     For background information why floats need this
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1283
     read: http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1284
    "
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1285
21149
b8ceb5aff633 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20706
diff changeset
  1286
    Epsilon isNil ifTrue:[
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1287
	Epsilon := self class computeEpsilon.
21149
b8ceb5aff633 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20706
diff changeset
  1288
    ].
b8ceb5aff633 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20706
diff changeset
  1289
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1290
%{  /* NOCONTEXT */
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1291
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1292
    /*
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1293
     * notice:
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1294
     * the following inline code handles some common cases,
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1295
     * and exists as an optimization, to speed up those cases.
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1296
     *
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1297
     * Conceptionally, (and for most other argument types),
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1298
     * mixed arithmetic is implemented by double dispatching
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1299
     * (see the message send at the bottom)
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1300
     */
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1301
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1302
    INT32 ulpDiff;
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1303
    union {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1304
	float f;
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1305
	INT32 i;
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1306
    } myself, otherFloat;
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1307
    int nEpsilon;
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1308
    float scaledEpsilon;
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1309
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1310
    if (!__isSmallInteger(nE)) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1311
	goto tryHarder;
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1312
    }
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1313
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1314
    nEpsilon =  __intVal(nE);
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1315
    scaledEpsilon = nEpsilon *__shortFloatVal(@global(Epsilon));
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1316
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1317
    if (__isSmallInteger(aNumber)) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1318
	otherFloat.f = (float)(__intVal(aNumber));
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1319
    } else if (aNumber == nil) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1320
	RETURN(false)
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1321
    } else if (__qIsFloatLike(aNumber)) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1322
	otherFloat.f = (float)(__floatVal(aNumber));
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1323
    } else if (__qIsShortFloat(aNumber)) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1324
	otherFloat.f = __shortFloatVal(aNumber);
22853
a0380f086736 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22788
diff changeset
  1325
//    } else if (__qIsLongFloat(aNumber)) {
a0380f086736 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22788
diff changeset
  1326
//        otherFloat.f = (float)(__longFloatVal(aNumber));
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1327
    } else {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1328
	goto tryHarder;
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1329
    }
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1330
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1331
    myself.f = __shortFloatVal(self);
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1332
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1333
    // Check if the numbers are really close -- needed
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1334
    // when comparing numbers near zero (ULP method below fails for numbers near 0!).
22919
1f77f065b31e fix for borland
Claus Gittinger <cg@exept.de>
parents: 22853
diff changeset
  1335
# ifdef NO_ABSF
22920
ab4f159ef843 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 22919
diff changeset
  1336
    if (fabs((double)(myself.f - otherFloat.f)) <= scaledEpsilon) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1337
	RETURN(true);
22919
1f77f065b31e fix for borland
Claus Gittinger <cg@exept.de>
parents: 22853
diff changeset
  1338
    }
1f77f065b31e fix for borland
Claus Gittinger <cg@exept.de>
parents: 22853
diff changeset
  1339
# else
22853
a0380f086736 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22788
diff changeset
  1340
    // fprintf(stderr, "%.10f %.10f\n", fabsf(myself.f - otherFloat.f), scaledEpsilon);
a0380f086736 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22788
diff changeset
  1341
    if (fabsf(myself.f - otherFloat.f) <= scaledEpsilon) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1342
	RETURN(true);
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1343
    }
22919
1f77f065b31e fix for borland
Claus Gittinger <cg@exept.de>
parents: 22853
diff changeset
  1344
#endif
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1345
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1346
    // if the signs differ, the numbers are different
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1347
    if ((myself.f >= 0) != (otherFloat.f >= 0)) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1348
	RETURN(false);
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1349
    }
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1350
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1351
    // compute the difference of the 'units in the last place" ULP
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1352
    // (if ulpDiff == 1, two floats are adjecant)
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1353
    ulpDiff = myself.i - otherFloat.i;
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1354
    if (ulpDiff < 0) ulpDiff = -ulpDiff;
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1355
    if (ulpDiff <= nEpsilon) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1356
	RETURN(true);
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1357
    } else {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1358
	RETURN(false)
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1359
    }
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1360
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1361
tryHarder:;
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1362
%}.
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1363
    ^ aNumber isAlmostEqualToFromShortFloat:self nEpsilon:nE
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1364
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1365
    "
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1366
	67329.234 asShortFloat isAlmostEqualTo:67329.23401 asShortFloat nEpsilon:1
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1367
	1.0 asShortFloat isAlmostEqualTo:1.0000001 asShortFloat nEpsilon:1
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1368
	1.0 asShortFloat isAlmostEqualTo:1.0000001  nEpsilon:1
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1369
	1.0 asShortFloat isAlmostEqualTo:-1.0 nEpsilon:1
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1370
	1.0 asShortFloat isAlmostEqualTo:1 nEpsilon:1
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1371
	0.0 asShortFloat isAlmostEqualTo:0.0000001 asShortFloat nEpsilon:1
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1372
	0.0 asShortFloat isAlmostEqualTo:0.000001 asShortFloat nEpsilon:1
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1373
	0.0 asShortFloat isAlmostEqualTo:self epsilon nEpsilon:1
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  1374
	0.0 asShortFloat - 1.192093e-07 asShortFloat
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1375
    "
22853
a0380f086736 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22788
diff changeset
  1376
a0380f086736 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22788
diff changeset
  1377
    "Modified: / 10-05-2018 / 00:47:22 / stefan"
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1378
!
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1379
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1380
~= aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1381
    "return true, if the arguments value are not equal"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1382
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1383
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1384
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1385
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1386
	if (__isSmallInteger(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1387
	    RETURN ( (__shortFloatVal(self) != (float)(__intVal(aNumber))) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1388
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1389
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1390
	    RETURN ( (double)(__shortFloatVal(self) !=  __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1391
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1392
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1393
	    RETURN ( (__shortFloatVal(self) !=  __shortFloatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1394
	}
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1395
    } else {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1396
	RETURN ( true );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1397
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1398
%}.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1399
    ^ super ~= aNumber
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1400
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1401
24189
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1402
!ShortFloat methodsFor:'copying'!
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1403
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1404
deepCopy
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1405
    "return a deep copy of myself
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1406
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1407
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1408
    ^ self
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1409
!
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1410
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1411
deepCopyUsing:aDictionary postCopySelector:postCopySelector
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1412
    "return a deep copy of myself
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1413
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1414
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1415
    ^ self
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1416
!
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1417
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1418
shallowCopy
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1419
    "return a shallow copy of the receiver"
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1420
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1421
    ^ self
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1422
!
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1423
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1424
simpleDeepCopy
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1425
    "return a deep copy of the receiver
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1426
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1427
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1428
    ^ self
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1429
! !
51e1451f72fd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24150
diff changeset
  1430
13359
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1431
!ShortFloat methodsFor:'mathematical functions'!
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1432
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1433
fastInverseSqrt
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1434
    "return a rough but fast approximation of (1 / self sqrt).
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1435
     The error is some 1%, which is ok for many 3D computations or physics simulations.
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1436
     Do not use this for now: it is non-portable and probably not speeding things up
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1437
     much, unless inlined into the sender code.
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1438
     The code is here as a reminder and might be later used as a hint for the inliner
13360
1aac241c9981 comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13359
diff changeset
  1439
     (to speed up 3D computations, for example).
1aac241c9981 comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13359
diff changeset
  1440
     see: http://betterexplained.com/articles/understanding-quakes-fast-inverse-square-root/"
13359
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1441
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1442
%{  /* NOCONTEXT */
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1443
    float x, rslt;
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1444
    OBJ newFloat;
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1445
13361
Michael Beyl <mb@exept.de>
parents: 13360
diff changeset
  1446
    if (sizeof(float) == 4) {
14673
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1447
	x = __shortFloatVal(self);
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1448
	{
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1449
	    float xhalf = 0.5f * x;
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1450
	    int i = *(int*)&x; // store floating-point bits in integer
13359
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1451
14673
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1452
	    i = 0x5f3759d5 - (i >> 1); // initial guess for Newton's method
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1453
	    x = *(float*)&i; // convert new bits into float
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1454
	    x = x*(1.5f - xhalf*x*x); // One round of Newton's method
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1455
	    __qMKSFLOAT(newFloat, x);
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1456
	    RETURN ( newFloat );
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1457
	}
13359
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1458
    }
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1459
%}.
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1460
    ^ 1 / self sqrt
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1461
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1462
    "
14673
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1463
     10.0 asShortFloat fastInverseSqrt
13359
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1464
     (1 / 10.0 asShortFloat sqrt)
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1465
    "
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1466
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1467
    "
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1468
     |a b t0 t1 t2|
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1469
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1470
     a := 345 asShortFloat.
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1471
     t0 := Time millisecondsToRun:[
14673
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1472
	1000000 timesRepeat:[
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1473
	]
13359
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1474
     ].
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1475
     t1 := Time millisecondsToRun:[
14673
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1476
	1000000 timesRepeat:[
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1477
	    a fastInverseSqrt
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1478
	]
13359
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1479
     ].
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1480
     t2 := Time millisecondsToRun:[
14673
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1481
	1000000 timesRepeat:[
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1482
	    (1 / a sqrt)
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1483
	]
13359
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1484
     ].
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1485
     Transcript show:'empty: '; showCR:t0.
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1486
     Transcript show:'fast: '; showCR:t1.
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1487
     Transcript show:'regular: '; showCR:t2.
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1488
    "
21829
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1489
!
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1490
21956
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1491
ln
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1492
    "return the natural logarithm of the receiver.
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1493
     Raises an exception, if the receiver is less or equal to zero."
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1494
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1495
%{  /* NOCONTEXT */
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1496
#ifndef __SCHTEAM__
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1497
    float val, rslt;
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1498
    OBJ newFloat;
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1499
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1500
    val = __shortFloatVal(self);
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1501
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1502
    /*
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1503
     * to suppress the warnBox opened by win32
21956
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1504
     * to avoid returning -INF from some unix math libs (__osx__)
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1505
     */
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1506
    if (val > 0.0) {
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1507
	__threadErrno = 0;
21956
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1508
# ifdef NO_LOGF
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1509
	{
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1510
	    double dRslt = log((double)val);
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1511
	    rslt = (float)dRslt;
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1512
	}
21956
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1513
# else
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1514
	rslt = logf(val);
21956
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1515
# endif
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1516
	if (! isnanf(rslt))  /* Currently all our systems support isnan() */
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1517
	{
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1518
	    if (__threadErrno == 0) {
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1519
		__qMKSFLOAT(newFloat, rslt);
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1520
		RETURN ( newFloat );
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1521
	    }
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1522
	}
21956
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1523
    }
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1524
#endif
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1525
%}.
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1526
    "
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1527
     an invalid value for logarithm
21972
846097bcc0c9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21965
diff changeset
  1528
     if you need -INF for a zero receiver, try Number trapInfinity:[...]
21956
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1529
    "
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1530
    ^ self class
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1531
	raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal])
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1532
	receiver:self
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1533
	selector:#ln
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1534
	arguments:#()
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1535
	errorString:'bad receiver in log10 (not strictly positive)'
21956
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1536
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1537
    "
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1538
     0 asFloat ln
21965
ace6435a0903 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21956
diff changeset
  1539
     Number trapInfinity:[ 0 asFloat ln ]
ace6435a0903 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21956
diff changeset
  1540
21956
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1541
     10 asFloat ln       2.30258509299405
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1542
     10 asShortFloat ln  2.302585
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1543
     10 asLongFloat ln   2.302585092994045684
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1544
     10 asQDouble ln     2.30258509299404568402
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1545
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1546
     50 asFloat ln       3.91202300542815
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1547
     50 asShortFloat ln  3.912023
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1548
     50 asLongFloat ln   3.912023005428146059
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1549
     50 asQDouble ln     3.91202300542814605862
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1550
    "
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1551
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1552
    "Created: / 03-07-2017 / 15:20:07 / cg"
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1553
!
7a51828d5c96 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21955
diff changeset
  1554
21829
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1555
log10
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1556
    "return the base-10 logarithm of the receiver.
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1557
     Raises an exception, if the receiver is less or equal to zero."
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1558
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1559
%{  /* NOCONTEXT */
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1560
#ifndef __SCHTEAM__
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1561
    float val, rslt;
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1562
    OBJ newFloat;
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1563
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1564
    val = __shortFloatVal(self);
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1565
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1566
    /*
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1567
     * to suppress the warnBox opened by win32
21955
c6b82cbb4b6a #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21950
diff changeset
  1568
     * to avoid returning -INF from some unix math libs (__osx__)
c6b82cbb4b6a #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21950
diff changeset
  1569
     */
c6b82cbb4b6a #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21950
diff changeset
  1570
    if (val > 0.0) {
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1571
	__threadErrno = 0;
21834
1fe471f18a2e oops - no log10f under win32
Claus Gittinger <cg@exept.de>
parents: 21829
diff changeset
  1572
# ifdef NO_LOG10F
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1573
	{
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1574
	    double dRslt = log10((double)val);
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1575
	    rslt = (float)dRslt;
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1576
	}
21834
1fe471f18a2e oops - no log10f under win32
Claus Gittinger <cg@exept.de>
parents: 21829
diff changeset
  1577
# else
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1578
	rslt = log10f(val);
21834
1fe471f18a2e oops - no log10f under win32
Claus Gittinger <cg@exept.de>
parents: 21829
diff changeset
  1579
# endif
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1580
	if (! isnanf(rslt))  /* Currently all our systems support isnan() */
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1581
	{
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1582
	    if (__threadErrno == 0) {
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1583
		__qMKSFLOAT(newFloat, rslt);
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1584
		RETURN ( newFloat );
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1585
	    }
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1586
	}
21829
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1587
    }
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1588
#endif
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1589
%}.
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1590
    "
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1591
     an invalid value for logarithm
21972
846097bcc0c9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21965
diff changeset
  1592
     if you need -INF for a zero receiver, try Number trapInfinity:[...]
21829
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1593
    "
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1594
    ^ self class
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1595
	raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal])
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1596
	receiver:self
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1597
	selector:#log10
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1598
	arguments:#()
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1599
	errorString:'bad receiver in log10 (not strictly positive)'
21829
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1600
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1601
    "
21976
a57d00890b72 no logf in borland
Claus Gittinger <cg@exept.de>
parents: 21972
diff changeset
  1602
     0 asShortFloat log10
21965
ace6435a0903 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21956
diff changeset
  1603
     Number trapInfinity:[ 0 asShortFloat log10 ]
ace6435a0903 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21956
diff changeset
  1604
21829
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1605
     10 asFloat log10       1.0
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1606
     10 asShortFloat log10  1.0
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1607
     10 asLongFloat log10   1.0
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1608
     10 asQDouble log10     1.00000000000000000000000000000000000000000
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1609
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1610
     50 asFloat log10       1.69897000433602
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1611
     50 asShortFloat log10  1.69897
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1612
     50 asLongFloat log10   1.698970004336018805
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1613
     50 asQDouble log10     1.69897000433601880478626110527550697323181
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1614
    "
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1615
ecd8892d2de5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 21799
diff changeset
  1616
    "Created: / 16-06-2017 / 10:47:53 / cg"
21972
846097bcc0c9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21965
diff changeset
  1617
    "Modified (comment): / 03-07-2017 / 15:59:05 / cg"
13359
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1618
! !
17228556cabd comment/format in: #fastInverseSqrt
Claus Gittinger <cg@exept.de>
parents: 13358
diff changeset
  1619
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1620
!ShortFloat methodsFor:'printing & storing'!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1621
22303
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1622
printOn:aStream
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1623
    "append a printed representation of the receiver to
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1624
     the argument, aStream.
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1625
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1626
     I use #printString instead of #printOn: as basic print mechanism."
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1627
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1628
    aStream nextPutAll:self printString
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1629
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1630
    "Created: / 10-10-2017 / 14:05:28 / cg"
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1631
!
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1632
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1633
printString
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3158
diff changeset
  1634
    "return a printed representation of the receiver
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3158
diff changeset
  1635
     LimitedPrecisonReal and its subclasses use #printString instead of
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3158
diff changeset
  1636
     #printOn: as basic print mechanism."
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1637
18139
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1638
    ^ self printStringWithFormat:DefaultPrintFormat
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1639
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1640
    "
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1641
	1.234 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1642
	1.0 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1643
	1e10 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1644
	1.2e3 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1645
	1.2e30 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1646
	(1.0 uncheckedDivide:0) asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1647
	(0.0 uncheckedDivide:0) asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1648
	self pi printString.
18139
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1649
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1650
	self pi printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1651
	DefaultPrintFormat := '.3'.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1652
	self pi printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1653
	DefaultPrintFormat := '.7'.
18139
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1654
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1655
	DecimalPointCharacterForPrinting := $,.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1656
	1.234 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1657
	1.0 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1658
	1e10 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1659
	1.2e3 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1660
	1.2e30 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1661
	(1.0 uncheckedDivide:0) asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1662
	(0.0 uncheckedDivide:0) asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1663
	DecimalPointCharacterForPrinting := $.
18139
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1664
    "
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1665
!
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1666
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1667
printStringWithFormat:format
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1668
    "return a printed representation of the receiver;
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1669
     fmt must be of the form: .nn, where nn is the number of digits.
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1670
     To print 6 valid digits, use printStringWithFormat:'.6'
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1671
     For Floats, the default used in printString, is 15 (because its a double);
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1672
     for ShortFloats, it is 6 (because it is a float)"
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1673
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1674
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1675
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1676
    char buffer[64];
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1677
    REGISTER char *cp;
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
  1678
    int len;
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1679
    OBJ s;
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1680
    char *fmt;
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1681
    char fmtBuffer[20];
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1682
18139
b001bda4f8f5 class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 18130
diff changeset
  1683
    if (__isStringLike(format)) {
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1684
	fmt = (char *) __stringVal(format);
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1685
    } else {
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1686
	/*
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1687
	 * in case we get called with garbage...
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1688
	 */
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1689
	fmt = ".7";
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1690
    }
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1691
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1692
    /*
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1693
     * build a printf format string
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1694
     */
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1695
    fmtBuffer[0] = '%';
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1696
    strncpy(fmtBuffer+1, fmt, 10);
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1697
    strcat(fmtBuffer, "g");
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1698
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1699
    /*
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1700
     * actually only needed on sparc: since thisContext is
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1701
     * in a global register, which gets destroyed by printf,
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1702
     * manually save it here - very stupid ...
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1703
     */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1704
    __BEGIN_PROTECT_REGISTERS__
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1705
    len = snprintf(buffer, sizeof(buffer), fmtBuffer, (float)__shortFloatVal(self));
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1706
    __END_PROTECT_REGISTERS__
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1707
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
  1708
    if (len >= 0 && len <= sizeof(buffer)-3) {
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1709
	/*
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1710
	 * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1711
	 * (i.e. look if string contains '.' or 'e' and append '.0' if not)
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1712
	 */
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1713
	for (cp = buffer; *cp; cp++) {
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1714
	    if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break;
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1715
	}
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1716
	if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) {
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1717
	    if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1718
		*cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1719
	    } else {
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1720
		*cp++ = '.';
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1721
	    }
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1722
	    *cp++ = '0';
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1723
	    *cp = '\0';
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1724
	} else {
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1725
	    if (cp && (*cp == '.')) {
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1726
		if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1727
		    *cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1728
		}
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1729
	    }
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1730
	}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1731
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1732
	s = __MKSTRING(buffer);
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1733
	if (s != nil) {
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1734
	    RETURN (s);
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1735
	}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1736
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1737
%}.
5432
c71559a881e2 migration support
Claus Gittinger <cg@exept.de>
parents: 5411
diff changeset
  1738
    ^ self asFloat printString
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
  1739
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
  1740
    "
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1741
	1.234 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1742
	ShortFloat pi printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1743
	1.0 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1744
	1e10 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1745
	1.2e3 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1746
	1.2e30 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1747
	(1.0 uncheckedDivide:0) asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1748
	(0.0 uncheckedDivide:0) asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1749
	self pi printString.
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
  1750
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1751
	self pi printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1752
	DefaultPrintFormat := '.3'.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1753
	self pi printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1754
	DefaultPrintFormat := '.7'.
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1755
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1756
	DecimalPointCharacterForPrinting := $,.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1757
	1.234 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1758
	1.0 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1759
	1e10 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1760
	1.2e3 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1761
	1.2e30 asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1762
	(1.0 uncheckedDivide:0) asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1763
	(0.0 uncheckedDivide:0) asShortFloat printString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1764
	DecimalPointCharacterForPrinting := $.
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
  1765
    "
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1766
!
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1767
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1768
printfPrintString:formatString
24693
9587c4518f5d #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24459
diff changeset
  1769
    <unsave>
9587c4518f5d #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24459
diff changeset
  1770
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7725
diff changeset
  1771
    "non-standard: return a printed representation of the receiver
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1772
     as specified by formatString, which is defined by printf.
21950
f5852ca02a75 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21906
diff changeset
  1773
f5852ca02a75 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21906
diff changeset
  1774
     If you use this, be aware, that the format string must be correct and something like %f.
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1775
     Also, the resulting string may not be longer than 255 bytes -
20433
29c784535d3b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20008
diff changeset
  1776
     since that's the (static) size of the buffer.
21906
f070c75710f1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21891
diff changeset
  1777
11924
db93de0d761d changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11730
diff changeset
  1778
     This method is NONSTANDARD and may be removed without notice.
24693
9587c4518f5d #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24459
diff changeset
  1779
9587c4518f5d #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24459
diff changeset
  1780
     WARNING: this goes directly to the C-printf function and may therefore me inherently unsafe.
11924
db93de0d761d changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11730
diff changeset
  1781
     Please use the printf: method, which is safe as it is completely implemented in Smalltalk."
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1782
25016
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1783
%{  /* STACK: 16000 */
24693
9587c4518f5d #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24459
diff changeset
  1784
#ifndef __SCHTEAM__
25016
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1785
    char buffer[1024];
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1786
    OBJ s;
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
  1787
    int len;
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1788
12486
f1ef886832f1 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11945
diff changeset
  1789
    if (__isStringLike(formatString)) {
25016
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1790
        /*
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1791
         * actually only needed on sparc: since thisContext is
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1792
         * in a global register, which gets destroyed by printf,
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1793
         * manually save it here - very stupid ...
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1794
         */
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1795
        __BEGIN_PROTECT_REGISTERS__
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1796
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1797
        len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __shortFloatVal(self));
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1798
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1799
        __END_PROTECT_REGISTERS__
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1800
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1801
        if (len < 0) goto fail;
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1802
        if (len >= sizeof(buffer)) goto fail;
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1803
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1804
        s = __MKSTRING_L(buffer, len);
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1805
        if (s != nil) {
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1806
            RETURN (s);
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  1807
        }
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1808
    }
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
  1809
fail: ;
24693
9587c4518f5d #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24459
diff changeset
  1810
#endif /* not __SCHTEAM__ */
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1811
%}.
21906
f070c75710f1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21891
diff changeset
  1812
    ^ super printfPrintString:formatString
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1813
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1814
    "ShortFloat pi printfPrintString:'%%lg -> %lg'"
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1815
    "ShortFloat pi printfPrintString:'%%lf -> %lf'"
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1816
    "ShortFloat pi printfPrintString:'%%7.5lg -> %7.5lg'"
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1817
    "ShortFloat pi printfPrintString:'%%G -> %G'"
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1818
    "ShortFloat pi printfPrintString:'%%F -> %F'"
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1819
    "ShortFloat pi printfPrintString:'%%7.5G -> %7.5G'"
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1820
    "ShortFloat pi printfPrintString:'%%7.5F -> %7.5F'"
21906
f070c75710f1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21891
diff changeset
  1821
21950
f5852ca02a75 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21906
diff changeset
  1822
    "Modified (comment): / 03-07-2017 / 15:12:20 / cg"
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1823
!
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1824
22303
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1825
storeOn:aStream
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1826
    "append a printed representation of the receiver to
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1827
     the argument, aStream.
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1828
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1829
     I use #storeString instead of #storeOn: as basic store mechanism."
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1830
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1831
    aStream nextPutAll:self storeString
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1832
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1833
    "Created: / 10-10-2017 / 14:06:52 / cg"
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1834
!
a6cd53d4a5fe #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22259
diff changeset
  1835
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1836
storeString
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1837
    "return a printed representation of the receiver;
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1838
     all valid digits are printed.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1839
     LimitedPrecisonReal and its subclasses use #storeString instead of
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1840
     #storeOn: as basic print mechanism."
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1841
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1842
%{  /* NOCONTEXT */
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1843
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1844
    char buffer[64];
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1845
    REGISTER char *cp;
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1846
    OBJ s;
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1847
    int len;
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1848
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1849
    /*
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1850
     * build a printf format string
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1851
     */
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1852
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1853
    __BEGIN_PROTECT_REGISTERS__
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  1854
    len = snprintf(buffer, sizeof(buffer), "%.8g", (float)__shortFloatVal(self));
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1855
    __END_PROTECT_REGISTERS__
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1856
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1857
    if (len >= 0 && len < sizeof(buffer)-3) {
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1858
	/*
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1859
	 * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1860
	 * (i.e. look if string contains '.' or 'e' and append '.0' if not)
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1861
	 */
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1862
	for (cp = buffer; *cp; cp++) {
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1863
	    if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break;
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1864
	}
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1865
	if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) {
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1866
	    *cp++ = '.';
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1867
	    *cp++ = '0';
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1868
	    *cp = '\0';
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1869
	}
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1870
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1871
	s = __MKSTRING(buffer);
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1872
	if (s != nil) {
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1873
	    RETURN (s);
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1874
	}
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1875
    }
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1876
%}.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1877
    "
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1878
     memory allocation (for the new string) failed.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1879
     When we arrive here, there was no memory, even after a garbage collect.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1880
     This means, that the VM wanted to get some more memory from the
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1881
     OS, which was not kind enough to give it.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1882
     Bad luck - you should increase the swap space on your machine.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1883
    "
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20433
diff changeset
  1884
    ^ AllocationFailure raise.
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1885
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1886
    "
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1887
	0.1 asShortFloat storeString
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1888
	((Array new:10 withAll:0.1 asShortFloat) inject:0 into:[:v :sumSoFar| sumSoFar + v]) storeString
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1889
	1.0 asShortFloat storeString
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1890
	1.234 asShortFloat storeString
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1891
	1e10 asShortFloat storeString
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1892
	1.2e3 asShortFloat storeString
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1893
	1.2e30 asShortFloat storeString
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1894
	Float pi asShortFloat storeString
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1895
	(1.0 uncheckedDivide:0) asShortFloat storeString
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1896
	(0.0 uncheckedDivide:0) asShortFloat storeString
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1897
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
  1898
     notice that the storeString is NOT affected by DecimalPointCharacterForPrinting:
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
  1899
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1900
	DecimalPointCharacterForPrinting := $,.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1901
	1.234 asShortFloat storeString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1902
	1.0 asShortFloat storeString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1903
	1e10 asShortFloat storeString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1904
	1.2e3 asShortFloat storeString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1905
	1.2e30 asShortFloat storeString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1906
	(1.0 uncheckedDivide:0) asShortFloat storeString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1907
	(0.0 uncheckedDivide:0) asShortFloat storeString.
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  1908
	DecimalPointCharacterForPrinting := $.
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1909
    "
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1910
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1911
12628
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1912
!ShortFloat methodsFor:'private accessing'!
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1913
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1914
basicAt:index
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1915
    "return an internal byte of the float.
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1916
     The value returned here depends on byte order, float representation etc.
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1917
     Therefore, this method should be used strictly private.
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1918
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1919
     Notice:
14673
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1920
	the need to redefine this method here is due to the
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1921
	inability of many machines to store floats in non-double aligned memory.
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1922
	Therefore, on some machines, the first 4 bytes of a float are left unused,
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1923
	and the actual float is stored at index 5 .. 12.
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1924
	To hide this at one place, this method knows about that, and returns
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1925
	values as if this filler wasnt present."
12628
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1926
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1927
%{  /* NOCONTEXT */
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1928
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1929
    register int indx;
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1930
    unsigned char *cp;
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1931
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1932
    /*
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1933
     * notice the missing test for self being a nonNilObject -
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1934
     * this can be done since basicAt: is defined both in UndefinedObject
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1935
     * and SmallInteger
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1936
     */
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1937
    if (__isSmallInteger(index)) {
14673
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1938
	indx = __intVal(index) - 1;
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1939
	if (((unsigned)(indx)) < sizeof(float)) {
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1940
	    cp = (unsigned char *)(& (__ShortFloatInstPtr(self)->f_floatvalue));
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1941
	    RETURN ( __mkSmallInteger(cp[indx] & 0xFF) );
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1942
	}
12628
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1943
    }
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1944
%}.
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1945
    ^ self indexNotIntegerOrOutOfBounds:index
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1946
!
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1947
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1948
basicAt:index put:value
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1949
    "set an internal byte of the float.
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1950
     The value to be stored here depends on byte order, float representation etc.
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1951
     Therefore, this method should be used strictly private.
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1952
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1953
     Notice:
14673
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1954
	the need to redefine this method here is due to the
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1955
	inability of many machines to store floats in non-double aligned memory.
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1956
	Therefore, on some machines, the first 4 bytes of a float are left unused,
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1957
	and the actual float is stored at index 5 .. 12.
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1958
	To hide this at one place, this method knows about that, and returns
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1959
	values as if this filler wasnt present."
12628
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1960
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1961
%{  /* NOCONTEXT */
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1962
    register int indx, val;
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1963
    unsigned char *cp;
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1964
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1965
    /*
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1966
     * notice the missing test for self being a nonNilObject -
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1967
     * this can be done since basicAt: is defined both in UndefinedObject
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1968
     * and SmallInteger
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1969
     */
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1970
    if (__bothSmallInteger(index, value)) {
14673
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1971
	val = __intVal(value);
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1972
	if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) {
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1973
	    indx = __intVal(index) - 1;
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1974
	    if (((unsigned)(indx)) < sizeof(float)) {
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1975
		cp = (unsigned char *)(& (__ShortFloatInstPtr(self)->f_floatvalue));
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1976
		cp[indx] = val;
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1977
		RETURN ( value );
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1978
	    }
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1979
	}
12628
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1980
    }
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1981
%}.
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1982
    value isInteger ifFalse:[
14673
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1983
	"
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1984
	 the object to store should be an integer number
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1985
	"
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1986
	^ self elementNotInteger
12628
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1987
    ].
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1988
    (value between:0 and:255) ifFalse:[
14673
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1989
	"
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1990
	 the object to store must be a bytes value
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1991
	"
d3c91be01e96 setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents: 14601
diff changeset
  1992
	^ self elementBoundsError:value
12628
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1993
    ].
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1994
    ^ self indexNotIntegerOrOutOfBounds:index
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1995
! !
Claus Gittinger <cg@exept.de>
parents: 12486
diff changeset
  1996
22259
60b47f522c85 #BUGFIX by sr
sr
parents: 21976
diff changeset
  1997
!ShortFloat methodsFor:'private-accessing'!
60b47f522c85 #BUGFIX by sr
sr
parents: 21976
diff changeset
  1998
60b47f522c85 #BUGFIX by sr
sr
parents: 21976
diff changeset
  1999
byteAt:index
60b47f522c85 #BUGFIX by sr
sr
parents: 21976
diff changeset
  2000
    ^ self basicAt:index
60b47f522c85 #BUGFIX by sr
sr
parents: 21976
diff changeset
  2001
!
60b47f522c85 #BUGFIX by sr
sr
parents: 21976
diff changeset
  2002
60b47f522c85 #BUGFIX by sr
sr
parents: 21976
diff changeset
  2003
byteAt:index put:newByte
60b47f522c85 #BUGFIX by sr
sr
parents: 21976
diff changeset
  2004
    self shouldNotImplement
60b47f522c85 #BUGFIX by sr
sr
parents: 21976
diff changeset
  2005
! !
60b47f522c85 #BUGFIX by sr
sr
parents: 21976
diff changeset
  2006
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2007
!ShortFloat methodsFor:'queries'!
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2008
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2009
nextFloat:count
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2010
    "answer the next float count places after (or before if count is negative) myself"
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2011
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2012
%{
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2013
    union u {
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2014
	float d;
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2015
	INT32 i;
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2016
    } this;
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2017
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2018
    if (__isSmallInteger(count)) {
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2019
	this.d = __shortFloatVal(self);
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2020
	if (isfinite(this.d))
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2021
	    this.i += __intVal(count);
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2022
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2023
	RETURN(__MKSFLOAT(this.d));
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2024
    }
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2025
%}.
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2026
    self primitiveFailed:#badArgument
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2027
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2028
  "
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2029
     (1.0 asShortFloat nextFloat:2) storeString
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2030
     (67329.234 asShortFloat nextFloat:1) storeString
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2031
     ShortFloat NaN nextFloat:100000
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2032
     ShortFloat infinity nextFloat:100000
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2033
  "
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2034
! !
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2035
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2036
!ShortFloat methodsFor:'special access'!
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2037
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2038
exponent
24964
0236232a98e1 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24953
diff changeset
  2039
    "extract a normalized float's (unbiased) exponent.
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2040
     The returned value depends on the float-representation of
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2041
     the underlying machine and is therefore highly unportable.
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2042
     This is not for general use.
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2043
     This assumes that the mantissa is normalized to
21850
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2044
     0.5 .. 1.0 and the float's value is mantissa * 2^exp"
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2045
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2046
%{  /* NOCONTEXT */
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2047
    int exp;
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2048
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8706
diff changeset
  2049
#if defined(__i386__) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2050
    frexpf( __shortFloatVal(self), &exp);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2051
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2052
    frexp( (double)(__shortFloatVal(self)), &exp);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2053
#endif
14744
24c92caccacf class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 14741
diff changeset
  2054
    RETURN (__mkSmallInteger(exp));
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2055
%}.
21850
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2056
    ^ super exponent
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2057
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2058
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2059
     4.0 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2060
     2.0 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2061
     1.0 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2062
     0.5 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2063
     0.25 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2064
     0.00000011111 asShortFloat exponent
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2065
    "
21850
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2066
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2067
    "Modified: / 20-06-2017 / 11:33:41 / cg"
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2068
!
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2069
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2070
mantissa
24150
bf24bb4dd79e #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23478
diff changeset
  2071
    "extract a normalized float's mantissa.
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2072
     The returned value depends on the float-representation of
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2073
     the underlying machine and is therefore highly unportable.
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2074
     This is not for general use.
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2075
     This assumes that the mantissa is normalized to
24150
bf24bb4dd79e #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23478
diff changeset
  2076
     0.5 .. 1.0 and the float's value is mantissa * 2^exp"
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2077
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2078
%{  /* NOCONTEXT */
21850
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2079
    float myVal;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2080
    int exp;
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2081
21850
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2082
    myVal = __shortFloatVal(self);
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2083
    // ouch: math libs seem to not care for NaN here;
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2084
#if 1
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2085
    // should we?
21868
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21858
diff changeset
  2086
    if (!isnanf(myVal) && isfinitef(myVal))
21850
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2087
#endif
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2088
    {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8706
diff changeset
  2089
#if defined(__i386__) && defined(__GNUC__)
25016
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  2090
        float frac = frexpf(myVal, &exp);
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  2091
        RETURN (__MKSFLOAT(frac));
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2092
#else
25016
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  2093
        double frac = frexp( (double)(myVal), &exp);
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  2094
        RETURN (__MKFLOAT(frac));
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2095
#endif
21850
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2096
    }
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2097
%}.
20008
21d2247d8dd8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20000
diff changeset
  2098
    ^ super mantissa
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20433
diff changeset
  2099
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2100
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2101
     1.0 asShortFloat exponent
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2102
     1.0 asShortFloat mantissa
21850
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2103
     1e1000 asShortFloat mantissa
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2104
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2105
     0.5 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2106
     0.5 asShortFloat mantissa
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2107
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2108
     0.25 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2109
     0.25 asShortFloat mantissa
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2110
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2111
     0.00000011111 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2112
     0.00000011111 asShortFloat mantissa
25016
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  2113
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  2114
     self assert:(1.0 asShortFloat mantissa * (2 raisedTo:1.0 asShortFloat exponent)) = 1.0 asShortFloat.
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  2115
     self assert:(100.0 asShortFloat mantissa * (2 raisedTo:100.0 asShortFloat exponent)) = 100.0 asShortFloat.
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  2116
     self assert:(10e15 asShortFloat mantissa * (2 raisedTo:10e15 asShortFloat exponent)) = 10e15 asShortFloat.
cbd04064b803 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25003
diff changeset
  2117
     self assert:(10e-15 asShortFloat mantissa * (2 raisedTo:10e-15 asShortFloat exponent)) = 10e-15 asShortFloat.
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2118
    "
21850
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2119
30b47dffc27c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21836
diff changeset
  2120
    "Modified: / 20-06-2017 / 11:41:11 / cg"
24150
bf24bb4dd79e #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23478
diff changeset
  2121
    "Modified: / 26-05-2019 / 03:13:14 / Claus Gittinger"
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2122
! !
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2123
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2124
!ShortFloat methodsFor:'testing'!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2125
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2126
isFinite
24701
594248902e06 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24693
diff changeset
  2127
    "return true, if the receiver is a finite float (not NaN and not +/-INF)"
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2128
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2129
%{  /* NOCONTEXT */
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
  2130
    float fV = __shortFloatVal(self);
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2131
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  2132
    /*
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  2133
     * notice: on machines which do not provide
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2134
     * a isfinite() macro or function (WIN32),
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
  2135
     * this may always ret true here ...
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  2136
     */
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
  2137
    if (isfinitef(fV)) { RETURN (true); }
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2138
%}.
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
  2139
    ^ false
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2140
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2141
    "
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2142
	1.0 asShortFloat isFinite
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2143
	(0.0 asShortFloat uncheckedDivide: 0.0) isFinite
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2144
	(1.0 asShortFloat uncheckedDivide: 0.0) isFinite
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2145
    "
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2146
!
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2147
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  2148
isNaN
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  2149
    "return true, if the receiver is an invalid float (NaN - not a number).
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  2150
     These are not created by ST/X float operations (they raise an exception);
24701
594248902e06 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24693
diff changeset
  2151
     however, inline C-code could produce them."
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  2152
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  2153
%{  /* NOCONTEXT */
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
  2154
    float sV = __shortFloatVal(self);
3139
ca
parents: 3014
diff changeset
  2155
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  2156
    /*
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  2157
     * notice: on machines which do not provide
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2158
     * a isnan() macro or function (WIN32),
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
  2159
     * this may always ret false here ...
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  2160
     */
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
  2161
    if (isnanf(sV)) { RETURN (true); }
2392
cd44ad5cf015 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2391
diff changeset
  2162
%}.
cd44ad5cf015 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2391
diff changeset
  2163
    ^ false
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  2164
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2165
    "
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2166
     1.0 asShortFloat isNaN
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2167
     (0.0 asShortFloat uncheckedDivide: 0.0) isNaN
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2168
     (0.0 asShortFloat uncheckedDivide: 0.0 asShortFloat) isNaN
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2169
    "
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  2170
!
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  2171
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  2172
isNegativeZero
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  2173
    "many systems have two float.Pnt zeros"
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  2174
17396
b587ca0a385f class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17394
diff changeset
  2175
%{ /* NOCONTEXT */
17394
5adc10f7b7a5 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17391
diff changeset
  2176
#if defined(__BORLANDC__)
5adc10f7b7a5 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17391
diff changeset
  2177
    union { float f; int i; } __u;
5adc10f7b7a5 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17391
diff changeset
  2178
   __u.f = __shortFloatVal(self);
5adc10f7b7a5 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17391
diff changeset
  2179
    RETURN ( (__u.f == 0.0 && __u.i < 0) ? true : false );
17391
a3b12aec97ac class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17382
diff changeset
  2180
#else
17382
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2181
    RETURN ( (__shortFloatVal(self) == 0.0 && signbit(__shortFloatVal(self)) != 0) ? true : false );
17391
a3b12aec97ac class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17382
diff changeset
  2182
#endif
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  2183
%}.
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  2184
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  2185
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2186
     0.0 asShortFloat isNegativeZero
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2187
     -0.0 asShortFloat isNegativeZero
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  2188
    "
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  2189
!
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  2190
24947
2b4b6de3a009 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24933
diff changeset
  2191
isShortFloat
2b4b6de3a009 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24933
diff changeset
  2192
    "return true, if the receiver is some kind of short floating point number (iee single precision)"
2b4b6de3a009 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24933
diff changeset
  2193
2b4b6de3a009 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24933
diff changeset
  2194
    ^ true
2b4b6de3a009 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24933
diff changeset
  2195
!
2b4b6de3a009 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24933
diff changeset
  2196
24330
a06e1fba915a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24324
diff changeset
  2197
isZero
a06e1fba915a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24324
diff changeset
  2198
    "return true, if the receiver is zero"
a06e1fba915a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24324
diff changeset
  2199
a06e1fba915a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24324
diff changeset
  2200
    ^ self = 0.0
a06e1fba915a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24324
diff changeset
  2201
a06e1fba915a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24324
diff changeset
  2202
    "Created: / 10-06-2019 / 21:59:09 / Claus Gittinger"
a06e1fba915a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24324
diff changeset
  2203
!
a06e1fba915a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24324
diff changeset
  2204
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2205
negative
17382
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2206
    "return true if the receiver is less than zero.
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2207
     -0.0 is positive for now."
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2208
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2209
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2210
17382
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2211
    RETURN ( __shortFloatVal(self) < 0.0  ? true : false );
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2212
    // RETURN ( signbit(__shortFloatVal(self)) != 0  ? true : false );
5411
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
  2213
%}.
17382
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2214
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2215
    "
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2216
	0.0 asShortFloat negative
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2217
	-0.0 asShortFloat negative
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2218
	1.0 asShortFloat negative
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2219
	-1.0 asShortFloat negative
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2220
	(1.0 uncheckedDivide: 0.0) asShortFloat negative
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2221
	(-1.0 uncheckedDivide: 0.0) asShortFloat negative
17382
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2222
    "
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2223
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2224
5357
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2225
numberOfBits
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2226
    "return the size (in bits) of the real;
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2227
     typically, 32 is returned here,
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2228
     but who knows ..."
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2229
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2230
%{  /* NOCONTEXT */
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2231
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2232
    RETURN (__mkSmallInteger (sizeof(float) * 8));
5357
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2233
%}
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2234
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2235
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2236
     1.2 numberOfBits
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2237
     1.2 asShortFloat numberOfBits
5357
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2238
    "
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2239
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2240
!
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2241
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2242
positive
18852
49601a7aefd8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18841
diff changeset
  2243
    "return true if the receiver is greater or equal to zero (not negative)
17382
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2244
     0.0 and -0.0 are positive for now."
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2245
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2246
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2247
17382
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2248
    RETURN ( __shortFloatVal(self) >= 0.0 ? true : false );
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2249
//    RETURN ( (signbit(__shortFloatVal(self)) == 0 ? true : false ) );
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2250
%}.
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2251
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2252
    "
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2253
	0.0 asShortFloat positive
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2254
	-0.0 asShortFloat positive
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2255
	1.0 asShortFloat positive
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2256
	-1.0 asShortFloat positive
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2257
	(1.0 uncheckedDivide: 0.0) asShortFloat positive
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19325
diff changeset
  2258
	(-1.0 uncheckedDivide: 0.0) asShortFloat positive
17382
1181f2c99686 class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 17220
diff changeset
  2259
    "
1880
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2260
!
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2261
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2262
strictlyPositive
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2263
    "return true if the receiver is greater than zero"
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2264
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2265
%{  /* NOCONTEXT */
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2266
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2267
    RETURN ( (__shortFloatVal(self) > 0.0) ? true : false );
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2268
%}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2269
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2270
5552
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5432
diff changeset
  2271
!ShortFloat methodsFor:'truncation & rounding'!
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2272
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2273
ceiling
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2274
    "return the smallest integer which is greater or equal to the receiver."
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2275
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2276
    |val|
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2277
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2278
%{
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2279
    float fVal;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2280
22788
6a6604fa5b49 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22785
diff changeset
  2281
#if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2282
    fVal = ceilf(__shortFloatVal(self));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2283
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2284
    fVal = (float)(ceil((double)__shortFloatVal(self)));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2285
#endif
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2286
    /*
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2287
     * ST-80 (and X3J20) returns integer.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2288
     */
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2289
    if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2290
	RETURN ( __mkSmallInteger( (INT) fVal ) );
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2291
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2292
    __qMKSFLOAT(val, fVal);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2293
%}.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2294
    ^ val asInteger
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2295
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2296
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2297
     0.5 asShortFloat ceiling
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2298
     -0.5 asShortFloat ceiling
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2299
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2300
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2301
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2302
ceilingAsFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2303
    "return the smallest integer-valued float greater or equal to the receiver.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2304
     This is much like #ceiling, but avoids a (possibly expensive) conversion
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2305
     of the result to an integer.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2306
     It may be useful, if the result is to be further used in another float-operation."
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2307
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2308
%{  /* NOCONTEXT */
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2309
    float fVal;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2310
    OBJ v;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2311
22788
6a6604fa5b49 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22785
diff changeset
  2312
#if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2313
    fVal = ceilf(__shortFloatVal(self));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2314
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2315
    fVal = (float) ceil((double)__shortFloatVal(self));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2316
#endif
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2317
    __qMKSFLOAT(v, fVal);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2318
    RETURN (v);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2319
%}
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2320
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2321
     0.5 asShortFloat ceilingAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2322
     -0.5 asShortFloat ceilingAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2323
     -1.5 asShortFloat ceilingAsFloat
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2324
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2325
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2326
4100
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2327
floor
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2328
    "return the integer nearest the receiver towards negative infinity."
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2329
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2330
    |val|
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2331
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2332
%{
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2333
    float fVal;
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2334
22788
6a6604fa5b49 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22785
diff changeset
  2335
#if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2336
    fVal = floorf(__shortFloatVal(self));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2337
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2338
    fVal = (float)(floor((double)__shortFloatVal(self)));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2339
#endif
4100
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2340
    /*
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2341
     * ST-80 (and X3J20) returns integer.
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2342
     */
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2343
    if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2344
	RETURN ( __mkSmallInteger( (INT) fVal ) );
4100
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2345
    }
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2346
    __qMKSFLOAT(val, fVal);
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2347
%}.
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2348
    ^ val asInteger
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2349
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2350
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2351
     0.5 asShortFloat floor
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2352
     -0.5 asShortFloat floor
4100
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2353
    "
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2354
!
4100
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2355
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2356
floorAsFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2357
    "return the float which represents the next lower
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2358
     integer nearest the receiver towards negative infinity.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2359
     Much like floor, but returns a float result - useful if the result
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2360
     will be used in another float operation, to avoid costy int-conversion."
4100
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2361
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2362
%{  /* NOCONTEXT */
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2363
    float fVal;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2364
    OBJ v;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2365
22788
6a6604fa5b49 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22785
diff changeset
  2366
#if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2367
    fVal = floorf(__shortFloatVal(self));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2368
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2369
    fVal = (float)(floor((double)__shortFloatVal(self)));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2370
#endif
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2371
    __qMKSFLOAT(v, fVal);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2372
    RETURN ( v );
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2373
%}
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2374
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2375
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2376
     0.5 asShortFloat floorAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2377
     -0.5 asShortFloat floorAsFloat
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2378
    "
4100
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2379
!
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  2380
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2381
fractionPart
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2382
    "extract the after-decimal fraction part.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2383
     such that (self truncated + self fractionPart) = self"
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2384
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2385
%{  /* NOCONTEXT */
14727
10825e6940d3 no modff, no fmodf with bcc
Claus Gittinger <cg@exept.de>
parents: 14719
diff changeset
  2386
#ifdef NO_MODFF
10825e6940d3 no modff, no fmodf with bcc
Claus Gittinger <cg@exept.de>
parents: 14719
diff changeset
  2387
    double dFrac, dTrunc;
10825e6940d3 no modff, no fmodf with bcc
Claus Gittinger <cg@exept.de>
parents: 14719
diff changeset
  2388
#else
14741
4a898f7517d5 hack for visualc
Claus Gittinger <cg@exept.de>
parents: 14727
diff changeset
  2389
# ifndef __VISUALC__
14727
10825e6940d3 no modff, no fmodf with bcc
Claus Gittinger <cg@exept.de>
parents: 14719
diff changeset
  2390
    float modff(float, float *);
14741
4a898f7517d5 hack for visualc
Claus Gittinger <cg@exept.de>
parents: 14727
diff changeset
  2391
# endif
14727
10825e6940d3 no modff, no fmodf with bcc
Claus Gittinger <cg@exept.de>
parents: 14719
diff changeset
  2392
#endif
14718
01835f8e7bab class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 14710
diff changeset
  2393
    float frac, trunc;
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2394
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  2395
    __threadErrno = 0;
14727
10825e6940d3 no modff, no fmodf with bcc
Claus Gittinger <cg@exept.de>
parents: 14719
diff changeset
  2396
#ifdef NO_MODFF
10825e6940d3 no modff, no fmodf with bcc
Claus Gittinger <cg@exept.de>
parents: 14719
diff changeset
  2397
	dFrac = modf((double)__shortFloatVal(self), &dTrunc) ;
10825e6940d3 no modff, no fmodf with bcc
Claus Gittinger <cg@exept.de>
parents: 14719
diff changeset
  2398
	frac = (float)dFrac;
10825e6940d3 no modff, no fmodf with bcc
Claus Gittinger <cg@exept.de>
parents: 14719
diff changeset
  2399
#else
14718
01835f8e7bab class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 14710
diff changeset
  2400
    frac = modff(__shortFloatVal(self), &trunc);
14727
10825e6940d3 no modff, no fmodf with bcc
Claus Gittinger <cg@exept.de>
parents: 14719
diff changeset
  2401
#endif
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2402
    if (! isnan(frac)) {
14719
a354c1ef4a56 comment
Claus Gittinger <cg@exept.de>
parents: 14718
diff changeset
  2403
	if (__threadErrno == 0) {
a354c1ef4a56 comment
Claus Gittinger <cg@exept.de>
parents: 14718
diff changeset
  2404
	    RETURN (__MKSFLOAT(frac));
a354c1ef4a56 comment
Claus Gittinger <cg@exept.de>
parents: 14718
diff changeset
  2405
	}
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2406
    }
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2407
%}.
7403
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7392
diff changeset
  2408
    ^ self class
14719
a354c1ef4a56 comment
Claus Gittinger <cg@exept.de>
parents: 14718
diff changeset
  2409
	raise:#domainErrorSignal
a354c1ef4a56 comment
Claus Gittinger <cg@exept.de>
parents: 14718
diff changeset
  2410
	receiver:self
a354c1ef4a56 comment
Claus Gittinger <cg@exept.de>
parents: 14718
diff changeset
  2411
	selector:#fractionPart
a354c1ef4a56 comment
Claus Gittinger <cg@exept.de>
parents: 14718
diff changeset
  2412
	arguments:#()
a354c1ef4a56 comment
Claus Gittinger <cg@exept.de>
parents: 14718
diff changeset
  2413
	errorString:'bad receiver in fractionPart'
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2414
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2415
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2416
     1.6 asShortFloat fractionPart + 1.6 asShortFloat truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2417
     -1.6 asShortFloat fractionPart + -1.6 asShortFloat truncated
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2418
14718
01835f8e7bab class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 14710
diff changeset
  2419
     1.0 asShortFloat fractionPart
01835f8e7bab class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 14710
diff changeset
  2420
     0.5 asShortFloat fractionPart
01835f8e7bab class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 14710
diff changeset
  2421
     0.25 asShortFloat fractionPart
01835f8e7bab class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 14710
diff changeset
  2422
     3.14159 asShortFloat fractionPart
01835f8e7bab class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 14710
diff changeset
  2423
     12345673.14159 asShortFloat fractionPart
01835f8e7bab class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 14710
diff changeset
  2424
     123456731231231231.14159 asShortFloat fractionPart
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2425
    "
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2426
!
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2427
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2428
rounded
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2429
    "return the receiver rounded to the nearest integer"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2430
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2431
    |val|
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2432
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2433
%{
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2434
    float fVal;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2435
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2436
    fVal = __shortFloatVal(self);
22788
6a6604fa5b49 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22785
diff changeset
  2437
#if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2438
    if (fVal < 0.0) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2439
	fVal = ceilf(fVal - (float)0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2440
    } else {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2441
	fVal = floorf(fVal + (float)0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2442
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2443
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2444
    if (fVal < 0.0) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2445
	fVal = (float)ceil((double)fVal - 0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2446
    } else {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2447
	fVal = (float)floor((double)fVal + 0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2448
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2449
#endif
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2450
    /*
22788
6a6604fa5b49 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22785
diff changeset
  2451
     * ST-80 (and X3J20) return integer.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2452
     */
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2453
    if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2454
	RETURN ( __mkSmallInteger( (INT) fVal ) );
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2455
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2456
    __qMKSFLOAT(val, fVal);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2457
%}.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2458
    ^ val asInteger
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2459
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2460
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2461
     0.4 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2462
     0.5 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2463
     0.6 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2464
     -0.4 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2465
     -0.5 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2466
     -0.6 asShortFloat rounded
22788
6a6604fa5b49 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22785
diff changeset
  2467
     1e32 asShortFloat rounded
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2468
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2469
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2470
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2471
roundedAsFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2472
    "return the receiver rounded to the nearest integer as a float.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2473
     This is much like #rounded, but avoids a (possibly expensive) conversion
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2474
     of the result to an integer.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2475
     It may be useful, if the result is to be further used in another float-operation."
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2476
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2477
%{  /* NOCONTEXT */
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2478
    float fVal;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2479
    OBJ v;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2480
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2481
    fVal = __shortFloatVal(self);
22788
6a6604fa5b49 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22785
diff changeset
  2482
#if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2483
    if (fVal < 0.0) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2484
	fVal = ceilf(fVal - (float)0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2485
    } else {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2486
	fVal = floorf(fVal + (float)0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2487
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2488
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2489
    if (fVal < 0.0) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2490
	fVal = (float)ceil((double)fVal - 0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2491
    } else {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2492
	fVal = (float)floor((double)fVal + 0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2493
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2494
#endif
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2495
    __qMKSFLOAT(v, fVal);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2496
    RETURN (v);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2497
%}
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2498
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2499
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2500
     0.4 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2501
     0.5 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2502
     0.6 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2503
     -0.4 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2504
     -0.5 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2505
     -0.6 asShortFloat rounded
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2506
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2507
     0.4 asShortFloat roundedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2508
     0.5 asShortFloat roundedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2509
     0.6 asShortFloat roundedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2510
     -0.4 asShortFloat roundedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2511
     -0.5 asShortFloat roundedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2512
     -0.6 asShortFloat roundedAsFloat
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2513
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2514
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2515
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2516
truncated
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2517
    "return the receiver truncated towards zero as an integer"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2518
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2519
    |val|
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2520
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2521
%{
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2522
    float fVal;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2523
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2524
    fVal = __shortFloatVal(self);
22788
6a6604fa5b49 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22785
diff changeset
  2525
#if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2526
    if (fVal < 0.0) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2527
	fVal = ceilf(fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2528
    } else {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2529
	fVal = floorf(fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2530
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2531
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2532
    if (fVal < 0.0) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2533
	fVal = (float)ceil((double)fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2534
    } else {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2535
	fVal = (float)floor((double)fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2536
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2537
#endif
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2538
    /*
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2539
     * ST-80 (and X3J20) returns integer.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2540
     */
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2541
    if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2542
	RETURN ( __mkSmallInteger( (INT) fVal ) );
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2543
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2544
    __qMKSFLOAT(val, fVal);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2545
%}.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2546
    ^ val asInteger
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2547
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2548
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2549
     0.5 asShortFloat truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2550
     -0.5 asShortFloat truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2551
     0.5 asShortFloat truncatedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2552
     -0.5 asShortFloat truncatedAsFloat
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2553
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2554
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2555
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2556
truncatedAsFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2557
    "return the receiver truncated towards zero as a float.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2558
     This is much like #truncated, but avoids a (possibly expensive) conversion
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2559
     of the result to an integer.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2560
     It may be useful, if the result is to be further used in another
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2561
     float-operation."
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2562
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2563
%{  /* NOCONTEXT */
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2564
    float fVal;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2565
    OBJ v;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2566
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2567
    fVal = __shortFloatVal(self);
22788
6a6604fa5b49 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22785
diff changeset
  2568
#if (defined(__i386__) || defined(xx__x86_64__)) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2569
    if (fVal < 0.0) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2570
	fVal = ceilf(fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2571
    } else {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2572
	fVal = floorf(fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2573
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2574
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2575
    if (fVal < 0.0) {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2576
	fVal = (float)ceil((double)fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2577
    } else {
24976
0b3c34125507 fallback for missing strtof with BORLAND
Claus Gittinger <cg@exept.de>
parents: 24975
diff changeset
  2578
	fVal = (float)floor((double)fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2579
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2580
#endif
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2581
    __qMKSFLOAT(v, fVal);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2582
    RETURN (v);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2583
%}
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2584
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2585
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2586
     0.5 asShortFloat truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2587
     -0.5 asShortFloat truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2588
     0.5 asShortFloat truncatedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  2589
     -0.5 asShortFloat truncatedAsFloat
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2590
    "
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2591
! !
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  2592
1880
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2593
!ShortFloat class methodsFor:'documentation'!
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2594
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2595
version
18841
0578521d1cea #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18139
diff changeset
  2596
    ^ '$Header$'
12486
f1ef886832f1 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11945
diff changeset
  2597
!
f1ef886832f1 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11945
diff changeset
  2598
f1ef886832f1 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11945
diff changeset
  2599
version_CVS
18841
0578521d1cea #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18139
diff changeset
  2600
    ^ '$Header$'
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2601
! !
15012
3361a2f2993e class: ShortFloat
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
  2602
16670
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2603
b81b77ec431d class: ShortFloat
Stefan Vogel <sv@exept.de>
parents: 16633
diff changeset
  2604
ShortFloat initialize!