ShortFloat.st
author Stefan Vogel <sv@exept.de>
Tue, 13 Oct 2009 11:55:18 +0200
changeset 12252 93c323c8a166
parent 11945 8697e2333da3
child 12486 f1ef886832f1
permissions -rw-r--r--
changed: #autoload #initialize Autoload autoload - so not reload Autoload
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
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
LimitedPrecisionReal variableByteSubclass:#ShortFloat
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:''
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    16
	classVariableNames:''
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Magnitude-Numbers'
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
2394
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    21
!ShortFloat primitiveDefinitions!
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    22
%{
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    23
3471
91bad1642e2f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
    24
#include <errno.h>
91bad1642e2f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
    25
91bad1642e2f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
    26
#ifndef __OPTIMIZE__
91bad1642e2f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
    27
# define __OPTIMIZE__
91bad1642e2f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
    28
#endif
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
    29
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
    30
#define __USE_ISOC9X 1
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
    31
#define __USE_ISOC99 1
3471
91bad1642e2f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
    32
#include <math.h>
91bad1642e2f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
    33
91bad1642e2f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
    34
/*
91bad1642e2f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
    35
 * on some systems errno is a macro ... check for it here
91bad1642e2f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
    36
 */
91bad1642e2f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
    37
#ifndef errno
91bad1642e2f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
    38
 extern errno;
91bad1642e2f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
    39
#endif
91bad1642e2f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3470
diff changeset
    40
2394
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    41
#if defined (_AIX)
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    42
# include <float.h>
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    43
#endif
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
    44
2395
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
    45
#if defined(IRIX)
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
    46
# include <nan.h>
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
    47
#endif
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
    48
2397
dd6979979e67 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2395
diff changeset
    49
#if defined(LINUX)
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
    50
# ifndef NAN
5822
4e56f8aadda5 Get nan.h from bits/nan.h for Linux
Stefan Vogel <sv@exept.de>
parents: 5718
diff changeset
    51
#  include <bits/nan.h>
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
    52
# endif
2397
dd6979979e67 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2395
diff changeset
    53
#endif
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4637
diff changeset
    54
2400
01b61753386f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2398
diff changeset
    55
#if defined(solaris) || defined(sunos)
2398
652c9f2a13fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2397
diff changeset
    56
# include <nan.h>
652c9f2a13fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2397
diff changeset
    57
#endif
2394
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    58
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
    59
#ifdef WIN32
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
    60
/*
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
    61
 * no finite(x) ?
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
    62
 * no isnan(x) ?
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
    63
 */
7419
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    64
# ifndef isnan
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    65
#  define isnan(x)      \
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
    66
	((((unsigned int *)(&x))[0] == 0x00000000) && \
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
    67
	 (((unsigned int *)(&x))[1] == 0xFFF80000))
7419
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    68
# endif
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    69
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    70
# ifndef isPositiveInfinity
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    71
#  define isPositiveInfinity(x) \
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
    72
	((((unsigned int *)(&x))[0] == 0x00000000) && \
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
    73
	 (((unsigned int *)(&x))[1] == 0x7FF00000))
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
    74
# endif
7419
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    75
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    76
# ifndef isNegativeInfinity
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    77
#  define isPositiveInfinity(x) \
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
    78
	((((unsigned int *)(&x))[0] == 0x00000000) && \
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
    79
	 (((unsigned int *)(&x))[1] == 0xFFF00000))
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
    80
# endif
7419
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    81
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    82
# ifndef isinf
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    83
#  define isinf(x) \
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
    84
	((((unsigned int *)(&x))[0] == 0x00000000) && \
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
    85
	 ((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000))
7419
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    86
# endif
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    87
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
    88
# ifndef isfinite
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
    89
#  define isfinite(x) (!isinf(x) && !isnan(x))
7419
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    90
# endif
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
    91
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
    92
# ifndef isnanf
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
    93
#  define isnanf(x)      \
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
    94
	(((unsigned int *)(&x))[0] == 0xFFC00000)
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
    95
# endif
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
    96
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
    97
# ifndef isPositiveInfinityf
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
    98
#  define isPositiveInfinityf(x)      \
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
    99
	(((unsigned int *)(&x))[0] == 0x7F800000)
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   100
# endif
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   101
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   102
# ifndef isNegativeInfinityf
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   103
#  define isNegativeInfinityf(x)      \
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   104
	(((unsigned int *)(&x))[0] == 0xFF800000)
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   105
# endif
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   106
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   107
# ifndef isinff
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   108
#  define isinff(x)      \
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   109
	((((unsigned int *)(&x))[0] & 0x7FFFFFFF) == 0x7F800000)
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   110
# endif
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   111
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   112
# ifndef isfinitef
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   113
#  define isfinitef(x) (!isinff(x) && !isnanf(x))
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   114
# endif
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   115
7419
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
   116
# define NO_ASINH
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
   117
# define NO_ACOSH
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
   118
# define NO_ATANH
8706
d48896f0a910 mac stuff
Claus Gittinger <cg@exept.de>
parents: 8635
diff changeset
   119
#endif /* WIN32 */
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   120
8984
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   121
#ifdef solaris
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   122
# ifndef isfinite
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   123
#  define isfinite(f) finite((double)(f))
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   124
# endif
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   125
#endif
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   126
3414
d9aefd18c10d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   127
#ifdef realIX
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
   128
# ifndef isfinite
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
   129
#  define isfinite(x)     1
3414
d9aefd18c10d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   130
# endif
8706
d48896f0a910 mac stuff
Claus Gittinger <cg@exept.de>
parents: 8635
diff changeset
   131
#endif /* realIX */
d48896f0a910 mac stuff
Claus Gittinger <cg@exept.de>
parents: 8635
diff changeset
   132
9896
307c7296064e Fix syntax warning in #ifdef
Stefan Vogel <sv@exept.de>
parents: 9636
diff changeset
   133
#ifndef isfinitef
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   134
# define isfinitef(x) isfinite(x)
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   135
#endif
9896
307c7296064e Fix syntax warning in #ifdef
Stefan Vogel <sv@exept.de>
parents: 9636
diff changeset
   136
#ifndef isnanf
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   137
# define isnanf(x) isnan(x)
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   138
#endif
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   139
2394
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
   140
%}
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
   141
! !
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
   142
1880
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   143
!ShortFloat class methodsFor:'documentation'!
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
copyright
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
 COPYRIGHT (c) 1996 by Claus Gittinger
3158
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   148
	      All Rights Reserved
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
 This software is furnished under a license and may be used
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
 only in accordance with the terms of that license and with the
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
 inclusion of the above copyright notice.   This software may not
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
 be provided or otherwise made available to, or used by, any
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
 other person.  No title to or ownership of the software is
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
 hereby transferred.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
documentation
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
"
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   163
    ShortFloats represent rational numbers with limited precision.
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   164
    They use the C-compilers 'float' format, which is usually the IEE single float format.
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   165
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   166
    In contrast to Floats (which use the C-compilers 64bit 'double' format),
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   167
    ShortFloats give you 32 bit floats.
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
    Notice, that ST/X Floats are what Doubles are in ST-80 and ShortFloats are
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
    ST-80's Floats respectively.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   171
    This may change in one of the next versions (at least on machines, which
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
    provide different float and double types in their C-compiler.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
    WARNING:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   175
	The layout of shortFloat instances is known by the runtime system and the compiler;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   176
	you may not add instance variables here.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   177
	Also, subclassing is complicated by the fact, that the VM creates floats/shortFloats,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   178
	and does some of its float-checks by an identity compare with the ShortFloat-class.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   179
	(i.e. your subclasses instances may not be recognized as float-like objects,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   180
	 thus mixed mode arithmetic will always coerce them, effectively slowing things down).
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   181
	This may be changed, to use a flag bit in the class.
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   183
    Mixed mode arithmetic:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   184
	shortFloat op shortFloat   -> shortFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   185
	shortFloat op fix         -> shortFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   186
	shortFloat op fraction    -> shortFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   187
	shortFloat op integer     -> shortFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   188
	shortFloat op longFloat   -> longFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   189
	shortFloat op float       -> float
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   190
	shortFloat op complex     -> complex
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   191
7405
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
   192
    Representation:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   193
	    32bit single precision IEE floats
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   194
	    23 bit mantissa,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   195
	    8 bit exponent,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   196
	    6 decimal digits (approx)
7405
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
   197
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
   198
    Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
   199
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   200
    [author:]
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   201
	Claus Gittinger
1556
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   202
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   203
    [see also:]
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   204
	Number
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   205
	Float LongFloat Fraction FixedPoint Integer Complex
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   206
	FloatArray DoubleArray
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
1880
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   210
!ShortFloat class methodsFor:'instance creation'!
1207
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   211
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   212
basicNew
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   213
    "return a new shortFloat - here we return 0.0
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   214
     - shortFloats are usually NOT created this way ...
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   215
     Its implemented here to allow things like binary store & load
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   216
     of shortFloats. (but even this support will go away eventually, its not
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   217
     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
   218
     totally different representation - so floats will eventually be
1207
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   219
     binary stored in a device independent format."
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   220
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   221
%{  /* NOCONTEXT */
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   222
    OBJ newFloat;
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   223
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   224
    __qMKSFLOAT(newFloat, 0.0);
1207
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   225
    RETURN (newFloat);
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   226
%}
3158
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   227
!
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   228
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   229
fastFromString:aString at:startIndex
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   230
    "return the next ShortFloat from the string starting at startIndex.
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   231
     No spaces are skipped.
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   232
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   233
     This is a specially tuned entry (using a low-level C-call), which
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   234
     returns garbage if the argument string is not a valid float number.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   235
     It has been added to allow higher speed string decomposition into numbers,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   236
     especially for mass-data."
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   237
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   238
%{   /* NOCONTEXT */
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   239
     if (__isString(aString) && __isSmallInteger(startIndex)) {
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
   240
	char *cp = (char *)(__stringVal(aString));
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
   241
	int idx = __intVal(startIndex) - 1;
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
   242
	double atof();
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
   243
	double val;
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   244
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
   245
	if ((unsigned)idx < __stringSize(aString)) {
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
   246
	    val = atof(cp + idx);
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
   247
	    RETURN (__MKSFLOAT(val));
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
   248
	}
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   249
     }
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   250
%}.
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   251
     self primitiveFailed.
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   252
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   253
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   254
     ShortFloat fastFromString:'123.45' at:1
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   255
     ShortFloat fastFromString:'123.45' at:2
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   256
     ShortFloat fastFromString:'123.45E4' at:1
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   257
     ShortFloat fastFromString:'hello123.45E4' at:6
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   258
     ShortFloat fastFromString:'12345' at:1
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   259
     ShortFloat fastFromString:'12345' at:2
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   260
     ShortFloat fastFromString:'12345' at:3
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   261
     ShortFloat fastFromString:'12345' at:4
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   262
     ShortFloat fastFromString:'12345' at:5
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   263
     ShortFloat fastFromString:'12345' at:6
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   264
     ShortFloat fastFromString:'12345' at:0
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   265
     ShortFloat fastFromString:'hello123.45E4' at:1
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   266
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   267
     Time millisecondsToRun:[
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
   268
	100000 timesRepeat:[
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
   269
	    ShortFloat readFrom:'123.45'
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
   270
	]
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   271
     ]
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   272
    "
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   273
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   274
    "
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   275
     Time millisecondsToRun:[
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
   276
	100000 timesRepeat:[
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   277
	    ShortFloat fastFromString:'123.45' at:1
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
   278
	]
4297
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   279
     ]
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   280
    "
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   281
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   282
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   283
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   284
!
302e80e0b14a added #fastFromString:
Claus Gittinger <cg@exept.de>
parents: 4166
diff changeset
   285
4637
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   286
readFrom:aStringOrStream
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   287
    "read a shortFloat from a string"
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   288
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   289
    |num|
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   290
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   291
    num := super readFrom:aStringOrStream onError:[self error:'conversion error for: ' , self name].
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   292
    num notNil ifTrue:[
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
   293
	num := num asShortFloat
4637
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   294
    ].
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   295
    ^ num
4637
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   296
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   297
    "
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   298
     ShortFloat readFrom:'0.1'
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   299
     ShortFloat readFrom:'0'
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   300
     ShortFloat readFrom:'.123'
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   301
     ShortFloat readFrom:'-.123'
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   302
     ShortFloat readFrom:'1e4'
4637
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   303
    "
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   304
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   305
    "Modified: / 7.1.1998 / 16:17:59 / cg"
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   306
!
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   307
3158
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   308
readFrom:aStringOrStream onError:exceptionBlock
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   309
    "read a shortFloat from a string"
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   310
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   311
    |num|
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   312
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   313
    num := super readFrom:aStringOrStream onError:nil.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   314
    num isNil ifTrue:[
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
   315
	^ exceptionBlock value
3158
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   316
    ].
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   317
    ^ num asShortFloat
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   318
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   319
    "
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   320
     ShortFloat readFrom:'0.1'
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   321
     ShortFloat readFrom:'0'
4637
814b3d8e3f72 allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   322
     ShortFloat readFrom:'.123'
3158
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   323
    "
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   324
8e6bec40f6b0 added #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3147
diff changeset
   325
    "Modified: / 7.1.1998 / 16:17:59 / cg"
1207
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   326
! !
8c3d75503dd2 need basicNew
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   327
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   328
!ShortFloat class methodsFor:'binary storage'!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   329
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   330
readBinaryIEEESingleFrom:aStream
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   331
    "read a float value from the binary stream, aStream,
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   332
     interpreting the next bytes as an IEEE formatted 4-byte float"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   334
    |f|
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   336
    f := ShortFloat basicNew.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   337
    self readBinaryIEEESingleFrom:aStream into:f.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   338
    ^ f
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
9636
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   340
    "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
   341
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   342
    "Created: / 16-04-1996 / 21:00:35 / cg"
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   343
    "Modified: / 23-08-2006 / 16:01:47 / cg"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   346
readBinaryIEEESingleFrom:aStream into:aFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   347
    "read a float value from the binary stream, aStream,
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   348
     interpreting the next bytes as an IEEE formatted 4-byte float"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   349
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   350
    aFloat class == self ifFalse:[self error:'no a ShortFloat'].
6574
788f5a36dcb1 Define #precision, #radix
Stefan Vogel <sv@exept.de>
parents: 6063
diff changeset
   351
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   352
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   353
     this implementation is wrong: does not work on non-IEEE machines
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   354
     (to date all machines where ST/X is running on use
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   355
      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
   356
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   357
    self isIEEEFormat ifFalse:[self error:'unsupported operation'].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   358
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   359
    UninterpretedBytes isBigEndian ifFalse:[
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   360
	"swap the bytes"
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   361
	8 to:4 by:-1 do:[:i |
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   362
	    aFloat basicAt:i put:(aStream next)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   363
	].
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   364
	^ self
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   365
    ].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   366
    1 to:4 do:[:i |
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   367
	aFloat basicAt:i put:aStream next
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   368
    ]
9636
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   369
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   370
    "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
   371
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   372
    "Modified: / 23-08-2006 / 16:01:52 / cg"
6574
788f5a36dcb1 Define #precision, #radix
Stefan Vogel <sv@exept.de>
parents: 6063
diff changeset
   373
!
788f5a36dcb1 Define #precision, #radix
Stefan Vogel <sv@exept.de>
parents: 6063
diff changeset
   374
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   375
storeBinaryIEEESingle:aFloat on:aStream
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   376
    "store aFloat as an IEEE formatted 4-byte float
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   377
     onto the binary stream, aStream"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   378
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   379
    |float|
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   380
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   381
    float := aFloat asShortFloat.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   382
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   383
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   384
     this implementation is wrong: does not work on non-IEEE machines
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   385
     (to date all machines where ST/X is running on use
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   386
      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
   387
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   388
    self isIEEEFormat ifFalse:[self error:'unsupported operation'].
6574
788f5a36dcb1 Define #precision, #radix
Stefan Vogel <sv@exept.de>
parents: 6063
diff changeset
   389
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   390
    UninterpretedBytes isBigEndian ifFalse:[
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   391
	"swap the bytes"
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   392
	8 to:4 by:-1 do:[:i |
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   393
	    aStream nextPut:(float basicAt:i).
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   394
	].
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   395
	^ self
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   396
    ].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   397
    1 to:4 do:[:i |
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   398
	aStream nextPut:(float basicAt:i).
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   399
    ]
9636
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   400
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   401
    "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
   402
c6b63e749626 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9149
diff changeset
   403
    "Modified: / 23-08-2006 / 16:01:55 / cg"
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   404
! !
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   405
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   406
!ShortFloat class methodsFor:'constants'!
6574
788f5a36dcb1 Define #precision, #radix
Stefan Vogel <sv@exept.de>
parents: 6063
diff changeset
   407
7392
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   408
e
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   409
    "return the constant e as ShortFloat"
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   410
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   411
    ^ Float e asShortFloat
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   412
!
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   413
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   414
pi
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   415
    "return the constant pi as ShortFloat"
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   416
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   417
    ^ Float pi asShortFloat
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   418
!
8084c9ca941d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7387
diff changeset
   419
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   420
unity
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1207
diff changeset
   421
    "return the neutral element for multiplication (1.0) as ShortFloat"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
    ^ 1.0 asShortFloat
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1207
diff changeset
   425
    "Modified: 23.4.1996 / 09:26:51 / cg"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
zero
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1207
diff changeset
   429
    "return the neutral element for addition (0.0) as ShortFloat"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
    ^ 0.0 asShortFloat
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1207
diff changeset
   433
    "Modified: 23.4.1996 / 09:26:45 / cg"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
1880
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   436
!ShortFloat class methodsFor:'queries'!
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
6898
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   438
exponentCharacter
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   439
    ^ $e
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   440
!
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   441
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   443
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   444
     Here, true is returned for myself, false for subclasses."
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
    ^ self == ShortFloat
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   448
    "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
   449
!
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   450
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   451
isIEEEFormat
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   452
    "return true, if this machine represents floats in IEEE format.
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   453
     Currently, no support is provided for non-ieee machines
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   454
     to convert their floats into this (which is only relevant,
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   455
     if such a machine wants to send floats as binary to some other
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   456
     machine).
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   457
     Machines with non-IEEE format are VAXed and IBM370-type systems
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   458
     (among others). Today, most systems use IEEE format floats."
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   459
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   460
    ^ true "/ this may be a lie
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   461
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   462
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   463
numBitsInExponent
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   464
    "answer the number of bits in the exponent
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   465
     This is an IEEE float, where 8 bits are available:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   466
	seeeeeee emmmmmmm mmmmmmmm mmmmmmmm
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
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   469
    ^ 8
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   470
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   471
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   472
numBitsInMantissa
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   473
    "answer the number of bits in the mantissa.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   474
     This is an IEEE float, where 23 bits (the hidden one is not counted here) are available:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   475
	seeeeeee emmmmmmm mmmmmmmm mmmmmmmm
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   476
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   477
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   478
    ^ 23
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   479
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   480
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   481
precision
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   482
    "answer the precision of a ShortFloat (in bits)
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   483
     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
   484
     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
   485
     (although only 23 are needed in the binary representation)"
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   486
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   487
    ^  24
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   488
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   489
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   490
radix
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   491
    "answer the radix of a ShortFloats exponent
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   492
     This is an IEEE float, which is represented as binary"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   493
9149
3fb15c4d83d8 comment
Claus Gittinger <cg@exept.de>
parents: 9121
diff changeset
   494
    ^ 2 "must be careful here, whenever ST/X is used on a VAX or a 370"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
!ShortFloat methodsFor:'arithmetic'!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
* aNumber
11730
eabe6364c89b comment
Claus Gittinger <cg@exept.de>
parents: 11720
diff changeset
   500
    "return the product of the receiver and the argument."
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
    OBJ newFloat;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
    float result;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
    double dResult;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   509
	result = __shortFloatVal(self) * (float)(__intVal(aNumber));
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
retResult:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   511
	__qMKSFLOAT(newFloat, result);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   512
	RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   513
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   514
    if (__isShortFloat(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   515
	result = __shortFloatVal(self) * __shortFloatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   516
	goto retResult;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   517
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   518
    if (__isFloatLike(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   519
	dResult = (double) __shortFloatVal(self)* __floatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   520
	__qMKFLOAT(newFloat, dResult);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   521
	RETURN ( newFloat );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   524
    ^ aNumber productFromShortFloat:self
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
+ aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
    "return the sum of the receiver and the argument, aNumber"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
    OBJ newFloat;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   533
    float result;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   534
    double dResult;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   535
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   537
	result = __shortFloatVal(self) + (float)(__intVal(aNumber));
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
retResult:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   539
	__qMKSFLOAT(newFloat, result);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   540
	RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   541
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   542
    if (__isShortFloat(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   543
	result = __shortFloatVal(self) + __shortFloatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   544
	goto retResult;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   545
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   546
    if (__isFloatLike(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   547
	dResult = (double) __shortFloatVal(self) + __floatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   548
	__qMKFLOAT(newFloat, dResult);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   549
	RETURN ( newFloat );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   550
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   551
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   552
    ^ aNumber sumFromShortFloat:self
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   553
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   554
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   555
- aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   556
    "return the difference of the receiver and the argument, aNumber"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   558
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   559
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   560
    OBJ newFloat;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   561
    float result;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   562
    double dResult;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   563
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   564
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   565
	result = __shortFloatVal(self) - (float)(__intVal(aNumber));
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   566
retResult:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   567
	__qMKSFLOAT(newFloat, result);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   568
	RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   569
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   570
    if (__isShortFloat(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   571
	result = __shortFloatVal(self) - __shortFloatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   572
	goto retResult;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   573
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   574
    if (__isFloatLike(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   575
	dResult = (double) __shortFloatVal(self) - __floatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   576
	__qMKFLOAT(newFloat, dResult);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   577
	RETURN ( newFloat );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   578
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   579
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   580
    ^ aNumber differenceFromShortFloat:self
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   581
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   582
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   583
/ aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   584
    "return the quotient of the receiver and the argument, aNumber"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   585
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   586
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   587
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   588
    OBJ newFloat;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   589
    float result, val;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   590
    double dResult, dVal;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   591
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   592
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   593
	if (aNumber != __mkSmallInteger(0)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   594
	    result = __shortFloatVal(self) / (float)(__intVal(aNumber));
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   595
retResult:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   596
	    __qMKSFLOAT(newFloat, result);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   597
	    RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   598
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   599
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   600
    if (__isShortFloat(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   601
	val = __shortFloatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   602
	if (val != 0.0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   603
	    result = __shortFloatVal(self) / val;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   604
	    goto retResult;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   605
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   606
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   607
    if (__isFloatLike(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   608
	dVal = __floatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   609
	if (dVal != 0.0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   610
	    dResult = (double) __shortFloatVal(self) / dVal;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   611
	    __qMKFLOAT(newFloat, dResult);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   612
	    RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   613
	}
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
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   616
    ((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   617
	"
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   618
	 No, you shalt not divide by zero
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   619
	"
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   620
	^ ZeroDivide raiseRequestWith:thisContext.
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   621
    ].
4166
5730ad6b744b oops - from coercion in quotient / uncheckedQuotient
Claus Gittinger <cg@exept.de>
parents: 4100
diff changeset
   622
    ^ aNumber quotientFromShortFloat:self
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   624
7725
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   625
abs
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   626
    "return the absolute value of the receiver
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   627
     reimplemented here for speed"
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   628
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   629
%{  /* NOCONTEXT */
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   630
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   631
    OBJ newFloat;
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   632
    float val = __shortFloatVal(self);
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   633
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   634
    if (val < 0.0) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   635
	__qMKSFLOAT(newFloat, -val);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   636
	RETURN ( newFloat );
7725
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   637
    }
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   638
    RETURN (self);
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   639
%}.
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   640
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   641
    "
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   642
     3.0 asShortFloat abs
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   643
     -3.0 asShortFloat abs
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   644
    "
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   645
!
c3c9115bb492 Define #abs
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   646
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   647
negated
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   648
    "return myself negated"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   650
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   651
    OBJ newFloat;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   652
    float rslt = - __shortFloatVal(self);
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   653
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   654
    __qMKSFLOAT(newFloat, rslt);
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   655
    RETURN ( newFloat );
5411
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   656
%}.
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   657
    ^ 0.0 - self
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   658
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   659
!
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   660
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   661
uncheckedDivide:aNumber
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   662
    "return the quotient of the receiver and the argument, aNumber.
7471
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7437
diff changeset
   663
     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
   664
     This operation is provided for emulators of other languages/semantics,
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   665
     where no exception is raised for these results (i.e. Java).
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   666
     Its only defined if the arguments type is the same as the receivers."
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   667
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   668
%{  /* NOCONTEXT */
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   669
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   670
    OBJ newFloat;
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   671
    float result, val;
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   672
    double dResult, dVal;
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   673
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   674
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   675
	result = __shortFloatVal(self) / (float)(__intVal(aNumber));
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   676
retResult:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   677
	__qMKSFLOAT(newFloat, result);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   678
	RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   679
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   680
    if (__isShortFloat(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   681
	val = __shortFloatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   682
	result = __shortFloatVal(self) / val;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   683
	goto retResult;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   684
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   685
    if (__isFloatLike(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   686
	dVal = __floatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   687
	dResult = (double) __shortFloatVal(self) / dVal;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   688
	__qMKFLOAT(newFloat, dResult);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   689
	RETURN ( newFloat );
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   690
    }
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   691
%}.
4166
5730ad6b744b oops - from coercion in quotient / uncheckedQuotient
Claus Gittinger <cg@exept.de>
parents: 4100
diff changeset
   692
    ^ aNumber quotientFromShortFloat:self
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   693
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   694
    "
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   695
      0.0 asShortFloat uncheckedDivide:0
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   696
      1.0 asShortFloat uncheckedDivide:0.0
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   697
    "
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   698
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   699
5257
a90fd9cb3c18 category rename
Claus Gittinger <cg@exept.de>
parents: 5120
diff changeset
   700
!ShortFloat methodsFor:'coercing & converting'!
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   701
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   702
asFloat
11238
f321de80643a comment
Claus Gittinger <cg@exept.de>
parents: 9896
diff changeset
   703
    "return a Float with same value as the receiver.
f321de80643a comment
Claus Gittinger <cg@exept.de>
parents: 9896
diff changeset
   704
     Redefined for performance (machine can do it faster)"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   705
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   706
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   707
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   708
    OBJ newFloat;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   709
    double dVal = (double)__shortFloatVal(self);
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   710
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   711
    __qMKFLOAT(newFloat, dVal);
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   712
    RETURN ( newFloat );
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   713
%}
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   714
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   715
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   716
     1.0 asShortFloat asFloat
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   717
    "
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   718
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   719
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   720
asInteger
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   721
    "return an integer with same value - might truncate"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   722
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   723
%{  /* NOCONTEXT */
1670
55cde0b3ee8e slightly faster asInteger
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
   724
    float fVal;
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   725
1670
55cde0b3ee8e slightly faster asInteger
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
   726
    fVal = __shortFloatVal(self);
7419
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
   727
#ifdef WIN32
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   728
    if (! isnanf(fVal))
7419
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
   729
#endif
44b2f66791f1 isnanf for Win32
Claus Gittinger <cg@exept.de>
parents: 7408
diff changeset
   730
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   731
	if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   732
	    RETURN ( __mkSmallInteger( (INT)fVal) );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   733
	}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   734
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   735
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   736
    ^ super asInteger
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   737
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
    "
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   739
     12345.0 asShortFloat asInteger
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   740
     1e15 asShortFloat asInteger
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   741
    "
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   742
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   743
7437
834ea4d6cdbc oops - printString of NaN/INF where wrong;
Claus Gittinger <cg@exept.de>
parents: 7419
diff changeset
   744
asLongFloat
834ea4d6cdbc oops - printString of NaN/INF where wrong;
Claus Gittinger <cg@exept.de>
parents: 7419
diff changeset
   745
    ^ LongFloat fromShortFloat:self
834ea4d6cdbc oops - printString of NaN/INF where wrong;
Claus Gittinger <cg@exept.de>
parents: 7419
diff changeset
   746
!
834ea4d6cdbc oops - printString of NaN/INF where wrong;
Claus Gittinger <cg@exept.de>
parents: 7419
diff changeset
   747
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   748
asShortFloat
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   749
    "return a ShortFloat with same value as the receiver - thats me"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   750
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   751
    ^ self
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
   752
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
   753
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   754
coerce:aNumber
11720
79b29ccf5f3c comment
Claus Gittinger <cg@exept.de>
parents: 11238
diff changeset
   755
    "convert the argument aNumber into an instance of the receivers class and return it."
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   756
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   757
    ^ aNumber asShortFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   758
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   759
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
   760
generality
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
   761
    "return the generality value - see ArithmeticValue>>retry:coercing:"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
   762
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
   763
    ^ 70
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
   764
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
   765
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   766
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   767
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   768
!ShortFloat methodsFor:'comparing'!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   769
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   770
< aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   771
    "return true, if the argument is greater"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   772
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   773
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   774
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   775
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   776
	RETURN ( (__shortFloatVal(self) < (float)(__intVal(aNumber))) ? true : false );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   777
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   778
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   779
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   780
	    RETURN ( (double)(__shortFloatVal(self) < __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   781
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   782
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   783
	    RETURN ( (__shortFloatVal(self) < __shortFloatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   784
	}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   785
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   786
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   787
    ^ aNumber lessFromShortFloat:self
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   788
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
   789
    "
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
   790
     1.0 asShortFloat > (1/3)
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
   791
    "
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   792
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   793
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   794
<= aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   795
    "return true, if the argument is greater or equal"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   796
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   797
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   798
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   799
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   800
	RETURN ( (__shortFloatVal(self) <= (float)(__intVal(aNumber))) ? true : false );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   801
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   802
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   803
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   804
	    RETURN ( (double)(__shortFloatVal(self) <= __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   805
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   806
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   807
	    RETURN ( (__shortFloatVal(self) <= __shortFloatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   808
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   809
    }
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   810
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
    ^ self retry:#<= coercing:aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   812
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   813
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   814
= aNumber
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   815
    "return true, if the argument represents the same numeric value
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   816
     as the receiver, false otherwise"
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   817
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   818
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   819
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   820
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   821
	RETURN ( (__shortFloatVal(self) == (float)(__intVal(aNumber))) ? true : false );
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   822
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   823
    if (aNumber == nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   824
	RETURN (false);
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   825
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   826
    if (__qIsFloatLike(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   827
	RETURN ( (double)(__shortFloatVal(self) == __floatVal(aNumber)) ? true : false );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   828
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   829
    if (__qIsShortFloat(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   830
	RETURN ( (__shortFloatVal(self) == __shortFloatVal(aNumber)) ? true : false );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   831
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   832
%}.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   833
    ^ aNumber equalFromShortFloat:self
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   834
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   835
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   836
> aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   837
    "return true, if the argument is less"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   838
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   839
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   840
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   841
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   842
	RETURN ( (__shortFloatVal(self) > (float)(__intVal(aNumber))) ? true : false );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   843
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   844
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   845
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   846
	    RETURN ( (double)(__shortFloatVal(self) > __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   847
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   848
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   849
	    RETURN ( (__shortFloatVal(self) > __shortFloatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   850
	}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   851
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   852
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   853
    ^ self retry:#> coercing:aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   854
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   855
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   856
>= aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   857
    "return true, if the argument is less or equal"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   858
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   859
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   860
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   861
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   862
	RETURN ( (__shortFloatVal(self) >= (float)(__intVal(aNumber))) ? true : false );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   863
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   864
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   865
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   866
	    RETURN ( (double)(__shortFloatVal(self) >= __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   867
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   868
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   869
	    RETURN ( (__shortFloatVal(self) >= __shortFloatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   870
	}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   871
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   872
%}.
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   873
    ^ self retry:#>= coercing:aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   874
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   875
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   876
hash
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   877
    "return a number for hashing; redefined, since floats compare
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   878
     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
   879
     as 3 hash."
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   880
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   881
    |i|
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   882
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   883
    (self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
   884
	i := self asInteger.
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
   885
	self = i ifTrue:[
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
   886
	    ^ i hash
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
   887
	].
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   888
    ].
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   889
4594
eb09f567a3bc float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents: 4593
diff changeset
   890
    ^ self asFloat hash
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
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   893
     1.2345 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   894
     1.2345 asShortFloat hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   895
     1.0 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   896
     1.0 asShortFloat hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   897
     0.5 asShortFloat hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   898
     0.25 asShortFloat hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   899
     0.5 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   900
     0.25 hash
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   901
    "
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   902
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   903
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   904
~= aNumber
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   905
    "return true, if the arguments value are not equal"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   906
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   907
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   908
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   909
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   910
	if (__isSmallInteger(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   911
	    RETURN ( (__shortFloatVal(self) != (float)(__intVal(aNumber))) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   912
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   913
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   914
	    RETURN ( (double)(__shortFloatVal(self) !=  __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   915
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   916
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   917
	    RETURN ( (__shortFloatVal(self) !=  __shortFloatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   918
	}
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   919
    } else {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   920
	RETURN ( true );
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   921
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   922
%}.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   923
    ^ super ~= aNumber
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   924
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   925
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   926
!ShortFloat methodsFor:'printing & storing'!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   927
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   928
printString
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3158
diff changeset
   929
    "return a printed representation of the receiver
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3158
diff changeset
   930
     LimitedPrecisonReal and its subclasses use #printString instead of
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3158
diff changeset
   931
     #printOn: as basic print mechanism."
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   932
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   933
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   934
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   935
    char buffer[64];
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   936
    REGISTER char *cp;
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   937
    int len;
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   938
    OBJ s;
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   939
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   940
    /*
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   941
     * actually only needed on sparc: since thisContext is
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   942
     * in a global register, which gets destroyed by printf,
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   943
     * manually save it here - very stupid ...
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   944
     */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   945
    __BEGIN_PROTECT_REGISTERS__
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   946
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   947
#ifdef SYSV
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   948
    len = snprintf(buffer, sizeof(buffer), "%.6lg", (double)__shortFloatVal(self));
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   949
#else
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   950
    len = snprintf(buffer, sizeof(buffer), "%.6G", (double)__shortFloatVal(self));
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   951
#endif
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   952
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   953
    __END_PROTECT_REGISTERS__
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   954
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   955
    if (len >= 0 && len <= sizeof(buffer)-3) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   956
	/*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   957
	 * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   958
	 * (i.e. look if string contains '.' or 'e' and append '.0' if not)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   959
	 */
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   960
	for (cp = buffer; *cp; cp++) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   961
	    if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   962
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   963
	if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   964
	    if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   965
		*cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   966
	    } else {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   967
		*cp++ = '.';
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   968
	    }
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   969
	    *cp++ = '0';
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   970
	    *cp = '\0';
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   971
	} else {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   972
	    if (cp && (*cp == '.')) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   973
		if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   974
		    *cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   975
		}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   976
	    }
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   977
	}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   978
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   979
	s = __MKSTRING(buffer);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   980
	if (s != nil) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   981
	    RETURN (s);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   982
	}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   983
    }
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   984
%}.
5432
c71559a881e2 migration support
Claus Gittinger <cg@exept.de>
parents: 5411
diff changeset
   985
    ^ self asFloat printString
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   986
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   987
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   988
	1.234 asShortFloat printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   989
	1.0 asShortFloat printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   990
	1e10 asShortFloat printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   991
	1.2e3 asShortFloat printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   992
	1.2e30 asShortFloat printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   993
	(1.0 uncheckedDivide:0) asShortFloat printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   994
	(0.0 uncheckedDivide:0) asShortFloat printString.
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
   995
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   996
	DecimalPointCharacterForPrinting := $,.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   997
	1.234 asShortFloat printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   998
	1.0 asShortFloat printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
   999
	1e10 asShortFloat printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1000
	1.2e3 asShortFloat printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1001
	1.2e30 asShortFloat printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1002
	(1.0 uncheckedDivide:0) asShortFloat printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1003
	(0.0 uncheckedDivide:0) asShortFloat printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1004
	DecimalPointCharacterForPrinting := $.
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
  1005
    "
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1006
!
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1007
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1008
printfPrintString:formatString
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7725
diff changeset
  1009
    "non-standard: return a printed representation of the receiver
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1010
     as specified by formatString, which is defined by printf.
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1011
     If you use this, be aware, that specifying doubles differs on
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1012
     systems; on SYSV machines you have to give something like %lf,
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1013
     while on BSD systems the format string has to be %F.
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1014
     Also, the resulting string may not be longer than 255 bytes -
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1015
     since thats the (static) size of the buffer.
11924
db93de0d761d changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11730
diff changeset
  1016
     This method is NONSTANDARD and may be removed without notice.
db93de0d761d changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11730
diff changeset
  1017
     WARNNG: this goes directly to the C-printf function and may therefore me inherently unsafe.
db93de0d761d changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11730
diff changeset
  1018
     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
  1019
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1020
%{  /* STACK: 400 */
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1021
    char buffer[256];
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1022
    OBJ s;
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
  1023
    int len;
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1024
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1025
    if (__isString(formatString)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1026
	/*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1027
	 * actually only needed on sparc: since thisContext is
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1028
	 * in a global register, which gets destroyed by printf,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1029
	 * manually save it here - very stupid ...
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1030
	 */
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1031
	__BEGIN_PROTECT_REGISTERS__
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1032
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1033
	len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __shortFloatVal(self));
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
  1034
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1035
	__END_PROTECT_REGISTERS__
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
  1036
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1037
	if (len < 0) goto fail;
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
  1038
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1039
	s = __MKSTRING_L(buffer, len);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1040
	if (s != nil) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1041
	    RETURN (s);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1042
	}
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1043
    }
8418
37ccc74bbf9e Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
  1044
fail: ;
5718
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1045
%}.
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1046
    self primitiveFailed
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1047
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1048
    "ShortFloat pi printfPrintString:'%%lg -> %lg'"
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1049
    "ShortFloat pi printfPrintString:'%%lf -> %lf'"
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1050
    "ShortFloat pi printfPrintString:'%%7.5lg -> %7.5lg'"
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1051
    "ShortFloat pi printfPrintString:'%%G -> %G'"
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1052
    "ShortFloat pi printfPrintString:'%%F -> %F'"
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1053
    "ShortFloat pi printfPrintString:'%%7.5G -> %7.5G'"
dfb94d8e4ad1 added #printfPrintString
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1054
    "ShortFloat pi printfPrintString:'%%7.5F -> %7.5F'"
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1055
!
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1056
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1057
storeString
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1058
    "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
  1059
     all valid digits are printed.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1060
     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
  1061
     #storeOn: as basic print mechanism."
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1062
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1063
%{  /* NOCONTEXT */
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1064
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1065
    char buffer[64];
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1066
    REGISTER char *cp;
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1067
    OBJ s;
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1068
    int len;
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1069
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1070
    /*
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1071
     * build a printf format string
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1072
     */
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1073
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1074
    __BEGIN_PROTECT_REGISTERS__
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1075
#ifdef SYSV
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1076
    len = snprintf(buffer, sizeof(buffer), "%.6lg", (double)__shortFloatVal(self));
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1077
#else
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1078
    len = snprintf(buffer, sizeof(buffer), "%.6G", (double)__shortFloatVal(self));
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1079
#endif
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1080
    __END_PROTECT_REGISTERS__
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1081
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1082
    if (len >= 0 && len < sizeof(buffer)-3) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1083
	/*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1084
	 * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1085
	 * (i.e. look if string contains '.' or 'e' and append '.0' if not)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1086
	 */
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1087
	for (cp = buffer; *cp; cp++) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1088
	    if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1089
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1090
	if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1091
	    *cp++ = '.';
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1092
	    *cp++ = '0';
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1093
	    *cp = '\0';
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1094
	}
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1095
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1096
	s = __MKSTRING(buffer);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1097
	if (s != nil) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1098
	    RETURN (s);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1099
	}
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1100
    }
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1101
%}.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1102
    "
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1103
     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
  1104
     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
  1105
     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
  1106
     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
  1107
     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
  1108
    "
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1109
    ^ ObjectMemory allocationFailureSignal raise.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1110
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1111
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1112
	1.0 asShortFloat storeString
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1113
	1.234 asShortFloat storeString
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1114
	1e10 asShortFloat storeString
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1115
	1.2e3 asShortFloat storeString
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1116
	1.2e30 asShortFloat storeString
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1117
	Float pi asShortFloat storeString
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1118
	(1.0 uncheckedDivide:0) asShortFloat storeString
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1119
	(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
  1120
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
  1121
     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
  1122
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1123
	DecimalPointCharacterForPrinting := $,.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1124
	1.234 asShortFloat storeString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1125
	1.0 asShortFloat storeString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1126
	1e10 asShortFloat storeString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1127
	1.2e3 asShortFloat storeString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1128
	1.2e30 asShortFloat storeString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1129
	(1.0 uncheckedDivide:0) asShortFloat storeString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1130
	(0.0 uncheckedDivide:0) asShortFloat storeString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1131
	DecimalPointCharacterForPrinting := $.
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8418
diff changeset
  1132
    "
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1133
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1134
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1135
!ShortFloat methodsFor:'special access'!
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1136
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1137
exponent
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1138
    "extract a normalized floats exponent.
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1139
     The returned value depends on the float-representation of
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1140
     the underlying machine and is therefore highly unportable.
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1141
     This is not for general use.
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1142
     This assumes that the mantissa is normalized to
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1143
     0.5 .. 1.0 and the floats value is mantissa * 2^exp"
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1144
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1145
%{  /* NOCONTEXT */
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1146
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1147
    double frexp();
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1148
    int exp;
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1149
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1150
    __threadErrno = 0;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8706
diff changeset
  1151
#if defined(__i386__) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1152
    frexpf( __shortFloatVal(self), &exp);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1153
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1154
    frexp( (double)(__shortFloatVal(self)), &exp);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1155
#endif
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1156
    if (__threadErrno == 0) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1157
	RETURN (__mkSmallInteger(exp));
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1158
    }
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1159
%}.
7387
9be7990ded99 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7380
diff changeset
  1160
    ^ super exponent
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1161
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1162
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1163
     4.0 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1164
     2.0 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1165
     1.0 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1166
     0.5 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1167
     0.25 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1168
     0.00000011111 asShortFloat exponent
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1169
    "
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1170
!
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1171
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1172
mantissa
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1173
    "extract a normalized floats mantissa.
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1174
     The returned value depends on the float-representation of
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1175
     the underlying machine and is therefore highly unportable.
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1176
     This is not for general use.
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1177
     This assumes that the mantissa is normalized to
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1178
     0.5 .. 1.0 and the floats value is mantissa * 2^exp"
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1179
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1180
%{  /* NOCONTEXT */
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1181
    int exp;
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1182
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8706
diff changeset
  1183
#if defined(__i386__) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1184
    float frac;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1185
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1186
    __threadErrno = 0;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1187
    frac = frexpf( (double)__shortFloatVal(self), &exp);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1188
    if (__threadErrno == 0) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1189
	RETURN (__MKSFLOAT(frac));
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1190
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1191
#else
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1192
    double frexp();
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1193
    double frac;
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1194
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1195
    __threadErrno = 0;
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1196
    frac = frexp( (double)(__shortFloatVal(self)), &exp);
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1197
    if (__threadErrno == 0) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1198
	RETURN (__MKFLOAT(frac));
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1199
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1200
#endif
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1201
%}.
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1202
    ^ self primitiveFailed
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1203
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1204
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1205
     1.0 asShortFloat exponent
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1206
     1.0 asShortFloat mantissa
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1207
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1208
     0.5 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1209
     0.5 asShortFloat mantissa
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1210
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1211
     0.25 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1212
     0.25 asShortFloat mantissa
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1213
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1214
     0.00000011111 asShortFloat exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1215
     0.00000011111 asShortFloat mantissa
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1216
    "
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1217
! !
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1218
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1219
!ShortFloat methodsFor:'testing'!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1220
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1221
isFinite
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1222
    "return true, if the receiver is a finite float
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1223
     i.e. not NaN and not infinite."
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1224
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1225
%{  /* NOCONTEXT */
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
  1226
    float fV = __shortFloatVal(self);
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1227
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  1228
    /*
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  1229
     * notice: on machines which do not provide
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1230
     * a isfinite() macro or function (WIN32),
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
  1231
     * 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
  1232
     */
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
  1233
    if (isfinitef(fV)) { RETURN (true); }
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1234
%}.
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
  1235
    ^ false
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1236
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1237
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1238
	1.0 asShortFloat isFinite
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1239
	(0.0 asShortFloat uncheckedDivide: 0.0) isFinite
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1240
	(1.0 asShortFloat uncheckedDivide: 0.0) isFinite
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1241
    "
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1242
!
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1243
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  1244
isNaN
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  1245
    "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
  1246
     These are not created by ST/X float operations (they raise an exception);
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  1247
     however, inline C-code could produce them ..."
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  1248
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  1249
%{  /* NOCONTEXT */
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
  1250
    float sV = __shortFloatVal(self);
3139
ca
parents: 3014
diff changeset
  1251
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  1252
    /*
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  1253
     * notice: on machines which do not provide
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1254
     * a isnan() macro or function (WIN32),
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4297
diff changeset
  1255
     * 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
  1256
     */
9121
561e28aa22f9 fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
  1257
    if (isnanf(sV)) { RETURN (true); }
2392
cd44ad5cf015 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2391
diff changeset
  1258
%}.
cd44ad5cf015 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2391
diff changeset
  1259
    ^ false
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  1260
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1261
    "
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1262
     1.0 asShortFloat isNaN
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1263
     (0.0 asShortFloat uncheckedDivide: 0.0) isNaN
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1264
     (0.0 asShortFloat uncheckedDivide: 0.0 asShortFloat) isNaN
3147
60396c4b82eb New #finite, fix #isNaN.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1265
    "
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  1266
!
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  1267
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  1268
isNegativeZero
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  1269
    "many systems have two float.Pnt zeros"
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  1270
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  1271
%{
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8706
diff changeset
  1272
#if defined(__i386__) && defined(linux)
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  1273
    RETURN ((__ByteArrayInstPtr(self)->ba_element[sizeof(float)-1] == 128) ? true : false );
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  1274
#endif
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  1275
%}.
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  1276
    ^ super isNegativeZero
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  1277
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  1278
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1279
     0.0 asShortFloat isNegativeZero
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1280
     -0.0 asShortFloat isNegativeZero
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  1281
    "
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  1282
!
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
  1283
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1284
negative
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1285
    "return true if the receiver is less than zero"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1286
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1287
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1288
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1289
    RETURN ( (__shortFloatVal(self) < 0.0) ? true : false );
5411
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
  1290
%}.
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1291
!
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1292
5357
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  1293
numberOfBits
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  1294
    "return the size (in bits) of the real;
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  1295
     typically, 32 is returned here,
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  1296
     but who knows ..."
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  1297
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  1298
%{  /* NOCONTEXT */
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  1299
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1300
    RETURN (__mkSmallInteger (sizeof(float) * 8));
5357
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  1301
%}
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  1302
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  1303
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1304
     1.2 numberOfBits
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1305
     1.2 asShortFloat numberOfBits
5357
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  1306
    "
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  1307
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  1308
!
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  1309
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1310
positive
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1311
    "return true if the receiver is greater or equal to zero"
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1312
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1313
%{  /* NOCONTEXT */
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1314
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1315
    RETURN ( (__shortFloatVal(self) >= 0.0) ? true : false );
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1316
%}
1880
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1317
!
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1318
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1319
strictlyPositive
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1320
    "return true if the receiver is greater than zero"
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1321
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1322
%{  /* NOCONTEXT */
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1323
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1324
    RETURN ( (__shortFloatVal(self) > 0.0) ? true : false );
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1325
%}
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1326
! !
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1327
5552
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5432
diff changeset
  1328
!ShortFloat methodsFor:'truncation & rounding'!
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1329
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1330
ceiling
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1331
    "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
  1332
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1333
    |val|
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1334
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1335
%{
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1336
    float fVal;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1337
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8706
diff changeset
  1338
#if defined(__i386__) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1339
    fVal = ceilf(__shortFloatVal(self));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1340
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1341
    fVal = (float)(ceil((double)__shortFloatVal(self)));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1342
#endif
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1343
    /*
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1344
     * ST-80 (and X3J20) returns integer.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1345
     */
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1346
    if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1347
	RETURN ( __mkSmallInteger( (INT) fVal ) );
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1348
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1349
    __qMKSFLOAT(val, fVal);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1350
%}.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1351
    ^ val asInteger
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1352
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1353
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1354
     0.5 asShortFloat ceiling
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1355
     -0.5 asShortFloat ceiling
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1356
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1357
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1358
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1359
ceilingAsFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1360
    "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
  1361
     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
  1362
     of the result to an integer.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1363
     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
  1364
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1365
%{  /* NOCONTEXT */
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1366
    float fVal;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1367
    OBJ v;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1368
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8706
diff changeset
  1369
#if defined(__i386__) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1370
    fVal = ceilf(__shortFloatVal(self));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1371
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1372
    fVal = (float) ceil((double)__shortFloatVal(self));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1373
#endif
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1374
    __qMKSFLOAT(v, fVal);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1375
    RETURN (v);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1376
%}
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1377
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1378
     0.5 asShortFloat ceilingAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1379
     -0.5 asShortFloat ceilingAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1380
     -1.5 asShortFloat ceilingAsFloat
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1381
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1382
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1383
4100
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1384
floor
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1385
    "return the integer nearest the receiver towards negative infinity."
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1386
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1387
    |val|
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1388
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1389
%{
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1390
    float fVal;
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1391
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8706
diff changeset
  1392
#if defined(__i386__) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1393
    fVal = floorf(__shortFloatVal(self));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1394
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1395
    fVal = (float)(floor((double)__shortFloatVal(self)));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1396
#endif
4100
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1397
    /*
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1398
     * ST-80 (and X3J20) returns integer.
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1399
     */
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1400
    if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1401
	RETURN ( __mkSmallInteger( (INT) fVal ) );
4100
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1402
    }
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1403
    __qMKSFLOAT(val, fVal);
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1404
%}.
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1405
    ^ val asInteger
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1406
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1407
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1408
     0.5 asShortFloat floor
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1409
     -0.5 asShortFloat floor
4100
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1410
    "
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1411
!
4100
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1412
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1413
floorAsFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1414
    "return the float which represents the next lower
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1415
     integer nearest the receiver towards negative infinity.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1416
     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
  1417
     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
  1418
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1419
%{  /* NOCONTEXT */
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1420
    float fVal;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1421
    OBJ v;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1422
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8706
diff changeset
  1423
#if defined(__i386__) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1424
    fVal = floorf(__shortFloatVal(self));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1425
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1426
    fVal = (float)(floor((double)__shortFloatVal(self)));
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1427
#endif
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1428
    __qMKSFLOAT(v, fVal);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1429
    RETURN ( v );
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1430
%}
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1431
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1432
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1433
     0.5 asShortFloat floorAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1434
     -0.5 asShortFloat floorAsFloat
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1435
    "
4100
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1436
!
a605c54bf9a9 fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
  1437
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1438
fractionPart
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1439
    "extract the after-decimal fraction part.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1440
     such that (self truncated + self fractionPart) = self"
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1441
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1442
%{  /* NOCONTEXT */
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1443
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1444
    double modf();
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1445
    double frac, trunc;
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1446
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1447
    __threadErrno = 0;
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1448
    frac = modf((double)(__shortFloatVal(self)), &trunc);
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1449
    if (! isnan(frac)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1450
	if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1451
	    RETURN (__MKSFLOAT((float)frac));
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1452
	}
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1453
    }
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1454
%}.
7403
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7392
diff changeset
  1455
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1456
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1457
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1458
	selector:#fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1459
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1460
	errorString:'bad receiver in fractionPart'
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1461
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1462
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1463
     1.6 asShortFloat fractionPart + 1.6 asShortFloat truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1464
     -1.6 asShortFloat fractionPart + -1.6 asShortFloat truncated
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1465
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1466
     1.0 asShortFloat fractionalPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1467
     0.5 asShortFloat fractionalPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1468
     0.25 asShortFloat fractionalPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1469
     3.14159 asShortFloat fractionalPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1470
     12345673.14159 asShortFloat fractionalPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1471
     123456731231231231.14159 asShortFloat fractionalPart
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1472
    "
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1473
!
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1474
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1475
rounded
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1476
    "return the receiver rounded to the nearest integer"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1477
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1478
    |val|
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1479
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1480
%{
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1481
    float fVal;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1482
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1483
    fVal = __shortFloatVal(self);
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8706
diff changeset
  1484
#if defined(__i386__) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1485
    if (fVal < 0.0) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1486
	fVal = ceilf(fVal - (float)0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1487
    } else {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1488
	fVal = floorf(fVal + (float)0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1489
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1490
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1491
    if (fVal < 0.0) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1492
	fVal = (float)ceil((double)fVal - 0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1493
    } else {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1494
	fVal = (float)floor((double)fVal + 0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1495
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1496
#endif
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1497
    /*
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1498
     * ST-80 (and X3J20) returns integer.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1499
     */
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1500
    if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1501
	RETURN ( __mkSmallInteger( (INT) fVal ) );
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1502
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1503
    __qMKSFLOAT(val, fVal);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1504
%}.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1505
    ^ val asInteger
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1506
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1507
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1508
     0.4 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1509
     0.5 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1510
     0.6 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1511
     -0.4 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1512
     -0.5 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1513
     -0.6 asShortFloat rounded
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1514
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1515
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1516
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1517
roundedAsFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1518
    "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
  1519
     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
  1520
     of the result to an integer.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1521
     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
  1522
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1523
%{  /* NOCONTEXT */
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1524
    float fVal;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1525
    OBJ v;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1526
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1527
    fVal = __shortFloatVal(self);
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8706
diff changeset
  1528
#if defined(__i386__) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1529
    if (fVal < 0.0) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1530
	fVal = ceilf(fVal - (float)0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1531
    } else {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1532
	fVal = floorf(fVal + (float)0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1533
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1534
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1535
    if (fVal < 0.0) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1536
	fVal = (float)ceil((double)fVal - 0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1537
    } else {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1538
	fVal = (float)floor((double)fVal + 0.5);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1539
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1540
#endif
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1541
    __qMKSFLOAT(v, fVal);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1542
    RETURN (v);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1543
%}
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1544
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1545
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1546
     0.4 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1547
     0.5 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1548
     0.6 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1549
     -0.4 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1550
     -0.5 asShortFloat rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1551
     -0.6 asShortFloat rounded
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1552
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1553
     0.4 asShortFloat roundedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1554
     0.5 asShortFloat roundedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1555
     0.6 asShortFloat roundedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1556
     -0.4 asShortFloat roundedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1557
     -0.5 asShortFloat roundedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1558
     -0.6 asShortFloat roundedAsFloat
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1559
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1560
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1561
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1562
truncated
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1563
    "return the receiver truncated towards zero as an integer"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1564
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1565
    |val|
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1566
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1567
%{
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1568
    float fVal;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1569
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1570
    fVal = __shortFloatVal(self);
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8706
diff changeset
  1571
#if defined(__i386__) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1572
    if (fVal < 0.0) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1573
	fVal = ceilf(fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1574
    } else {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1575
	fVal = floorf(fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1576
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1577
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1578
    if (fVal < 0.0) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1579
	fVal = (float)ceil((double)fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1580
    } else {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1581
	fVal = (float)floor((double)fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1582
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1583
#endif
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1584
    /*
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1585
     * ST-80 (and X3J20) returns integer.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1586
     */
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1587
    if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1588
	RETURN ( __mkSmallInteger( (INT) fVal ) );
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1589
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1590
    __qMKSFLOAT(val, fVal);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1591
%}.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1592
    ^ val asInteger
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1593
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1594
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1595
     0.5 asShortFloat truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1596
     -0.5 asShortFloat truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1597
     0.5 asShortFloat truncatedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1598
     -0.5 asShortFloat truncatedAsFloat
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1599
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1600
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1601
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1602
truncatedAsFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1603
    "return the receiver truncated towards zero as a float.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1604
     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
  1605
     of the result to an integer.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1606
     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
  1607
     float-operation."
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1608
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1609
%{  /* NOCONTEXT */
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1610
    float fVal;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1611
    OBJ v;
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1612
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1613
    fVal = __shortFloatVal(self);
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8706
diff changeset
  1614
#if defined(__i386__) && defined(__GNUC__)
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1615
    if (fVal < 0.0) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1616
	fVal = ceilf(fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1617
    } else {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1618
	fVal = floorf(fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1619
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1620
#else
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1621
    if (fVal < 0.0) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1622
	fVal = (float)ceil((double)fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1623
    } else {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1624
	fVal = (float)floor((double)fVal);
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1625
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1626
#endif
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1627
    __qMKSFLOAT(v, fVal);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1628
    RETURN (v);
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1629
%}
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1630
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1631
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1632
     0.5 asShortFloat truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1633
     -0.5 asShortFloat truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1634
     0.5 asShortFloat truncatedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1635
     -0.5 asShortFloat truncatedAsFloat
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1636
    "
3897
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1637
! !
b50a14f9083e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3895
diff changeset
  1638
1880
64341225f439 added strictlyPositive
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1639
!ShortFloat class methodsFor:'documentation'!
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1640
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1641
version
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11924
diff changeset
  1642
    ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.100 2009-09-16 17:08:24 cg Exp $'
1197
2b37cf664b81 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1643
! !