OctaFloat.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5372 32a6486d8c67
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5338
05801efc9fb3 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5327
diff changeset
     1
"{ Encoding: utf8 }"
05801efc9fb3 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5327
diff changeset
     2
5372
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
     3
"
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
     4
 COPYRIGHT (c) 2018 by eXept Software AG
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
     5
              All Rights Reserved
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
     6
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
     7
 This software is furnished under a license and may be used
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
     8
 only in accordance with the terms of that license and with the
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
    10
 be provided or otherwise made available to, or used by, any
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
    11
 other person.  No title to or ownership of the software is
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
    12
 hereby transferred.
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
    13
"
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
"{ NameSpace: Smalltalk }"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
LimitedPrecisionReal variableByteSubclass:#OctaFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:''
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:'OctaFloatZero OctaFloatOne Pi E Epsilon NaN PositiveInfinity
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
		NegativeInfinity Halfpi HalfpiNegative Phi'
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	poolDictionaries:''
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
	category:'Magnitude-Numbers'
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
!OctaFloat primitiveDefinitions!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
%{
5287
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
    28
#ifdef __xxosx__
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
    29
# define SUPPORT_OCTAFLOAT
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
    30
#endif 
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
#include <math.h>
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
extern float256_t STX_addQ(float256_t, float256_t, int);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
extern float256_t STX_mulQ(float256_t, float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
extern float256_t STX_divQ(float256_t, float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
extern float256_t STX_negQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
extern float256_t STX_absQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
extern float256_t STX_floorQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
extern float256_t STX_frexpQ(float256_t, int*);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
extern float256_t STX_ceilQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
extern float256_t STX_logQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
extern float256_t STX_log10Q(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
extern float256_t STX_log2Q(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
extern float256_t STX_expQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
extern float256_t STX_sinQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
extern float256_t STX_cosQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
extern float256_t STX_tanQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
extern float256_t STX_sinhQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
extern float256_t STX_coshQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
extern float256_t STX_tanhQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
extern float256_t STX_asinQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
extern float256_t STX_acosQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
extern float256_t STX_atanQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
extern float256_t STX_asinhQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
extern float256_t STX_acoshQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
extern float256_t STX_atanhQ(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
extern float256_t STX_QZero;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
extern float256_t STX_dbltoQ(double);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
extern float256_t STX_inttoQ(long);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
extern double STX_Qtodbl(float256_t);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
extern int STX_isNanQ(float256_t*);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
extern int STX_prcmpQ(float256_t*, float256_t*);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
#define STX_isfiniteQ(q)    (!STX_isNanQ(&(q)) && !STX_isInfQ(&(q)))
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
#define STX_eqQ(x1, x2)     (STX_prcmpQ (&(x1), &(x2)) == 0)
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
#define STX_neqQ(x1, x2)    (STX_prcmpQ (&(x1), &(x2)) != 0)
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
#define STX_gtQ(x1, x2)     (STX_prcmpQ (&(x1), &(x2)) > 0)
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
#define STX_geQ(x1, x2)     (STX_prcmpQ (&(x1), &(x2)) >= 0)
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
#define STX_ltQ(x1, x2)     (STX_prcmpQ (&(x1), &(x2)) < 0)
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
#define STX_leQ(x1, x2)     (STX_prcmpQ (&(x1), &(x2)) <= 0)
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
#ifdef __win32__
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
/*
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
 * no finite(x) ?
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
 * no isnan(x) ?
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
 */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
# ifndef isnan
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
#  define isnan(x)      \
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
	((((unsigned int *)(&x))[0] == 0x00000000) && \
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
	 (((unsigned int *)(&x))[1] == 0xFFF80000))
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
# endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
# ifndef isPositiveInfinity
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
#  define isPositiveInfinity(x) \
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
	((((unsigned int *)(&x))[0] == 0x00000000) && \
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
	 (((unsigned int *)(&x))[1] == 0x7FF00000))
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
# endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
# ifndef isNegativeInfinity
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
#  define isNegativeInfinity(x) \
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
	((((unsigned int *)(&x))[0] == 0x00000000) && \
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
	 (((unsigned int *)(&x))[1] == 0xFFF00000))
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
# endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
# ifndef isinf
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
#  define isinf(x) \
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
	((((unsigned int *)(&x))[0] == 0x00000000) && \
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
	 ((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000))
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
# endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
# ifndef isfinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
#  define isfinite(x) (!isinf(x) && !isnan(x))
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
# endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
#else // not win32
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
%}
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
!OctaFloat primitiveVariables!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
%{
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
%}
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
!OctaFloat primitiveFunctions!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
%{
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
%}
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
!OctaFloat class methodsFor:'documentation'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
5372
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
   124
copyright
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
   125
"
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
   126
 COPYRIGHT (c) 2018 by eXept Software AG
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
   127
              All Rights Reserved
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
   128
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
   129
 This software is furnished under a license and may be used
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
   130
 only in accordance with the terms of that license and with the
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
   131
 inclusion of the above copyright notice.   This software may not
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
   132
 be provided or otherwise made available to, or used by, any
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
   133
 other person.  No title to or ownership of the software is
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
   134
 hereby transferred.
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
   135
"
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
   136
!
32a6486d8c67 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5338
diff changeset
   137
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
documentation
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
    OctaFloats represent rational numbers with limited precision
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    and are mapped to IEEE octuple precision format (256bit),
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    also called binary256.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
    Notice, that a software emulation is done, which is much slower.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
    Thus only use them, if you really need the additional precision;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    if not, use Float (which are doubles) or LongFloats which usually have IEEE extended precision (80bit).
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
    OctaFloats give you definite 256 bit quadruple floats,
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    thus, code using octaFloats is guaranteed to be portable from one architecture to another.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
    Representation:
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
	    256bit octuple IEEE floats (32bytes);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
	    237 bit mantissa,
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
	    19 bit exponent,
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
	    71 decimal digits (approx.)
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    Mixed mode arithmetic:
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
	octaFloat op anyFloat    -> octaFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
	anyFloat op octaFloat    -> octaFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
    Range and precision of storage formats: see LimitedPrecisionReal >> documentation
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
    [author:]
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
	Claus Gittinger
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
    [see also:]
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
	Number
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
	Float ShortFloat LongFloat Fraction FixedPoint Integer Complex
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
	FloatArray DoubleArray
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
	https://en.wikipedia.org/wiki/Extended_precision
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
	https://en.wikipedia.org/wiki/Octuple-precision_floating-point_format
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
!OctaFloat class methodsFor:'instance creation'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
basicNew
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
    "return a new octaFloat - here we return 0.0
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
     - OctaFloats are usually NOT created this way ...
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
     Its implemented here to allow things like binary store & load
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
     of quadFloats.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
     (but it is not a good idea to store the bits of a float - the reader might have a
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
      totally different representation - so floats should be
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
      binary stored in a device independent format)."
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
    float256_t qf = STX_QZero;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
    __qMKFLOAT256(newFloat, qf);   /* OBJECT ALLOCATION */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
    RETURN (newFloat);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
#endif /* SUPPORT_QUADFLOAT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    self error:'OctaFloats not supported on this patform'
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
    "Created: / 06-06-2019 / 17:18:58 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
fromFloat:aFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
    "return a new quadFloat, given a float value"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
    if (__isFloatLike(aFloat)) {
5289
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   208
        double f = __floatVal(aFloat);
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   209
        float256_t qf;
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
5289
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   211
        qf = STX_dbltoQ (f);
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   212
        __qMKFLOAT256(newFloat, qf);   /* OBJECT ALLOCATION */
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   213
        RETURN (newFloat);
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
    }
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
#endif /* SUPPORT_OCTAFLOAT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
    aFloat isFloat ifTrue:[
5289
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   218
        self errorUnsupported.
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   219
        ^ aFloat asLongFloat
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
    ArgumentError raise
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
     OctaFloat fromFloat:123.0
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
     123.0 asOctaFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
     123 asOctaFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
    "Created: / 06-06-2019 / 18:01:03 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
fromInteger:anInteger
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
    "return a new quadFloat, given an integer value"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
    if (__isSmallInteger(anInteger)) {
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
	INT iVal = __intVal(anInteger);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
	float256_t qf;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
	qf = STX_inttoQ( (long)iVal );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
	__qMKFLOAT256(newFloat, qf);   /* OBJECT ALLOCATION */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
	RETURN (newFloat);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
    }
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
#endif /* SUPPORT_OCTAFLOAT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
    ^ super fromInteger:anInteger
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
     OctaFloat fromInteger:123
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
     123 asOctaFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
fromLongFloat:aFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
    "return a new quadFloat, given a long float value"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
#ifdef xSUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
    union {
5289
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   264
        LONGFLOAT_t lf;         // is long double
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   265
        extFloat80_t ef;        // is 80bit ext
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   266
        float256_t qf;          // is 128bit quad
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
    } u;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
    if (__isLongFloat(aFloat)) {
5289
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   270
        u.lf = __longFloatVal(aFloat);
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
5289
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   272
        if (sizeof(LONGFLOAT_t) == 16) {
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   273
            // longFloat is already 128 bits in size (sparc)
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   274
            __qMKFLOAT256(newFloat, u.qf);   /* OBJECT ALLOCATION */
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   275
            RETURN (newFloat);
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   276
        }
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   277
        if (sizeof(LONGFLOAT_t) < 16) {
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   278
            // assume 80bit extended float format (amd64, x86_64)
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   279
            u.qf = extF80_to_f128( u.ef);
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   280
            __qMKFLOAT256(newFloat, u.qf);   /* OBJECT ALLOCATION */
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   281
            RETURN (newFloat);
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   282
        }
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   283
        // fall into error case
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
    }
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
#endif /* SUPPORT_OCTAFLOAT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
    aFloat isLongFloat ifTrue:[
5289
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   288
        self errorUnsupported.
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   289
        ^ aFloat
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
    ArgumentError raise
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
     OctaFloat fromLongFloat:123.0 asLongFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
fromShortFloat:aShortFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
    "return a new quadFloat, given a float value"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
    ^ self fromFloat:(aShortFloat asFloat)
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
     OctaFloat fromShortFloat:123.0 asShortFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
    "Created: / 08-06-2019 / 03:28:37 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
!OctaFloat class methodsFor:'coercing & converting'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
coerce:aNumber
5327
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
   313
    "convert the argument aNumber into an instance of the receiver (class) and return it."
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
    ^ aNumber asOctaFloat.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
    "Created: / 06-06-2019 / 16:51:01 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
!OctaFloat class methodsFor:'constants'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
NaN
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
    "return a quadFloat which represents not-a-Number (i.e. an invalid number)"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
    |nan|
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
    NaN isNil ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
#ifdef xSUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
	{
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
	    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
	    float256_t qf;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
	    softfloat_commonNaNToF128M( (uint32_t*)(&qf) );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
	    __qMKFLOAT256(newFloat, qf);   /* OBJECT ALLOCATION */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
	    nan = newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
	}
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
#endif /* SUPPORT_OCTAFLOAT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
%}.
5287
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   340
        nan isNil ifTrue:[
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   341
	    self errorUnsupported
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   342
        ].
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
	NaN := nan
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
    ^ NaN
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
e
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
    "return the constant e as quadFloat"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
    E isNil ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
	"/ eDigits has enough digits for 128bit IEEE quads
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
	"/ do not use as a literal constant here - we cannot depend on the underlying C-compiler here...
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
	E  := self readFrom:(Number eDigits)
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
    ^ E
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
    "Created: / 06-06-2019 / 17:01:54 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
infinity
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
    "return a quadFloat which represents +INF"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
    |inf|
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
    PositiveInfinity isNil ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
#ifdef xSUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
	{
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
	    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
	    struct uint128 uiZ;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
	    union ui128_f128 uZ;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
	    float256_t qf;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
	    uiZ.v64 = packToF128UI64( 0, 0x7FFF, 0 );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
	    uiZ.v0 = 0;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
	    uZ.ui = uiZ;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
	    qf = uZ.f;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
	    __qMKFLOAT256(newFloat, qf);   /* OBJECT ALLOCATION */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
	    inf = newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
	}
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
#endif /* SUPPORT_OCTAFLOAT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
%}.
5287
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   384
        inf isNil ifTrue:[
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   385
	    self errorUnsupported
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   386
        ].
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
	PositiveInfinity := inf
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
    ^ PositiveInfinity
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
    "Created: / 08-06-2019 / 14:05:26 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   392
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
negativeInfinity
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
    "return a quadFloat which represents -INF"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
    |inf|
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
    NegativeInfinity isNil ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   401
#ifdef xSUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
	{
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
	    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   404
	    struct uint128 uiZ;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
	    union ui128_f128 uZ;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   406
	    float256_t qf;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   407
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
	    uiZ.v64 = packToF128UI64( 1, 0x7FFF, 0 );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
	    uiZ.v0 = 0;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
	    uZ.ui = uiZ;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
	    qf = uZ.f;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
	    __qMKFLOAT256(newFloat, qf);   /* OBJECT ALLOCATION */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
	    inf = newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
	}
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
#endif /* SUPPORT_OCTAFLOAT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
%}.
5287
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   417
        inf isNil ifTrue:[
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   418
	    self errorUnsupported
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   419
        ].
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   420
	NegativeInfinity := inf
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
    ^ NegativeInfinity
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
    "Created: / 08-06-2019 / 14:05:50 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
phi
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
    "return the constant phi as quadFloat"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
    Phi isNil ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
	"/ phiDigits has enough digits for 128bit IEEE quads
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
	"/ do not use as a literal constant here - we cannot depend on the underlying C-compiler here...
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
	Phi  := self readFrom:(Number phiDigits)
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
    ^ Phi
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   438
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
pi
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
    "return the constant pi as quadFloat"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
    Pi isNil ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
	"/ piDigits has enough digits for 128bit IEEE quads
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
	"/ do not use as a literal constant here - we cannot depend on the underlying C-compiler here...
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
	Pi  := self readFrom:(Number piDigits)
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
    ^ Pi
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
    "Created: / 06-06-2019 / 17:09:51 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
unity
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
    "return the neutral element for multiplication (1.0) as OctaFloat"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
    OctaFloatOne isNil ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
	OctaFloatOne := 1.0 asOctaFloat.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
    ^ OctaFloatOne
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
    "Created: / 07-06-2019 / 03:26:38 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   462
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   463
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   464
zero
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   465
    "return the neutral element for addition (0.0) as OctaFloat"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   466
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
    OctaFloatZero isNil ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
	OctaFloatZero := 0.0 asOctaFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
    ^ OctaFloatZero
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
    "Created: / 07-06-2019 / 09:22:56 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   473
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
!OctaFloat class methodsFor:'error reportng'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
errorUnsupported
5289
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   478
    "you may proceed from this error, to get a long float number result 
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   479
     (of course, with less than expected precision)"
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   480
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   481
    self errorUnsupported:'OctaFloats not supported on this patform'
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   482
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   483
    "Created: / 07-06-2019 / 02:44:39 / Claus Gittinger"
5289
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   484
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   485
    "
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   486
     UnimplementedFunctionalityError handle:[:ex |
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   487
         ex proceed
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   488
     ] do:[
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   489
         1.0 asQuadFloat
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   490
     ]. 
dddb01fc42d9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5287
diff changeset
   491
    "
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   492
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   493
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   494
!OctaFloat class methodsFor:'queries'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
epsilon
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
    "return the maximum relative spacing of instances of mySelf
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
     (i.e. the value-delta of the least significant bit)"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
    Epsilon isNil ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
	Epsilon := self computeEpsilon.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
    ^ Epsilon
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
     self epsilon
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
    "Created: / 10-06-2019 / 21:21:18 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
exponentCharacter
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
    "return the character used to print between mantissa an exponent.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
     Also used by the scanner when reading numbers."
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
    ^ $O
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
    "Created: / 10-06-2019 / 21:28:04 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
numBitsInExponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
    "answer the number of bits in the exponent.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
     This is a 256bit octuple float, where 19 bits are available in the exponent:
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   524
        seeeeeee eeeeeeee eeeemmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm...
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
    ^ 19
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
     1.0 class numBitsInExponent -> 11
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531
     1.0 asShortFloat class numBitsInExponent -> 8
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
     1.0 asLongFloat class numBitsInExponent -> 15
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   533
     1.0 asQuadFloat class numBitsInExponent -> 15
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   534
     1.0 asOctaFloat class numBitsInExponent -> 19
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   535
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   537
    "Created: / 11-06-2019 / 00:14:55 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   539
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   540
numBitsInMantissa
5338
05801efc9fb3 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5327
diff changeset
   541
    "answer the number of bits in the mantissa (the significant)
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   542
     This is a 256bit quadfloat,
5338
05801efc9fb3 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5327
diff changeset
   543
           where 236 bits are available in the mantissa (the hidden bit is not counted here):
05801efc9fb3 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5327
diff changeset
   544
        seeeeeee eeeeeeee eeeemmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm...
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   545
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   546
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   547
    ^ 236
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   548
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   549
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   550
     1.0 class numBitsInMantissa
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   551
     1.0 asShortFloat class numBitsInMantissa
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   552
     1.0 asLongFloat class numBitsInMantissa
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   553
     1.0 asQuadFloat class numBitsInMantissa
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   554
     1.0 asOctaFloat class numBitsInMantissa
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   555
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   556
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
    "Created: / 07-06-2019 / 03:24:20 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   558
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   559
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   560
radix
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   561
    "answer the radix of a OctaFloat's exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   562
     This is an IEEE float, which is represented as binary"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   563
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   564
    ^ 2 "must be careful here, whenever ST/X is used on VAX or a 370"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   565
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   566
    "Created: / 19-07-2019 / 17:28:00 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   567
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   568
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   569
!OctaFloat methodsFor:'arithmetic'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   570
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   571
* aNumber
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   572
    "return the product of the receiver and the argument."
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   573
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   574
    aNumber class == OctaFloat ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   575
	^ aNumber productFromOctaFloat:self
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   576
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   577
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   578
    thisContext isReallyRecursive ifTrue:[self error].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   579
    ^ aNumber productFromOctaFloat:self
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   580
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   581
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   582
+ aNumber
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   583
    "return the sum of the receiver and the argument, aNumber"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   584
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   585
    ^ aNumber sumFromOctaFloat:self
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   586
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   587
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   588
- aNumber
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   589
    "return the difference of the receiver and the argument, aNumber"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   590
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   591
    ^ aNumber differenceFromOctaFloat:self
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   592
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   593
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   594
/ aNumber
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   595
    "return the quotient of the receiver and the argument, aNumber"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   596
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   597
    aNumber isZero ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   598
	"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   599
	 No, you shalt not divide by zero
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   600
	"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   601
	^ ZeroDivide raiseRequestWith:thisContext.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   602
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   603
    ^ aNumber quotientFromOctaFloat:self
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   604
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   605
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   606
abs
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   607
    "return the absolute value of the receiver
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   608
     reimplemented here for speed"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   609
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   610
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   611
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   612
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   613
    float256_t result, myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   614
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   615
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   616
    result = STX_absQ(myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   617
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   618
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   619
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   620
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   621
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   622
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
ceiling
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   624
    "return the smallest integer which is greater or equal to the receiver."
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   625
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   626
    |val|
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   627
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   628
%{
5287
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   629
#ifdef SUPPORT_OCTAFLOAT
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   630
    float256_t qVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   631
    float256_t qMinInt;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   632
    float256_t qMaxInt;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   633
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   634
    qVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   635
    qVal = STX_ceilQ(qVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   636
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   637
    qMinInt = STX_dbltoQ((double)_MIN_INT);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   638
    qMaxInt = STX_dbltoQ((double)_MAX_INT);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   639
    if (STX_geQ(qVal, qMinInt) && STX_leQ(qVal, qMaxInt)) {
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   640
	double dVal = STX_Qtodbl(qVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   641
	RETURN ( __mkSmallInteger( (INT) dVal ) );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   642
    }
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   643
    __qMKFLOAT256(val, qVal);
5287
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   644
#endif
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   645
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   646
    ^ val asInteger
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   647
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   648
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
     0.5 asOctaFloat ceiling
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   650
     0.5 asOctaFloat ceilingAsFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   651
     -0.5 asOctaFloat ceiling
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   652
     -0.5 asOctaFloat ceilingAsFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   653
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   654
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   655
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   656
ceilingAsFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   657
    "return the smallest integer-valued float greater or equal to the receiver.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   658
     This is much like #ceiling, but avoids a (possibly expensive) conversion
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   659
     of the result to an integer.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   660
     It may be useful, if the result is to be further used in another float-operation."
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   661
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   662
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   663
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   664
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   665
    float256_t result, myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   666
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   667
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   668
    result = STX_ceilQ(myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   669
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   670
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   671
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   672
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   673
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   674
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   675
cos
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   676
    "return the cosine of the receiver (interpreted as radians)"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   677
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   678
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   679
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   680
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   681
    float256_t result, myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   682
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   683
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   684
    result = STX_cosQ(myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   685
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   686
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   687
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   688
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   689
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   690
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   691
cosh
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   692
    "return the hyperbolic cosine of the receiver (interpreted as radians)"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   693
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   694
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   695
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   696
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   697
    float256_t result, myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   698
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   699
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   700
    result = STX_coshQ(myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   701
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   702
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   703
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   704
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   705
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   706
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   707
exp
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   708
    "return e raised to the power of the receiver"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   709
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   710
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   711
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   712
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   713
    float256_t result, myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   714
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   715
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   716
    result = STX_expQ(myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   717
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   718
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   719
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   720
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   721
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   722
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   723
exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   724
    "extract a normalized float's (unbiased) exponent.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   725
     The returned value depends on the float-representation of
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   726
     the underlying machine and is therefore highly unportable.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   727
     This is not for general use.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   728
     This assumes that the mantissa is normalized to
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   729
     0.5 .. 1.0 and the float's value is: mantissa * 2^exp"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   730
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   731
%{  /* NOCONTEXT */
5287
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   732
#ifdef SUPPORT_OCTAFLOAT
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   733
    float256_t myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   734
    float256_t frac;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   735
    int exp;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   736
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   737
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
#if 1
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   739
    // should we?
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   740
    if (! (STX_isNanQ(&myVal) || STX_isInfQ(&myVal)))
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   741
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   742
    {
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   743
        frac = STX_frexpQ(myVal, &exp);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   744
        RETURN (__mkSmallInteger(exp));
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   745
    }
5287
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   746
#endif
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   747
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   748
    ^ super exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   749
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   750
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   751
     1.0 exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   752
     1.0 asOctaFloat exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   753
     2.0 exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   754
     2.0 asOctaFloat exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   755
     3.0 exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   756
     3.0 asOctaFloat exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   757
     4.0 exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   758
     4.0 asOctaFloat exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   759
     0.5 exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   760
     0.5 asOctaFloat exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   761
     0.4 exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   762
     0.4 asOctaFloat exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   763
     0.25 exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   764
     0.25 asOctaFloat exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   765
     0.2 exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   766
     0.2 asOctaFloat exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   767
     0.00000011111 exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   768
     0.00000011111 asOctaFloat exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   769
     0.0 exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   770
     0.0 asOctaFloat exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   771
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   772
     1e1000 exponent -> error (INF)
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   773
     1e1000 asOctaFloat exponent -> error (INF)
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   774
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   775
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   776
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   777
floor
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   778
    "return the integer nearest the receiver towards negative infinity."
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   779
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   780
    |val|
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   781
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   782
%{
5287
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   783
#ifdef SUPPORT_OCTAFLOAT
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   784
    float256_t qVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   785
    float256_t qMinInt;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   786
    float256_t qMaxInt;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   787
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   788
    qVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   789
    qVal = STX_floorQ(qVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   790
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   791
    qMinInt = STX_dbltoQ((double)_MIN_INT);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   792
    qMaxInt = STX_dbltoQ((double)_MAX_INT);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   793
    if (STX_geQ(qVal, qMinInt) && STX_leQ(qVal, qMaxInt)) {
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   794
	double dVal = STX_Qtodbl(qVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   795
	RETURN ( __mkSmallInteger( (INT) dVal ) );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   796
    }
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   797
    __qMKFLOAT256(val, qVal);
5287
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   798
#endif
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   799
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   800
    ^ val asInteger
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   801
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   802
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   803
     0.5 asOctaFloat floor
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   804
     0.5 asOctaFloat floorAsFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   805
     -0.5 asOctaFloat floor
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   806
     -0.5 asOctaFloat floorAsFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   807
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   808
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   809
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   810
floorAsFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
    "return the integer nearest the receiver towards negative infinity as a float.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   812
     This is much like #floor, but avoids a (possibly expensive) conversion
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   813
     of the result to an integer.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   814
     It may be useful, if the result is to be further used in another float-operation."
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   815
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   816
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   817
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   818
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   819
    float256_t result, myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   820
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   821
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   822
    result = STX_floorQ(myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   823
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   824
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   825
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   826
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   827
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   828
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   829
ln
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   830
    "return natural logarithm of the receiver."
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   831
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   832
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   833
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   834
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   835
    float256_t result, myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   836
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   837
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   838
    result = STX_logQ(myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   839
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   840
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   841
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   842
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   843
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   844
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   845
log
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   846
    "return log base 10 of the receiver.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   847
     Alias for log:10."
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   848
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   849
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   850
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   851
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   852
    float256_t result, myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   853
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   854
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   855
    result = STX_log10Q(myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   856
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   857
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   858
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   859
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   860
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   861
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   862
log2
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   863
    "return logarithm dualis of the receiver."
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   864
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   865
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   866
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   867
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   868
    float256_t result, myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   869
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   870
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   871
    result = STX_log2Q(myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   872
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   873
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   874
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   875
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   876
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   877
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   878
mantissa
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   879
    "extract a normalized float's mantissa.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   880
     The returned value depends on the float-representation of
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   881
     the underlying machine and is therefore highly unportable.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   882
     This is not for general use.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   883
     This assumes that the mantissa is normalized to
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   884
     0.5 .. 1.0 and the float's value is mantissa * 2^exp"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   885
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   886
%{  /* NOCONTEXT */
5287
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   887
#ifdef SUPPORT_OCTAFLOAT
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   888
    float256_t myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   889
    float256_t frac;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   890
    int exp;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   891
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   892
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   893
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   894
    // ouch: math libs seem to not care for NaN here;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   895
#if 1
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   896
    // should we?
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   897
    if (! (STX_isNanQ(&myVal) || STX_isInfQ(&myVal)))
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   898
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   899
    {
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   900
	frac = STX_frexpQ(myVal, &exp);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   901
	__qMKFLOAT256(newFloat, frac);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   902
	RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   903
    }
5287
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
   904
#endif
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   905
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   906
    ^ super mantissa
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   907
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   908
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   909
     1.0 exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   910
     1.0 asOctaFloat exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   911
     1.0 mantissa
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   912
     1.0 asOctaFloat mantissa
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   913
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   914
     0.25 exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   915
     0.25 asOctaFloat exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   916
     0.25 mantissa
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   917
     0.25 asOctaFloat mantissa
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   918
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   919
     0.00000011111 exponent
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   920
     0.00000011111 mantissa
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   921
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   922
     1e1000 mantissa
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   923
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   924
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   925
    "Modified: / 20-06-2017 / 11:37:13 / cg"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   926
    "Modified (comment): / 26-05-2019 / 03:12:55 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   927
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   928
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   929
negated
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   930
    "return the receiver negated"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   931
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   932
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   933
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   934
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   935
    float256_t result, myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   936
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   937
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   938
    result = STX_negQ(myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   939
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   940
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   941
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   942
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   943
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   944
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   945
rem: aNumber
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   946
    "return the floating point remainder of the receiver and the argument, aNumber"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   947
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   948
    aNumber isZero ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   949
	"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   950
	 No, you shalt not divide by zero
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   951
	"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   952
	^ ZeroDivide raiseRequestWith:thisContext.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   953
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   954
    ^ aNumber remainderFromLongFloat:self
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   955
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   956
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   957
sin
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   958
    "return the sine of the receiver (interpreted as radians)"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   959
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   960
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   961
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   962
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   963
    float256_t result, myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   964
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   965
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   966
    result = STX_sinQ(myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   967
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   968
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   969
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   970
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   971
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   972
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   973
sinh
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   974
    "return the hyperbolic sine of the receiver (interpreted as radians)"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   975
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   976
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   977
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   978
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   979
    float256_t result, myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   980
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   981
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   982
    result = STX_sinhQ(myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   983
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   984
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   985
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   986
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   987
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   988
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   989
tan
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   990
    "return the tangent of the receiver (interpreted as radians)"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   991
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   992
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   993
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   994
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   995
    float256_t result, myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   996
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   997
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   998
    result = STX_tanQ(myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   999
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1000
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1001
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1002
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1003
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1004
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1005
tanh
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1006
    "return the hyperbolic tangent of the receiver (interpreted as radians)"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1007
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1008
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1009
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1010
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1011
    float256_t result, myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1012
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1013
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1014
    result = STX_tanhQ(myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1015
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1016
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1017
#endif
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1018
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1019
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1020
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1021
!OctaFloat methodsFor:'coercing & converting'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1022
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1023
asFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1024
    "return a Float with same value as the receiver.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1025
     Raises an error if the receiver exceeds the float range."
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1026
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1027
%{  /* NOCONTEXT */
5287
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
  1028
#ifdef SUPPORT_OCTAFLOAT
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1029
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1030
    float256_t qVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1031
    double dVal = STX_qtodbl(qVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1032
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1033
    if (isfinite(dVal) || !STX_isfiniteQ(qVal)) {
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1034
	__qMKFLOAT(newFloat, dVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1035
	RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1036
    }
5287
16a42e9d5748 disabled (for now)
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
  1037
#endif
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1038
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1039
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1040
     value out of range
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1041
     if you need -INF for a zero receiver, try Number trapInfinity:[...]
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1042
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1043
    ^ self class
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1044
	raise:#infiniteResultSignal
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1045
	receiver:self
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1046
	selector:#asFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1047
	arguments:#()
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1048
	errorString:'receiver is out of the double-precision float range'
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1049
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1050
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1051
     1.0 asOctaFloat asFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1052
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1053
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1054
5327
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1055
asIEEEFloat
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1056
    "return an IEEE soft float with same value as receiver"
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1057
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1058
    ^ IEEEFloat fromFloat:self
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1059
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1060
    "
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1061
     123 asFloat asIEEEFloat
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1062
     0 asShortFloat asIEEEFloat
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1063
     0 asLongFloat asIEEEFloat
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1064
     0 asOctaFloat asIEEEFloat
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1065
     0.0 asIEEEFloat
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1066
    "
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1067
!
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1068
5294
dcfaed4ae26f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5289
diff changeset
  1069
asOctaFloat
dcfaed4ae26f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5289
diff changeset
  1070
    ^ self
dcfaed4ae26f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5289
diff changeset
  1071
dcfaed4ae26f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5289
diff changeset
  1072
    "
dcfaed4ae26f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5289
diff changeset
  1073
     1.0 asOctaFloat asOctaFloat
dcfaed4ae26f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5289
diff changeset
  1074
    "
dcfaed4ae26f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5289
diff changeset
  1075
!
dcfaed4ae26f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5289
diff changeset
  1076
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1077
generality
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1078
    "return the generality value - see ArithmeticValue>>retry:coercing:"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1079
5327
9cecf32b06e2 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5294
diff changeset
  1080
    ^ 96
5274
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1081
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1082
    "Created: / 07-06-2019 / 09:30:58 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1083
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1084
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1085
!OctaFloat methodsFor:'comparing'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1086
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1087
< aNumber
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1088
    "return true, if the argument is greater"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1089
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1090
    ^ aNumber lessFromOctaFloat:self
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1091
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1092
    "Created: / 07-06-2019 / 09:25:47 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1093
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1094
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1095
= aNumber
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1096
    "return true, if the argument represents the same numeric value
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1097
     as the receiver, false otherwise"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1098
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1099
    ^ aNumber equalFromOctaFloat:self
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1100
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1101
    "Created: / 07-06-2019 / 09:25:27 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1102
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1103
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1104
hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1105
    "return a number for hashing; redefined, since floats compare
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1106
     by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1107
     as 3 hash."
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1108
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1109
    |i|
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1110
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1111
    (self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1112
	i := self asInteger.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1113
	self = i ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1114
	    ^ i hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1115
	].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1116
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1117
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1118
    ^ self asFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1119
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1120
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1121
     1.2345 hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1122
     1.2345 asShortFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1123
     1.2345 asLongFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1124
     1.2345 asOctaFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1125
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1126
     1.0 hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1127
     1.0 asShortFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1128
     1.0 asLongFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1129
     1.0 asOctaFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1130
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1131
     0.5 asShortFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1132
     0.5 asShortFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1133
     0.5 asLongFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1134
     0.5 asOctaFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1135
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1136
     0.25 asShortFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1137
     0.25 asShortFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1138
     0.25 asLongFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1139
     0.25 asOctaFloat hash
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1140
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1141
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1142
    "Created: / 07-06-2019 / 09:28:07 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1143
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1144
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1145
!OctaFloat methodsFor:'double dispatching'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1146
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1147
differenceFromOctaFloat:aOctaFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1148
%{
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1149
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1150
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1151
    float256_t result, myVal, argVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1152
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1153
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1154
    argVal = __octaFloatVal(aOctaFloat);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1155
    result = STX_addQ( argVal, myVal, 1 );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1156
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1157
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1158
#endif // SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1159
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1160
    self errorUnsupported
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1161
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1162
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1163
equalFromOctaFloat:aOctaFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1164
    "sent when aOctaFloat does not know how to compare agaist the receiver, self"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1165
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1166
%{
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1167
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1168
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1169
    float256_t result, myVal, argVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1170
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1171
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1172
    argVal = __octaFloatVal(aOctaFloat);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1173
    RETURN (STX_eqQ(argVal, myVal) ? true : false);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1174
#endif // SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1175
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1176
    self errorUnsupported
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1177
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1178
    "Modified: / 08-06-2019 / 13:31:48 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1179
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1180
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1181
lessFromOctaFloat:aOctaFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1182
    "sent when aOctaFloat does not know how to compare agaist the receiver, self"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1183
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1184
%{
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1185
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1186
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1187
    float256_t result, myVal, argVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1188
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1189
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1190
    argVal = __octaFloatVal(aOctaFloat);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1191
    RETURN (STX_ltQ(argVal, myVal) ? true : false);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1192
#endif // SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1193
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1194
    self errorUnsupported
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1195
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1196
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1197
productFromOctaFloat:aOctaFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1198
    "sent when aOctaFloat does not know how to multiply the receiver, self"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1199
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1200
%{
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1201
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1202
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1203
    float256_t result, myVal, argVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1204
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1205
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1206
    argVal = __octaFloatVal(aOctaFloat);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1207
    result = STX_mulQ(myVal, argVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1208
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1209
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1210
#endif // SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1211
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1212
    self errorUnsupported
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1213
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1214
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1215
quotientFromOctaFloat:aOctaFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1216
    "sent when aOctaFloat does not know how to multiply the receiver, self"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1217
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1218
%{
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1219
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1220
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1221
    float256_t result, myVal, argVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1222
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1223
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1224
    argVal = __octaFloatVal(aOctaFloat);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1225
    result = STX_divQ(argVal, myVal);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1226
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1227
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1228
#endif // SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1229
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1230
    self errorUnsupported
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1231
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1232
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1233
sumFromOctaFloat:aOctaFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1234
    "sent when aOctaFloat does not know how to add the receiver, self"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1235
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1236
%{
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1237
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1238
    OBJ newFloat;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1239
    float256_t result, myVal, argVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1240
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1241
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1242
    argVal = __octaFloatVal(aOctaFloat);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1243
    result = STX_addQ( myVal, argVal, 0 );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1244
    __qMKFLOAT256(newFloat, result);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1245
    RETURN ( newFloat );
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1246
#endif // SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1247
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1248
    self errorUnsupported
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1249
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1250
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1251
!OctaFloat methodsFor:'error reportng'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1252
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1253
errorUnsupported
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1254
    self class errorUnsupported
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1255
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1256
    "Modified: / 07-06-2019 / 02:44:51 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1257
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1258
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1259
!OctaFloat methodsFor:'printing'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1260
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1261
printOn:aStream
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1262
    |mantissa exponent|
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1263
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1264
    mantissa := self mantissa.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1265
    exponent := self exponent.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1266
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1267
    self exponent == 0 ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1268
	mantissa printOn:aStream.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1269
	aStream nextPutAll:'.0'.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1270
	^ self
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1271
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1272
    mantissa == 0 ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1273
	"/ a zero mantissa is impossible - except for zero and a few others
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1274
	exponent == 0 ifTrue:[ aStream nextPutAll:'0.0'. ^ self].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1275
	self == NaN ifTrue:[ aStream nextPutAll:'NAN'. ^ self ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1276
	self == NegativeInfinity ifTrue:[ aStream nextPutAll:'-INF'. ^ self].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1277
	self == PositiveInfinity ifTrue:[ aStream nextPutAll:'INF'. ^ self].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1278
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1279
	self error:'invalid largeFloat' mayProceed:true.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1280
	aStream nextPutAll:'Invalid'. ^ self.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1281
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1282
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1283
    exponent >= 0 ifTrue:[
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1284
	(mantissa bitShift:exponent) printOn:aStream.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1285
	aStream nextPutAll:'.0'.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1286
	^ self
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1287
    ].
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1288
    ((mantissa / (1 bitShift:exponent negated)) asFixedPoint:6) printOn:aStream.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1289
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1290
    "Created: / 11-06-2019 / 00:13:00 / Claus Gittinger"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1291
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1292
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1293
!OctaFloat methodsFor:'queries'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1294
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1295
isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1296
    "return true, if the receiver is a finite float (not NaN and not +/-INF)"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1297
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1298
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1299
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1300
    float256_t myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1301
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1302
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1303
    RETURN (STX_isfiniteQ(myVal) ? true : false);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1304
#endif // SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1305
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1306
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1307
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1308
	1.0 isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1309
	self NaN isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1310
	self infinity isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1311
	self negativeInfinity isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1312
	(0.0 uncheckedDivide: 0.0) isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1313
	(1.0 uncheckedDivide: 0.0) isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1314
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1315
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1316
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1317
isInfinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1318
    "return true, if the receiver is an infinite float (+Inf or -Inf)."
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1319
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1320
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1321
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1322
    float256_t myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1323
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1324
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1325
    RETURN (STX_isInfQ(&myVal) ? true : false);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1326
#endif // SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1327
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1328
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1329
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1330
	1.0 asOctaFloat isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1331
	1.0 asOctaFloat isInfinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1332
	self NaN isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1333
	self NaN isInfinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1334
	self infinity isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1335
	self infinity isInfinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1336
	self negativeInfinity isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1337
	self negativeInfinity isInfinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1338
	(0.0 uncheckedDivide: 0.0) isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1339
	(1.0 uncheckedDivide: 0.0) isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1340
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1341
!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1342
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1343
isNaN
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1344
    "return true, if the receiver is an invalid float (NaN - not a number).
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1345
     These are not created by ST/X float operations (they raise an exception);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1346
     however, inline C-code could produce them."
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1347
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1348
%{  /* NOCONTEXT */
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1349
#ifdef SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1350
    float256_t myVal;
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1351
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1352
    myVal = __octaFloatVal(self);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1353
    RETURN (STX_isNanQ(&myVal) ? true : false);
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1354
#endif // SUPPORT_OCTAFLOAT
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1355
%}.
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1356
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1357
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1358
	1.0 asOctaFloat isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1359
	self NaN isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1360
	self infinity isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1361
	(0.0 uncheckedDivide: 0.0) isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1362
	(1.0 uncheckedDivide: 0.0) isFinite
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1363
    "
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1364
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1365
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1366
!OctaFloat methodsFor:'testing'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1367
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1368
isOctaFloat
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1369
    "return true, if the receiver is some kind of quad floating point number (iee quad precision)"
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1370
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1371
    ^ true
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1372
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1373
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1374
!OctaFloat class methodsFor:'documentation'!
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1375
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1376
version_CVS
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1377
    ^ '$Header$'
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1378
! !
635e877a7fee initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1379