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