QDouble.st
author Claus Gittinger <cg@exept.de>
Tue, 20 Jun 2017 12:22:56 +0200
changeset 4430 2abefbc21260
parent 4427 15d052db3e6e
child 4431 a7e1399f418e
permissions -rw-r--r--
#BUGFIX by cg class: QDouble added: #asTrueFraction #exponent class: QDouble class comment/format in: #documentation #numBitsInMantissa #precision
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2017 by eXept Software AG
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
     3
	      All Rights Reserved
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ NameSpace: Smalltalk }"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
LimitedPrecisionReal variableByteSubclass:#QDouble
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:''
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
    18
	classVariableNames:'DefaultPrintFormat E Epsilon FMax FMin InvFact Ln10 Ln2 Pi
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
    19
		QDoubleOne QDoubleZero'
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	poolDictionaries:''
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	category:'Magnitude-Numbers'
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!QDouble primitiveDefinitions!
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    25
%{
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    26
#include <stdio.h>
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    27
#include <errno.h>
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    28
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    29
#define __USE_ISOC9X 1
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    30
#define __USE_ISOC99 1
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    31
#include <math.h>
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    32
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    33
/*
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    34
 * on some systems, errno is a macro ... check for it here
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    35
 */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    36
#ifndef errno
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    37
 extern errno;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    38
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    39
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    40
#if !defined (__win32__)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    41
# include <locale.h>
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    42
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    43
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    44
#if defined (__aix__)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    45
# include <float.h>
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    46
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    47
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    48
#if defined(__irix__) || defined(__solaris__) || defined(__sunos__)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    49
# include <nan.h>
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    50
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    51
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    52
#if defined(__linux__)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    53
# ifndef NAN
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    54
#  include <bits/nan.h>
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    55
# endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    56
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    57
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    58
#ifdef __win32__
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    59
# ifndef isinf
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    60
#  define isinf(x) \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    61
	((((unsigned int *)(&x))[0] == 0x00000000) && \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    62
	 ((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000))
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    63
# endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    64
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    65
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    66
#if defined(__x86__) || defined(__x86_64__)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    67
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    68
# ifndef _FPU_EXTENDED
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    69
#  define _FPU_EXTENDED 0x0300
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    70
# endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    71
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    72
# ifndef _FPU_DOUBLE
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    73
#  define _FPU_DOUBLE 0x0200
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    74
# endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    75
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    76
# if defined( __win32__ ) && (defined( __BORLANDC__ ) || defined( __VISUALC__ ))
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    77
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    78
#  define fpu_fix_start(old_cw_ptr)\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    79
    {\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    80
	*old_cw_ptr = _control87(0, 0); \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    81
	_control87(_FPU_DOUBLE, _FPU_EXTENDED);\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    82
    }
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    83
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    84
#  define fpu_fix_end(old_cw_ptr)\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    85
    {\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    86
	_control87(*old_cw_ptr, _FPU_EXTENDED);\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    87
    }
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    88
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    89
# else // assume MINGW, GCC or CLANG
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    90
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    91
#  ifndef _FPU_GETCW
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    92
#   define _FPU_GETCW(x) asm volatile ("fnstcw %0":"=m" (x));
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    93
#  endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    94
#  ifndef _FPU_SETCW
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    95
#   define _FPU_SETCW(x) asm volatile ("fldcw %0": :"m" (x));
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    96
#  endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    97
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    98
#  define fpu_fix_start(old_cw_ptr)\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    99
    {\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   100
	volatile unsigned short cw, new_cw;\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   101
	_FPU_GETCW(cw);\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   102
	new_cw = (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE;\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   103
	_FPU_SETCW(new_cw);\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   104
	*old_cw_ptr = cw;\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   105
    }
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   106
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   107
#  define fpu_fix_end(old_cw_ptr)\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   108
    {\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   109
	volatile unsigned short cw = *old_cw_ptr;\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   110
	_FPU_SETCW(cw);\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   111
    }
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   112
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   113
# endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   114
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   115
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   116
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   117
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   118
struct qd_real {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   119
    double x[4];    /* The Components. */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   120
};
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   121
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   122
struct __quadDoubleStruct {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   123
	STX_OBJ_HEADER
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   124
#ifdef __NEED_DOUBLE_ALIGN
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   125
	__FILLTYPE_DOUBLE f_filler;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   126
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   127
	double d_quadDoubleValue[4];
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   128
};
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   129
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   130
#define __QuadDoubleInstPtr(obj)      ((struct __quadDoubleStruct *)(__objPtr(obj)))
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   131
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   132
#ifndef __isQuadDouble
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   133
# define __isQuadDouble(o) \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   134
	(__Class(o) == @global(QuadDouble))
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   135
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   136
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   137
#ifndef __qIsQuadDouble
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   138
# define __qIsQuadDouble(o) \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   139
	(__qClass(o) == @global(QuadDouble))
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   140
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   141
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   142
#define __qNew_qdReal(newQD, d0,d1,d2,d3) { \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   143
    __qNew(newQD, sizeof(struct __quadDoubleStruct)); \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   144
    __stx_setClass(newQD, QDouble);                \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   145
    __QuadDoubleInstPtr(newQD)->d_quadDoubleValue[0] = d0;   \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   146
    __QuadDoubleInstPtr(newQD)->d_quadDoubleValue[1] = d1;   \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   147
    __QuadDoubleInstPtr(newQD)->d_quadDoubleValue[2] = d2;   \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   148
    __QuadDoubleInstPtr(newQD)->d_quadDoubleValue[3] = d3;   \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   149
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   150
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   151
// sigh: not all compilers (borland) support inline functions;
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   152
// therefore we have to use macros...
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   153
// sigh2: c-macros are unhygienic - to avoid catching/hiding variable bindings,
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   154
// use different names in each macros (i.e. a_xxx)
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   155
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   156
// qd_real(c0, c1, c2, c3);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   157
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   158
#define _QD_SPLITTER 134217729.0               // = 2^27 + 1
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   159
#define _QD_SPLIT_THRESH 6.69692879491417e+299 // = 2^996
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   160
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   161
#define m_quick_two_sum(rslt_1, a_1, b_1, err_1)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   162
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   163
    double s_1 = (a_1) + (b_1);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   164
    (err_1) = (b_1) - (s_1 - (a_1));\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   165
    (rslt_1) = s_1; \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   166
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   167
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   168
#define m_quick_two_diff(rslt_2, a_2, b_2, err_2)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   169
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   170
    double s_2 = (a_2) - (b_2);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   171
    (err_2) = ((a_2) - s_2) - (b_2);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   172
    (rslt_2) = s_2;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   173
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   174
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   175
#define m_two_sum(rslt_3, a_3, b_3, err_3)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   176
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   177
    double s_3 = a_3 + b_3;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   178
    double bb_3 = s_3 - a_3;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   179
    err_3 = (a_3 - (s_3 - bb_3)) + (b_3 - bb_3);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   180
    rslt_3 = s_3;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   181
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   182
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   183
/* Computes fl(a-b) and err(a-b).  */
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   184
#define m_two_diff(rslt_4, a_4, b_4, err_4)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   185
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   186
    double s_4 = a_4 - b_4;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   187
    double bb_4 = s_4 - a_4;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   188
    err_4 = (a_4 - (s_4 - bb_4)) - (b_4 + bb_4);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   189
    rslt_4 = s_4;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   190
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   191
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   192
#define m_three_sum(a_5, b_5, c_5)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   193
{ \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   194
    double t1_5, t2_5, t3_5; \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   195
    m_two_sum(t1_5, a_5, b_5, t2_5); \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   196
    m_two_sum(a_5, c_5, t1_5, t3_5); \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   197
    m_two_sum(b_5, t2_5, t3_5, c_5); \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   198
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   199
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   200
#define m_three_sum2(a_6, b_6, c_6)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   201
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   202
    double t1_6, t2_6, t3_6;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   203
    m_two_sum(t1_6, a_6, b_6, t2_6);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   204
    m_two_sum(a_6, c_6, t1_6, t3_6);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   205
    b_6 = t2_6 + t3_6;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   206
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   207
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   208
#ifndef QD_FMS
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   209
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   210
/* Computes high word and lo word of a */
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   211
#define m_split(a_7, hi_7, lo_7)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   212
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   213
    double temp_7;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   214
    if (a_7 > _QD_SPLIT_THRESH || a_7 < -_QD_SPLIT_THRESH) {\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   215
	a_7 *= 3.7252902984619140625e-09;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   216
	temp_7 = _QD_SPLITTER * a_7;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   217
	hi_7 = temp_7 - (temp_7 - a_7);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   218
	lo_7 = a_7 - hi_7;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   219
	hi_7 *= 268435456.0;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   220
	lo_7 *= 268435456.0;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   221
    } else {\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   222
	temp_7 = _QD_SPLITTER * a_7;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   223
	hi_7 = temp_7 - (temp_7 - a_7);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   224
	lo_7 = a_7 - hi_7;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   225
    }\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   226
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   227
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   228
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   229
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   230
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   231
#ifdef QD_FMS
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   232
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   233
/* Computes fl(a*b) and err(a*b). */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   234
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   235
#define m_two_prod(rslt_8, a_8, b_8, err_8)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   236
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   237
    double p_8 = a_8 * b_8;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   238
    err_8 = QD_FMS(a_8, b_8, p_8);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   239
    rslt_8 = p_8; \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   240
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   241
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   242
#else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   243
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   244
#define m_two_prod(rslt_8, a_8, b_8, err_8)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   245
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   246
    double a_hi_8, a_lo_8, b_hi_8, b_lo_8;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   247
    double p_8 = a_8 * b_8;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   248
    m_split(a_8, a_hi_8, a_lo_8);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   249
    m_split(b_8, b_hi_8, b_lo_8);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   250
    err_8 = ((a_hi_8 * b_hi_8 - p_8) + a_hi_8 * b_lo_8 + a_lo_8 * b_hi_8) + a_lo_8 * b_lo_8;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   251
    rslt_8 = p_8; \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   252
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   253
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   254
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   255
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   256
#ifdef QD_FMS
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   257
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   258
#define m_two_sqr(rslt_9, a_9, err_9)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   259
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   260
    double p_9 = a_9 * a_9;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   261
    err_9 = QD_FMS(a_9, a_9, p_9);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   262
    rslt_9 = p_9;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   263
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   264
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   265
#else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   266
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   267
#define m_two_sqr(rslt_9, a_9, err_9)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   268
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   269
    double hi_9, lo_9;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   270
    double q_9 = a_9 * a_9;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   271
    m_split(a_9, hi_9, lo_9);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   272
    err_9 = ((hi_9 * hi_9 - q_9) + 2.0 * hi_9 * lo_9) + lo_9 * lo_9;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   273
    rslt_9 = q_9;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   274
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   275
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   276
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   277
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   278
#define m_renorm4(c0_10, c1_10, c2_10, c3_10)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   279
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   280
    double s0_10, s1_10, s2_10 = 0.0, s3_10 = 0.0;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   281
\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   282
    if (! isinf(c0_10)) { \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   283
\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   284
	m_quick_two_sum(s0_10, c2_10, c3_10, c3_10);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   285
	m_quick_two_sum(s0_10, c1_10, s0_10, c2_10);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   286
	m_quick_two_sum(c0_10, c0_10, s0_10, c1_10);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   287
\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   288
	s0_10 = c0_10;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   289
	s1_10 = c1_10;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   290
	if (s1_10 != 0.0) {\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   291
	     m_quick_two_sum(s1_10, s1_10, c2_10, s2_10);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   292
	    if (s2_10 != 0.0) {\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   293
		 m_quick_two_sum(s2_10, s2_10, c3_10, s3_10);\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   294
	    } else {\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   295
		 m_quick_two_sum(s1_10, s1_10, c3_10, s2_10);\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   296
	    }\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   297
	} else {\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   298
	    m_quick_two_sum(s0_10, s0_10, c2_10, s1_10);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   299
	    if (s1_10 != 0.0) {\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   300
		 m_quick_two_sum(s1_10, s1_10, c3_10, s2_10);\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   301
	    } else {\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   302
		 m_quick_two_sum(s0_10, s0_10, c3_10, s1_10);\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   303
	    }\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   304
	}\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   305
\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   306
	c0_10 = s0_10;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   307
	c1_10 = s1_10;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   308
	c2_10 = s2_10;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   309
	c3_10 = s3_10;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   310
    }\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   311
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   312
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   313
#define m_renorm5(c0_11, c1_11, c2_11, c3_11, c4_11)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   314
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   315
    double s0_11, s1_11, s2_11 = 0.0, s3_11 = 0.0; \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   316
\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   317
    if (! isinf(c0_11)) { \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   318
	m_quick_two_sum(s0_11, c3_11, c4_11, c4_11); \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   319
	m_quick_two_sum(s0_11, c2_11, s0_11, c3_11); \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   320
	m_quick_two_sum(s0_11, c1_11, s0_11, c2_11); \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   321
	m_quick_two_sum(c0_11, c0_11, s0_11, c1_11); \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   322
\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   323
	s0_11 = c0_11; \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   324
	s1_11 = c1_11; \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   325
\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   326
	m_quick_two_sum(s0_11, c0_11, c1_11, s1_11); \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   327
	if (s1_11 != 0.0) { \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   328
	    m_quick_two_sum(s1_11, s1_11, c2_11, s2_11); \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   329
	    if (s2_11 != 0.0) { \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   330
		m_quick_two_sum(s2_11 ,s2_11, c3_11, s3_11); \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   331
		if (s3_11 != 0.0) {\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   332
		    s3_11 += c4_11; \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   333
		} else {\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   334
		    s2_11 += c4_11;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   335
		}\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   336
	    } else { \
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   337
		m_quick_two_sum(s1_11, s1_11, c3_11, s2_11); \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   338
		if (s2_11 != 0.0) {\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   339
		    m_quick_two_sum(s2_11, s2_11, c4_11, s3_11); \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   340
		} else { \
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   341
		    m_quick_two_sum(s1_11, s1_11, c4_11, s2_11); \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   342
		} \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   343
	    } \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   344
	} else { \
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   345
	    m_quick_two_sum(s0_11,s0_11, c2_11, s1_11); \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   346
	    if (s1_11 != 0.0) { \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   347
		m_quick_two_sum(s1_11,s1_11, c3_11, s2_11); \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   348
		if (s2_11 != 0.0) {\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   349
		    m_quick_two_sum(s2_11,s2_11, c4_11, s3_11); \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   350
		} else { \
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   351
		    m_quick_two_sum(s1_11 ,s1_11, c4_11, s2_11); \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   352
		} \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   353
	    } else { \
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   354
		m_quick_two_sum(s0_11,s0_11, c3_11, s1_11); \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   355
		if (s1_11 != 0.0) { \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   356
		    m_quick_two_sum(s1_11,s1_11, c4_11, s2_11); \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   357
		} else { \
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   358
		    m_quick_two_sum(s0_11,s0_11, c4_11, s1_11); \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   359
		} \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   360
	    } \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   361
	} \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   362
 \
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   363
	c0_11 = s0_11; \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   364
	c1_11 = s1_11; \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   365
	c2_11 = s2_11; \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   366
	c3_11 = s3_11; \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   367
    } \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   368
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   369
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   370
%}
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
!QDouble primitiveFunctions!
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   374
%{
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   375
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   376
#if 0
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   377
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   378
/*********** Basic Functions ************/
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   379
/* Computes fl(a+b) and err(a+b).  Assumes |a| >= |b|. */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   380
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   381
quick_two_sum(double a, double b, double *errPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   382
  double s = a + b;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   383
  *errPtr = b - (s - a);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   384
  return s;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   385
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   386
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   387
/* Computes fl(a-b) and err(a-b).  Assumes |a| >= |b| */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   388
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   389
quick_two_diff(double a, double b, double *errPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   390
  double s = a - b;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   391
  *errPtr = (a - s) - b;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   392
  return s;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   393
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   394
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   395
/* Computes fl(a+b) and err(a+b).  */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   396
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   397
two_sum(double a, double b, double *errPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   398
  double s = a + b;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   399
  double bb = s - a;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   400
  *errPtr = (a - (s - bb)) + (b - bb);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   401
  return s;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   402
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   403
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   404
/* Computes fl(a-b) and err(a-b).  */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   405
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   406
two_diff(double a, double b, double *errPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   407
  double s = a - b;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   408
  double bb = s - a;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   409
  *errPtr = (a - (s - bb)) - (b + bb);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   410
  return s;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   411
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   412
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   413
#ifndef QD_FMS
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   414
/* Computes high word and lo word of a */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   415
inline void
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   416
split(double a, double *hiPtr, double *loPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   417
  double temp;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   418
  if (a > _QD_SPLIT_THRESH || a < -_QD_SPLIT_THRESH) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   419
    a *= 3.7252902984619140625e-09;  // 2^-28
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   420
    temp = _QD_SPLITTER * a;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   421
    *hiPtr = temp - (temp - a);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   422
    *loPtr = a - *hiPtr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   423
    *hiPtr *= 268435456.0;          // 2^28
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   424
    *loPtr *= 268435456.0;          // 2^28
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   425
  } else {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   426
    temp = _QD_SPLITTER * a;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   427
    *hiPtr = temp - (temp - a);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   428
    *loPtr = a - *hiPtr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   429
  }
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   430
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   431
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   432
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   433
/* Computes fl(a*b) and err(a*b). */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   434
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   435
two_prod(double a, double b, double *errPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   436
#ifdef QD_FMS
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   437
  double p = a * b;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   438
  *errPtr = QD_FMS(a, b, p);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   439
  return p;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   440
#else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   441
  double a_hi, a_lo, b_hi, b_lo;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   442
  double p = a * b;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   443
  split(a, &a_hi, &a_lo);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   444
  split(b, &b_hi, &b_lo);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   445
  *errPtr = ((a_hi * b_hi - p) + a_hi * b_lo + a_lo * b_hi) + a_lo * b_lo;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   446
  return p;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   447
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   448
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   449
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   450
/* Computes fl(a*a) and err(a*a).  Faster than the above method. */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   451
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   452
two_sqr(double a, double *errPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   453
#ifdef QD_FMS
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   454
  double p = a * a;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   455
  *errPtr = QD_FMS(a, a, p);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   456
  return p;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   457
#else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   458
  double hi, lo;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   459
  double q = a * a;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   460
  split(a, &hi, &lo);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   461
  *errPtr = ((hi * hi - q) + 2.0 * hi * lo) + lo * lo;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   462
  return q;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   463
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   464
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   465
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   466
/* Computes the nearest integer to d. */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   467
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   468
nint(double d) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   469
  if (d == floor(d))
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   470
    return d;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   471
  return floor(d + 0.5);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   472
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   473
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   474
/* Computes the truncated integer. */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   475
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   476
aint(double d) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   477
  return (d >= 0.0) ? floor(d) : ceil(d);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   478
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   479
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   480
inline void
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   481
renorm4(double *c0Ptr, double *c1Ptr, double *c2Ptr, double *c3Ptr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   482
  double s0, s1, s2 = 0.0, s3 = 0.0;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   483
  double c0 = *c0Ptr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   484
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   485
  if (isinf(c0)) return;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   486
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   487
  s0 = quick_two_sum(*c2Ptr, *c3Ptr, c3Ptr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   488
  s0 = quick_two_sum(*c1Ptr, s0, c2Ptr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   489
  c0 = quick_two_sum(c0, s0, c1Ptr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   490
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   491
  s0 = c0;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   492
  s1 = *c1Ptr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   493
  if (s1 != 0.0) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   494
    s1 = quick_two_sum(s1, *c2Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   495
    if (s2 != 0.0)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   496
      s2 = quick_two_sum(s2, *c3Ptr, &s3);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   497
    else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   498
      s1 = quick_two_sum(s1, *c3Ptr, &s2);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
  } else {
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
    s0 = quick_two_sum(s0, *c2Ptr, &s1);
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   501
    if (s1 != 0.0)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   502
      s1 = quick_two_sum(s1, *c3Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   503
    else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   504
      s0 = quick_two_sum(s0, *c3Ptr, &s1);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   505
  }
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   506
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   507
  *c0Ptr = s0;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   508
  *c1Ptr = s1;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   509
  *c2Ptr = s2;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   510
  *c3Ptr = s3;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   511
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   512
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   513
inline void
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   514
renorm5(double *c0Ptr, double *c1Ptr, double *c2Ptr, double *c3Ptr, double *c4Ptr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   515
  double s0, s1, s2 = 0.0, s3 = 0.0;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   516
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   517
  if (isinf(*c0Ptr)) return;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   518
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   519
  s0 = quick_two_sum(*c3Ptr, *c4Ptr, c4Ptr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   520
  s0 = quick_two_sum(*c2Ptr, s0, c3Ptr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   521
  s0 = quick_two_sum(*c1Ptr, s0, c2Ptr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   522
  *c0Ptr = quick_two_sum(*c0Ptr, s0, c1Ptr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   523
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   524
  s0 = *c0Ptr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   525
  s1 = *c1Ptr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   526
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   527
  s0 = quick_two_sum(*c0Ptr, *c1Ptr, &s1);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   528
  if (s1 != 0.0) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   529
    s1 = quick_two_sum(s1, *c2Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   530
    if (s2 != 0.0) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   531
      s2 =quick_two_sum(s2, *c3Ptr, &s3);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   532
      if (s3 != 0.0)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   533
	s3 += *c4Ptr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   534
      else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   535
	s2 += *c4Ptr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   536
    } else {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   537
      s1 = quick_two_sum(s1, *c3Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   538
      if (s2 != 0.0)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   539
	s2 = quick_two_sum(s2, *c4Ptr, &s3);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   540
      else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   541
	s1 = quick_two_sum(s1, *c4Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   542
    }
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   543
  } else {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   544
    s0 = quick_two_sum(s0, *c2Ptr, &s1);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   545
    if (s1 != 0.0) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   546
      s1 = quick_two_sum(s1, *c3Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   547
      if (s2 != 0.0)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   548
	s2 = quick_two_sum(s2, *c4Ptr, &s3);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   549
      else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   550
	s1 = quick_two_sum(s1, *c4Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   551
    } else {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   552
      s0 = quick_two_sum(s0, *c3Ptr, &s1);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   553
      if (s1 != 0.0)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   554
	s1 = quick_two_sum(s1, *c4Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   555
      else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   556
	s0 = quick_two_sum(s0, *c4Ptr, &s1);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   557
    }
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   558
  }
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   559
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   560
  *c0Ptr = s0;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   561
  *c1Ptr = s1;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   562
  *c2Ptr = s2;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   563
  *c3Ptr = s3;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   564
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   565
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   566
inline void
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   567
three_sum(double *aPtr, double *bPtr, double *cPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   568
  double t1, t2, t3;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   569
  t1 = two_sum(*aPtr, *bPtr, &t2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   570
  *aPtr  = two_sum(*cPtr, t1, &t3);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   571
  *bPtr  = two_sum(t2, t3, cPtr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   572
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   573
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   574
inline void three_sum2(double *aPtr, double *bPtr, double *cPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   575
  double t1, t2, t3;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   576
  t1 = two_sum(*aPtr, *bPtr, &t2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   577
  *aPtr  = two_sum(*cPtr, t1, &t3);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   578
  *bPtr = t2 + t3;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   579
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   580
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   581
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   582
#if 0
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   583
/* These are provided to give consistent
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   584
   interface for double with double-double and quad-double. */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   585
inline void
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   586
sincosh(double t, double &sinh_t, double &cosh_t) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   587
  sinh_t = sinh(t);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   588
  cosh_t = cosh(t);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   589
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   590
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   591
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   592
sqr(double t) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   593
  return t * t;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   594
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   595
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   596
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   597
to_double(double a) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   598
    return a;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   599
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   600
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   601
inline int
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   602
to_int(double a)    {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   603
    return static_cast<int>(a);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   604
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   605
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   606
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   607
%}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   608
! !
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   609
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   610
!QDouble class methodsFor:'documentation'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   611
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   612
copyright
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   613
"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   614
 COPYRIGHT (c) 2017 by eXept Software AG
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   615
	      All Rights Reserved
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   616
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   617
 This software is furnished under a license and may be used
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   618
 only in accordance with the terms of that license and with the
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   619
 inclusion of the above copyright notice.   This software may not
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   620
 be provided or otherwise made available to, or used by, any
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   621
 other person.  No title to or ownership of the software is
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   622
 hereby transferred.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   624
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   625
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   626
documentation
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   627
"
4391
f2ece85e1ae3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
   628
    ATTENTION: ongoing, unfinished work.
f2ece85e1ae3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
   629
    This does not work correctly at the moment.
f2ece85e1ae3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
   630
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   631
    QDoubles represent rational numbers with extended, but still limited precision.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   632
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   633
    In contrast to Floats (which use the C-compilers native 64bit 'double' format),
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
   634
    QDoubles give you roughly 200 bit or approx. 60 decimal digits of precision.
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   635
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   636
    Representation:
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
   637
        QDoubles use 4 IEEE doubles, each keeping 53 bits of precision.
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
   638
        The qDouble's value is the sum of those 4 doubles, 
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
   639
        and a qDouble keeps this unevaluated sum as its state.
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
   640
        (due to overlap, the final precision is less than 53*4)
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   641
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   642
    Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
   643
        Float decimalPrecision
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
   644
        QDouble decimalPrecision
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
   645
        QDouble precision
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   646
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   647
    [author:]
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
   648
        Claus Gittinger
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   650
    [see also:]
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
   651
        Number
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
   652
        Float ShortFloat LongFloat 
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
   653
        Fraction FixedPoint Integer Complex
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
   654
        FloatArray DoubleArray
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   655
"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   656
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   657
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   658
!QDouble class methodsFor:'instance creation'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   659
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   660
basicNew
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   661
    "return a new quad-precision double - here we return 0.0
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   662
     Notice that numbers are usually NOT created this way ...
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   663
     It's implemented here to allow things like binary store & load
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   664
     of floats. (but even this support will go away eventually, it's not
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   665
     a good idea to store the bits of a float - the reader might have a
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   666
     totally different representation - so floats should be
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   667
     binary stored in a device independent format."
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   668
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   669
%{  /* NOCONTEXT */
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   670
#ifdef __SCHTEAM__
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   671
    ERROR("trying to instantiate a quad double");
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   672
#else
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   673
    OBJ newFloat;
4404
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
   674
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   675
    __qNew(newFloat, sizeof(struct __quadDoubleStruct));
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   676
    __stx_setClass(newFloat, QDouble);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   677
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[0] = 0.0;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   678
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[1] = 0.0;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   679
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[2] = 0.0;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   680
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[3] = 0.0;
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   681
    RETURN (newFloat);
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   682
#endif /* not SCHTEAM */
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   683
%}
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   684
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   685
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   686
     self basicNew
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   687
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   688
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   689
    "Created: / 12-06-2017 / 16:00:38 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   690
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   691
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   692
d0:d0 d1:d1 d2:d2 d3:d3
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   693
    "return a new quad-precision double from individual double components"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   694
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   695
%{  /* NOCONTEXT */
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   696
#ifdef __SCHTEAM__
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   697
    ERROR("trying to instantiate a quad double");
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   698
#else
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   699
    OBJ newQD;
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   700
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   701
    if (__isFloatLike(d0)
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   702
     && __isFloatLike(d1)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   703
     && __isFloatLike(d2)
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   704
     && __isFloatLike(d3)) {
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   705
	__qNew_qdReal(newQD, __floatVal(d0), __floatVal(d1),
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   706
			     __floatVal(d2), __floatVal(d3));
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   707
	RETURN (newQD);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   708
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   709
#endif
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   710
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   711
    self error:'invalid argument'
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   712
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   713
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   714
     self d0: 3.141592653589793116e+00
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   715
	  d1: 1.224646799147353207e-16
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   716
	  d2: -2.994769809718339666e-33
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   717
	  d3: 1.112454220863365282e-49
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   718
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   719
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   720
    "Created: / 12-06-2017 / 20:17:14 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   721
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   722
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   723
fromDoubleArray:aDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   724
    "return a new quad-precision double from coercing a double array"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   725
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   726
%{  /* NOCONTEXT */
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   727
#ifdef __SCHTEAM__
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   728
    ERROR("trying to instantiate a quad double");
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   729
#else
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   730
    OBJ newQD;
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   731
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   732
    if (__isDoubleArray(aDoubleArray)) {
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   733
	__qNew_qdReal(newQD,
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   734
		    __DoubleArrayInstPtr(aDoubleArray)->d_element[0],
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   735
		    __DoubleArrayInstPtr(aDoubleArray)->d_element[1],
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   736
		    __DoubleArrayInstPtr(aDoubleArray)->d_element[2],
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   737
		    __DoubleArrayInstPtr(aDoubleArray)->d_element[3]);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   738
	RETURN (newQD);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   739
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   740
#endif
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   741
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   742
    self error:'invalid argument'
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   743
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   744
    "
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   745
     self fromDoubleArray(DoubleArray
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   746
				with: 3.141592653589793116e+00
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   747
				with: 1.224646799147353207e-16
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   748
				with: -2.994769809718339666e-33
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   749
				with: 1.112454220863365282e-49)
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   750
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   751
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   752
    "Created: / 12-06-2017 / 18:25:32 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   753
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   754
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   755
fromFloat:aFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   756
    "return a new quad-precision double from coercing aFloat"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   757
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   758
%{  /* NOCONTEXT */
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   759
#ifdef __SCHTEAM__
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   760
    ERROR("trying to instantiate a quad double");
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   761
#else
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   762
    double dVal;
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   763
    OBJ newFloat;
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   764
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   765
    if (__isFloatLike(aFloat)) {
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   766
	dVal = __floatVal(aFloat);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   767
    } else if (__isShortFloat(aFloat)) {
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   768
	dVal = __shortFloatVal(aFloat);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   769
    } else {
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   770
	goto badArg;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   771
    }
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   772
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   773
    __qNew(newFloat, sizeof(struct __quadDoubleStruct));
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   774
    __stx_setClass(newFloat, QDouble);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   775
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[0] = dVal;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   776
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[1] = 0.0;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   777
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[2] = 0.0;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   778
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[3] = 0.0;
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   779
    RETURN (newFloat);
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   780
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   781
badArg: ;
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   782
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   783
#endif
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   784
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   785
    self error:'invalid argument'
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   786
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   787
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   788
     self fromFloat:1.0
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   789
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   790
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   791
    "Created: / 12-06-2017 / 16:06:54 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   792
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   793
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   794
fromInteger:anInteger
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   795
    "return a new quad-precision double from coercing anInteger"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   796
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   797
%{  /* NOCONTEXT */
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   798
#ifndef __SCHTEAM__
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   799
    OBJ newFloat;
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   800
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   801
    if (__isSmallInteger(anInteger)) {
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   802
	__qNew(newFloat, sizeof(struct __quadDoubleStruct));
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   803
	__stx_setClass(newFloat, QDouble);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   804
	__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[0] = (double)(__smallIntegerVal(anInteger));
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   805
	__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[1] = 0.0;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   806
	__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[2] = 0.0;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   807
	__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[3] = 0.0;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   808
	RETURN (newFloat);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   809
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   810
#endif
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   812
    ^ super fromInteger:anInteger
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   813
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   814
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   815
     self fromInteger:2
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   816
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   817
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   818
    "Created: / 12-06-2017 / 16:10:10 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   819
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   820
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   821
!QDouble class methodsFor:'coercing & converting'!
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   822
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   823
coerce:aNumber
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   824
    "convert the argument aNumber into an instance of the receiver's class and return it."
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   825
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   826
    ^ aNumber asQDouble
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   827
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   828
    "Created: / 12-06-2017 / 17:13:47 / cg"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   829
    "Modified: / 12-06-2017 / 21:09:06 / cg"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   830
! !
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   831
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   832
!QDouble class methodsFor:'constants'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   833
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   834
e
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   835
    "return the constant e as quad precision double.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   836
     (returns approx. 212 bits of precision)"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   837
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   838
    E isNil ifTrue:[
4388
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   839
	E := self fromDoubleArray:(DoubleArray
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   840
				    with: 2.718281828459045091e+00
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   841
				    with: 1.445646891729250158e-16
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   842
				    with: -2.127717108038176765e-33
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   843
				    with: 1.515630159841218954e-49)
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   844
    ].
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   845
    ^ E
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   846
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   847
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   848
     self e
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   849
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   850
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   851
    "Created: / 12-06-2017 / 18:29:36 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   852
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   853
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   854
fmax
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   855
    "return the constant e as quad precision double.
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   856
     (returns approx. 212 bits of precision)"
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   857
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   858
    FMax isNil ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   859
	FMax := self fromDoubleArray:(DoubleArray
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   860
				    with: 1.797693134862314E+308
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   861
				    with: 9.97920154767359795037e+291
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   862
				    with: 5.53956966280111259858e+275
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   863
				    with: 3.07507889307840487279e+259)
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   864
    ].
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   865
    ^ FMax
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   866
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   867
    "
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   868
     Float fmax
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   869
     self fmax
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   870
    "
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   871
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   872
    "Created: / 14-06-2017 / 19:14:18 / cg"
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   873
!
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   874
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   875
fmin
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   876
    "return the smallest representable instance of this class"
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   877
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   878
    FMin isNil ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   879
	FMin := 1.6259745436952323e-260 asQDouble
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   880
    ].
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   881
    ^ FMin
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   882
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   883
    "
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   884
     QDouble fmin
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   885
     Float fmin
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   886
    "
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   887
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   888
    "Created: / 14-06-2017 / 19:14:49 / cg"
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   889
!
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   890
4411
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   891
infinity
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   892
    ^ Infinity positive
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   893
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   894
    "Created: / 18-06-2017 / 23:41:07 / cg"
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   895
!
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   896
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   897
invFact
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   898
    InvFact isNil ifTrue:[
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   899
	InvFact := Array new:15.
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   900
	InvFact at:1 put:(self d0:1.66666666666666657e-01 d1:9.25185853854297066e-18 d2:5.13581318503262866e-34 d3:2.85094902409834186e-50).
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   901
	InvFact at:2 put:(self d0:4.16666666666666644e-02 d1:2.31296463463574266e-18 d2:1.28395329625815716e-34 d3:7.12737256024585466e-51).
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   902
	InvFact at:3 put:(self d0:8.33333333333333322e-03 d1:1.15648231731787138e-19 d2:1.60494162032269652e-36 d3:2.22730392507682967e-53).
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   903
	InvFact at:4 put:(self d0:1.38888888888888894e-03 d1:-5.30054395437357706e-20 d2:-1.73868675534958776e-36 d3:-1.63335621172300840e-52).
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   904
	InvFact at:5 put:(self d0:1.98412698412698413e-04 d1:1.72095582934207053e-22 d2:1.49269123913941271e-40 d3:1.29470326746002471e-58).
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   905
	InvFact at:6 put:(self d0:2.48015873015873016e-05 d1:2.15119478667758816e-23 d2:1.86586404892426588e-41 d3:1.61837908432503088e-59).
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   906
	InvFact at:7 put:(self d0:2.75573192239858925e-06 d1:-1.85839327404647208e-22 d2:8.49175460488199287e-39 d3:-5.72661640789429621e-55).
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   907
	InvFact at:8 put:(self d0:2.75573192239858883e-07 d1:2.37677146222502973e-23 d2:-3.26318890334088294e-40 d3:1.61435111860404415e-56).
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   908
	InvFact at:9 put:(self d0:2.50521083854417202e-08 d1:-1.44881407093591197e-24 d2:2.04267351467144546e-41 d3:-8.49632672007163175e-58).
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   909
	InvFact at:10 put:(self d0:2.08767569878681002e-09 d1:-1.20734505911325997e-25 d2:1.70222792889287100e-42 d3:1.41609532150396700e-58).
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   910
	InvFact at:11 put:(self d0:1.60590438368216133e-10 d1:1.25852945887520981e-26 d2:-5.31334602762985031e-43 d3:3.54021472597605528e-59).
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   911
	InvFact at:12 put:(self d0:1.14707455977297245e-11 d1:2.06555127528307454e-28 d2:6.88907923246664603e-45 d3:5.72920002655109095e-61).
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   912
	InvFact at:13 put:(self d0:7.64716373181981641e-13 d1:7.03872877733453001e-30 d2:-7.82753927716258345e-48 d3:1.92138649443790242e-64).
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   913
	InvFact at:14 put:(self d0:4.77947733238738525e-14 d1:4.39920548583408126e-31 d2:-4.89221204822661465e-49 d3:1.20086655902368901e-65).
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   914
	InvFact at:15 put:(self d0:2.81145725434552060e-15 d1:1.65088427308614326e-31 d2:-2.87777179307447918e-50 d3:4.27110689256293549e-67).
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   915
    ].
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   916
    ^ InvFact
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   917
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   918
    "Created: / 19-06-2017 / 02:22:23 / cg"
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   919
!
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   920
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   921
ln10
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   922
    "return the constant e as quad precision double.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   923
     (returns approx. 212 bits of precision)"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   924
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   925
    Ln10 isNil ifTrue:[
4388
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   926
	Ln10 := self fromDoubleArray:(DoubleArray
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   927
				    with: 2.302585092994045901e+00
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   928
				    with: -2.170756223382249351e-16
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   929
				    with: -9.984262454465776570e-33
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   930
				    with: -4.023357454450206379e-49)
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   931
    ].
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   932
    ^ Ln10
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   933
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   934
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   935
     self ln10
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   936
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   937
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   938
    "Created: / 12-06-2017 / 18:32:29 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   939
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   940
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   941
ln2
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   942
    "return the constant e as quad precision double.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   943
     (returns approx. 212 bits of precision)"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   944
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   945
    Ln2 isNil ifTrue:[
4388
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   946
	Ln2 := self fromDoubleArray:(DoubleArray
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   947
				    with: 6.931471805599452862e-01
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   948
				    with: 2.319046813846299558e-17
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   949
				    with: 5.707708438416212066e-34
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   950
				    with: -3.582432210601811423e-50)
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   951
    ].
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   952
    ^ Ln2
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   953
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   954
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   955
     self ln2
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   956
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   957
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   958
    "Created: / 12-06-2017 / 18:31:34 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   959
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   960
4411
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   961
negativeInfinity
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   962
    ^ Infinity negative
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   963
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   964
    "Created: / 18-06-2017 / 23:40:47 / cg"
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   965
!
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   966
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   967
pi
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   968
    "return the constant pi as quad precision double.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   969
     (returns approx. 212 bits of precision)"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   970
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   971
    Pi isNil ifTrue:[
4388
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   972
	Pi := self fromDoubleArray:(DoubleArray
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   973
				    with: 3.141592653589793116e+00
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   974
				    with: 1.224646799147353207e-16
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   975
				    with: -2.994769809718339666e-33
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   976
				    with: 1.112454220863365282e-49)
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   977
    ].
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   978
    ^ Pi
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   979
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   980
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   981
     self pi
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   982
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   983
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   984
    "Created: / 12-06-2017 / 18:27:13 / cg"
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   985
!
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   986
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   987
unity
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   988
    "return the neutral element for multiplication (1.0) as QDouble"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   989
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   990
    QDoubleOne isNil ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   991
	QDoubleOne := 1.0 asQDouble.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   992
    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   993
    ^ QDoubleOne
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   994
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   995
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   996
     self unity
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   997
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   998
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   999
    "Created: / 15-06-2017 / 11:45:22 / cg"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1000
!
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1001
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1002
zero
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1003
    "return the neutral element for addition (0.0) as QDouble"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1004
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1005
    QDoubleZero isNil ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1006
	QDoubleZero := 0.0 asQDouble
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1007
    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1008
    ^ QDoubleZero
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1009
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1010
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1011
     self zero
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1012
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1013
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1014
    "Created: / 15-06-2017 / 11:44:13 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1015
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1016
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1017
!QDouble class methodsFor:'queries'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1018
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1019
defaultPrintPrecision
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1020
    "return the number of decimal digits printed by default"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1021
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1022
    ^ 10
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1023
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1024
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1025
     ShortFloat defaultPrintPrecision
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1026
     Float defaultPrintPrecision
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1027
     LongFloat defaultPrintPrecision
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1028
     QDouble defaultPrintPrecision
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1029
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1030
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1031
    "Created: / 17-06-2017 / 02:58:51 / cg"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1032
!
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1033
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1034
epsilon
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1035
    "return the maximum relative spacing of instances of mySelf
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1036
     (i.e. the value-delta of the least significant bit)"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1037
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
  1038
    ^ 1.2154326714572500565324311366323150942261000827598106963711353e-63
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1039
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1040
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1041
     Float epsilon
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1042
     ShortFloat epsilon
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1043
     QDouble epsilon
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1044
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1045
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1046
    "Created: / 12-06-2017 / 18:52:44 / cg"
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
  1047
    "Modified: / 14-06-2017 / 19:12:23 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1048
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1049
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1050
numBitsInExponent
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1051
    "answer the number of bits in the exponent"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1052
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1053
    ^ Float numBitsInExponent
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1054
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1055
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1056
     1.0 asQDouble class numBitsInExponent
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1057
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1058
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1059
    "Created: / 12-06-2017 / 11:11:04 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1060
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1061
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1062
numBitsInMantissa
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1063
    "answer the number of bits in the mantissa.
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1064
     Here, a fake number is returned"
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1065
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1066
    ^ (Float numBitsInMantissa - 1) * 4
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1067
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1068
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1069
     1.0 class numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1070
     1.0 asShortFloat class numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1071
     1.0 asLongFloat class numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1072
     1.0 asDDouble class numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1073
     1.0 asQDouble class numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1074
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1075
     Float numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1076
     ShortFloat numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1077
     QDouble numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1078
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1079
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1080
    "Created: / 12-06-2017 / 11:13:44 / cg"
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1081
    "Modified (comment): / 20-06-2017 / 11:05:26 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1082
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1083
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1084
precision
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1085
    "answer the number of bits in the mantissa"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1086
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1087
    ^ (Float precision - 1) * 4
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1088
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1089
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1090
     1.0 class numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1091
     1.0 asShortFloat class numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1092
     1.0 asLongFloat class numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1093
     1.0 asQDouble class numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1094
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1095
     Float numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1096
     ShortFloat numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1097
     QDouble numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1098
     QDouble precision
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1099
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1100
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1101
    "Created: / 12-06-2017 / 18:49:11 / cg"
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1102
    "Modified (comment): / 20-06-2017 / 11:04:25 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1103
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1104
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1105
radix
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1106
    "answer the radix of a Floats exponent
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1107
     This is an IEEE float, which is represented as binary"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1108
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1109
    ^ Float radix
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1110
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1111
    "Created: / 12-06-2017 / 18:50:04 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1112
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1113
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1114
!QDouble methodsFor:'arithmetic'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1115
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1116
* aNumber
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1117
    "return the product of the receiver and the argument, aNumber"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1118
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1119
    ^ aNumber productFromQDouble:self
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1120
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1121
    "
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
  1122
     (((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) * (QDouble fromFloat:2.0)) asDoubleArray
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1123
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1124
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1125
    "Created: / 13-06-2017 / 01:00:47 / cg"
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
  1126
    "Modified (comment): / 14-06-2017 / 12:08:50 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1127
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1128
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1129
+ aNumber
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1130
    "return the sum of the receiver and the argument, aNumber"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1131
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1132
    ^ aNumber sumFromQDouble:self
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1133
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1134
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1135
     ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1136
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1137
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1138
    "Created: / 12-06-2017 / 16:17:46 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1139
    "Modified: / 12-06-2017 / 23:06:22 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1140
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1141
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1142
- aNumber
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1143
    "return the sum of the receiver and the argument, aNumber"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1144
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1145
    ^ self + (aNumber negated)
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1146
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1147
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1148
     (QDouble fromFloat:1e20) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1149
     ((QDouble fromFloat:1e20) - (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1150
     (QDouble fromFloat:1e-20) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1151
     ((QDouble fromFloat:1e-20) - (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1152
     ((QDouble fromFloat:2.0) - (QDouble fromFloat:1.0)) asDoubleArray
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1153
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1154
     ((QDouble fromFloat:2.0) - (QDouble fromFloat:1.0) + (QDouble fromFloat:1.0)) asDoubleArray
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1155
     ((QDouble fromFloat:1e-20) - (QDouble fromFloat:1.0) + (QDouble fromFloat:1.0)) asDoubleArray
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1156
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1157
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1158
    "Created: / 12-06-2017 / 23:41:39 / cg"
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1159
    "Modified (comment): / 15-06-2017 / 00:34:41 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1160
!
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1161
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1162
/ aNumber
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1163
    "return the quotient of the receiver and the argument, aNumber"
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1164
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1165
    ^ aNumber quotientFromQDouble:self
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1166
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1167
    "
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1168
     ((QDouble fromFloat:1e20) / (QDouble fromFloat:2.0)) asDoubleArray
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1169
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1170
     ((QDouble fromFloat:1.2345) / (QDouble fromFloat:10.0)) asDoubleArray
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1171
     ((QDouble fromFloat:1.2345) / 10.0) asDoubleArray
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1172
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1173
    "
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1174
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1175
    "Created: / 13-06-2017 / 17:59:09 / cg"
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1176
    "Modified (comment): / 15-06-2017 / 00:14:26 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1177
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1178
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1179
!QDouble methodsFor:'coercing & converting'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1180
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1181
asDoubleArray
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1182
    ^ DoubleArray
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1183
	    with:self d0
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1184
	    with:self d1
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1185
	    with:self d2
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1186
	    with:self d3.
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1187
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1188
    "
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1189
     (QDouble fromFloat:1.0) asDoubleArray
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1190
     (QDouble fromFloat:2.0) asDoubleArray
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1191
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1192
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1193
    "Created: / 12-06-2017 / 18:19:19 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1194
    "Modified (comment): / 13-06-2017 / 17:58:09 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1195
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1196
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1197
asFloat
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1198
    ^ self d0
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1199
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1200
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1201
     (QDouble fromFloat:1.0) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1202
     (QDouble fromFloat:2.0) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1203
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1204
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1205
    "Created: / 12-06-2017 / 18:15:27 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1206
    "Modified: / 13-06-2017 / 17:56:50 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1207
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1208
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1209
asInteger
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1210
    ^ self d0 asInteger
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1211
    + self d1 asInteger 
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1212
    + self d2 asInteger 
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1213
    + self d3 asInteger
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1214
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1215
    "Created: / 19-06-2017 / 18:07:17 / cg"
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1216
!
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1217
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1218
asQDouble
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1219
    "return a QDouble with same value as myself."
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1220
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1221
    ^ self
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1222
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1223
    "Created: / 15-06-2017 / 12:08:02 / cg"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1224
!
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1225
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1226
asTrueFraction
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1227
self halt.
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1228
    ^ self d0 asTrueFraction
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1229
    + self d1 asTrueFraction
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1230
    + self d2 asTrueFraction
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1231
    + self d3 asTrueFraction
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1232
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1233
    "
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1234
     1e10 asTrueFraction        -> 10000000000
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1235
     1e20 asTrueFraction        -> 100000000000000000000
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1236
     (1e20 + 1) asTrueFraction  -> 100000000000000000000 ouch!!
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1237
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1238
     1e10 asQDouble asTrueFraction       -> 10000000000
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1239
     1e20 asQDouble asTrueFraction       -> 100000000000000000000
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1240
     (1e20 asQDouble + 1) asTrueFraction -> 100000000000000000001
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1241
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1242
     (1e40 asQDouble + 1e20 + 1) asTrueFraction -> 10000000000000000303886028427003666890753 
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1243
     (1e40 asQDouble + 1e20) asTrueFraction 
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1244
    "
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1245
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1246
    "Created: / 20-06-2017 / 11:09:03 / cg"
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1247
!
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1248
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1249
coerce:aNumber
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1250
    "convert the argument aNumber into an instance of the receiver's class and return it."
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1251
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1252
    ^ aNumber asQDouble
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1253
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1254
    "Created: / 12-06-2017 / 17:13:47 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1255
    "Modified: / 12-06-2017 / 21:09:06 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1256
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1257
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1258
exponent
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1259
    ^ self d0 exponent
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1260
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1261
    "Created: / 20-06-2017 / 11:06:02 / cg"
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1262
!
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1263
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1264
generality
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1265
    "return the generality value - see ArithmeticValue>>retry:coercing:"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1266
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1267
    ^ 95
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1268
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1269
    "Created: / 12-06-2017 / 17:13:14 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1270
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1271
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1272
negative
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1273
    ^ self d0 negative
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1274
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1275
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1276
     (QDouble fromFloat:0.0) negative
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1277
     (QDouble fromFloat:1.0) negative
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1278
     (QDouble fromFloat:-1.0) negative
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1279
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1280
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1281
    "Created: / 13-06-2017 / 01:57:39 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1282
    "Modified: / 13-06-2017 / 17:58:26 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1283
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1284
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1285
positive
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1286
    ^ self d0 positive
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1287
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1288
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1289
     (QDouble fromFloat:1.0) positive
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1290
     (QDouble fromFloat:-1.0) positive
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1291
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1292
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1293
    "Created: / 13-06-2017 / 01:56:53 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1294
    "Modified: / 13-06-2017 / 17:58:41 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1295
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1296
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1297
!QDouble methodsFor:'comparing'!
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1298
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1299
< aNumber
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1300
    "return true, if the argument, aNumber is greater than the receiver"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1301
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1302
    ^ aNumber lessFromQDouble:self
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1303
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1304
    "Created: / 13-06-2017 / 16:58:53 / cg"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1305
!
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1306
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1307
= aNumber
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1308
    "return true, if the argument, aNumber has the same value as than the receiver"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1309
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1310
    ^ aNumber equalFromQDouble:self
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1311
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1312
    "Created: / 13-06-2017 / 17:12:09 / cg"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1313
! !
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1314
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1315
!QDouble methodsFor:'double dispatching'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1316
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1317
differenceFromFloat:aFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1318
    "aFloat - self"
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1319
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1320
    ^ aFloat + (self negated)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1321
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1322
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1323
     1.0 - (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1324
     1e20 - (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1325
     (1.0 - (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1326
     (1e20 - (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1327
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1328
     (1.0 - (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1329
     (1e20 - (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1330
     (1e20 - (QDouble fromFloat:1.0) + 1e-20) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1331
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1332
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1333
    "Created: / 12-06-2017 / 23:38:05 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1334
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1335
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1336
differenceFromQDouble:aQDouble
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1337
    "aQDouble - self"
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1338
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1339
    ^ aQDouble + (self negated)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1340
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1341
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1342
     1.0 - (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1343
     1e20 - (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1344
     (1.0 - (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1345
     (1e20 - (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1346
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1347
     (1.0 - (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1348
     (1e20 - (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1349
     (1e20 - (QDouble fromFloat:1.0) + 1e-20) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1350
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1351
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1352
    "Created: / 12-06-2017 / 23:38:19 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1353
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1354
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1355
equalFromQDouble:aQDouble
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1356
%{
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1357
    if (__Class(aQDouble) == QDouble) {
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1358
	double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1359
	double *b = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1360
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1361
	RETURN ((a[0] == b[0]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1362
		&& a[1] == b[1]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1363
		&& a[2] == b[2]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1364
		&& a[3] == b[3]) ? true : false);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1365
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1366
%}.
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1367
    ^ (aQDouble d0 = self d0)
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1368
    and:[ (aQDouble d1 = self d1)
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1369
    and:[ (aQDouble d2 = self d2)
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1370
    and:[ (aQDouble d3 = self d3) ]]]
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1371
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1372
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1373
     (QDouble fromFloat:1.0) = (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1374
     (QDouble fromFloat:1.0) = 1.0
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1375
     1.0 = (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1376
   "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1377
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1378
    "Created: / 13-06-2017 / 03:01:19 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1379
    "Modified: / 13-06-2017 / 18:01:52 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1380
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1381
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1382
lessFromQDouble:aQDouble
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1383
    "sent when aQDouble does not know how to compare to the receiver..
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1384
     Return true if aQDouble < self"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1385
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1386
%{
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1387
    if (__Class(aQDouble) == QDouble) {
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1388
	double *a = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1389
	double *b = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1390
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1391
	// now compare if a < b!
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1392
	RETURN
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1393
	    ((a[0] < b[0] ||
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1394
	      (a[0] == b[0] && (a[1] < b[1] ||
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1395
		(a[1] == b[1] && (a[2] < b[2] ||
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1396
		  (a[2] == b[2] && a[3] < b[3])))))) ? true : false);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1397
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1398
%}.
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1399
    ^ super lessFromQDouble:aQDouble
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1400
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1401
    "
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1402
     (1.0 + 1e-40) > 1.0
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1403
     ((QDouble fromFloat:1.0) + (QDouble fromFloat:1e-40)) > (QDouble fromFloat:1.0)
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1404
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1405
     (QDouble fromFloat:1.0) > (QDouble fromFloat:1.0)
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1406
     (QDouble fromFloat:1.1) > (QDouble fromFloat:1.0)
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1407
     (QDouble fromFloat:1.0) > 1.0
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1408
     (QDouble fromFloat:1.1) > 1.0
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1409
     1.0 > (QDouble fromFloat:1.0)
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1410
   "
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1411
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1412
    "Created: / 13-06-2017 / 17:07:47 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1413
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1414
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1415
productFromFloat:aFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1416
%{
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1417
    if (__isFloatLike(aFloat)) {
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1418
        double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1419
        double b = __floatVal(aFloat);
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1420
        double p0, p1, p2, p3;
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1421
        double q0, q1, q2;
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1422
        double s0, s1, s2, s3, s4;
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1423
        OBJ newQD;
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1424
        int savedCV;
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1425
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1426
        fpu_fix_start(&savedCV);
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1427
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1428
        m_two_prod(p0, a[0], b, q0);
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1429
        m_two_prod(p1, a[1], b, q1);
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1430
        m_two_prod(p2, a[2], b, q2);
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1431
        p3 = a[3] * b;
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1432
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1433
        s0 = p0;
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1434
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1435
        m_two_sum(s1, q0, p1, s2);
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1436
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1437
        m_three_sum(s2, q1, p2);
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1438
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1439
        m_three_sum2(q1, q2, p3);
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1440
        s3 = q1;
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1441
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1442
        s4 = q2 + p2;
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1443
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1444
        m_renorm5(s0, s1, s2, s3, s4);
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1445
        fpu_fix_end(&savedCV);
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1446
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1447
        __qNew_qdReal(newQD, s0, s1, s2, s3);
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1448
        RETURN( newQD );
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1449
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1450
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1451
    ^ super productFromFloat:aFloat.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1452
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1453
    "
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1454
     loosing bits here:
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1455
     
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1456
     (1e20+1.0)*2.0
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1457
     (1e20+1.0)*1e20
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1458
     (1e40+1.0)*2.0
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1459
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1460
     but not here:
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1461
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1462
     (1.0 asQDouble) * 2.0
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1463
     ((1e20 asQDouble) + (1.0)) * 2.0   
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1464
     ((1e20 asQDouble) + (1.0)) * 100.0    10000000000000000000100.0
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1465
     ((1e20 asQDouble) + (1.0)) * 1000.0   
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1466
     ((1e40 asQDouble) + (1.0)) * 2.0    
4387
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1467
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1468
     2.0 * (QDouble fromFloat:1.0)
4387
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1469
     2.0 * (QDouble fromFloat:3.0)
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1470
     (QDouble fromFloat:2.0) * (QDouble fromFloat:3.0)
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1471
     
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1472
     QDouble ln2       DoubleArray(0.693147180559945 2.3190468138463E-17 5.70770843841621E-34 -3.58243221060181E-50)
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1473
     2.0 * QDouble ln2 DoubleArray(1.38629436111989 4.6380936276926E-17 1.14154168768324E-33 -7.16486442120362E-50)
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1474
     QDouble ln2 * 2.0 
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1475
     
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1476
     2.0 * ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) DoubleArray(2E+20 2.0 0.0 0.0)
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1477
     ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) * 2.0 DoubleArray(2E+20 4E+20 0.0 0.0)
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1478
     ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) * (QDouble fromFloat:2.0) DoubleArray(2E+20 4E+20 0.0 0.0)
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1479
     (QDouble fromFloat:2.0) * ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) DoubleArray(2E+20 4E+20 0.0 0.0)
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1480
     
4387
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1481
     (2.0 * ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0))) - (QDouble fromFloat:1e20) - (QDouble fromFloat:1e20)
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1482
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1483
     (2.0 * (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1484
     (1e20 * (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1485
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1486
     (1e20 * (QDouble fromFloat:1.0) * 1e-20) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1487
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1488
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1489
    "Created: / 13-06-2017 / 00:58:56 / cg"
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1490
    "Modified: / 19-06-2017 / 16:48:18 / cg"
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1491
    "Modified (comment): / 19-06-2017 / 18:11:43 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1492
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1493
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1494
productFromQDouble:aQDouble
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1495
%{
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1496
    if (__Class(aQDouble) == QDouble) {
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1497
	double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1498
	double *b = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1499
	OBJ newQD;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1500
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1501
	// sloppy
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1502
	double p0, p1, p2, p3, p4, p5;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1503
	double q0, q1, q2, q3, q4, q5;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1504
	double t0, t1;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1505
	double s0, s1, s2;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1506
	int savedCV;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1507
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1508
	fpu_fix_start(&savedCV);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1509
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1510
	m_two_prod(p0, a[0], b[0], q0);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1511
	// fprintf(stderr, "%f * %f -> %f, %f\n", a[0], b[0], p0, q0);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1512
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1513
	m_two_prod(p1, a[0], b[1], q1);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1514
	m_two_prod(p2, a[1], b[0], q2);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1515
	// fprintf(stderr, "%f * %f -> %f, %f\n", a[0], b[1], p1, q1);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1516
	// fprintf(stderr, "%f * %f -> %f, %f\n", a[1], b[0], p2, q2);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1517
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1518
	m_two_prod(p3, a[0], b[2], q3);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1519
	m_two_prod(p4, a[1], b[1], q4);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1520
	m_two_prod(p5, a[2], b[0], q5);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1521
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1522
	// fprintf(stderr, "%f * %f -> %f, %f\n", a[0], b[2], p3, q3);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1523
	// fprintf(stderr, "%f * %f -> %f, %f\n", a[1], b[1], p4, q4);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1524
	// fprintf(stderr, "%f * %f -> %f, %f\n", a[2], b[0], p5, q5);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1525
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1526
	/* Start Accumulation */
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1527
	m_three_sum(p1, p2, q0);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1528
	// fprintf(stderr, "mul7: after three_sum: p1:%e p2:%e q0:%e\n", p1, p2, q0);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1529
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1530
	/* Six-Three Sum  of p2, q1, q2, p3, p4, p5. */
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1531
	m_three_sum(p2, q1, q2);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1532
	// fprintf(stderr, "mul8: after three_sum: p2:%e q1:%e q2:%e\n", p2, q1, q2);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1533
	m_three_sum(p3, p4, p5);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1534
	// fprintf(stderr, "mul9: after three_sum: p3:%e p4:%e p5:%e\n", p3, p4, p5);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1535
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1536
	/* compute (s0, s1, s2) = (p2, q1, q2) + (p3, p4, p5). */
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1537
	m_two_sum(s0, p2, p3, t0);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1538
	// fprintf(stderr, "mul10: after two_sum: s0:%e p2:%e p3:%e t0:%e\n", s0, p2, p3, t0);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1539
	m_two_sum(s1, q1, p4, t1);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1540
	// fprintf(stderr, "mul11: after two_sum: s1:%e q1:%e p4:%e t1:%e\n", s1, q1, p4, t1);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1541
	s2 = q2 + p5;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1542
	m_two_sum(s1, s1, t0, t0);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1543
	// fprintf(stderr, "mul12: after two_sum: s1:%e s1:%e t0:%e t0:%e\n", s1, s1, t0, t0);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1544
	s2 += (t0 + t1);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1545
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1546
	/* O(eps^3) order terms */
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1547
	s1 += a[0]*b[3] + a[1]*b[2] + a[2]*b[1] + a[3]*b[0] + q0 + q3 + q4 + q5;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1548
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1549
	// fprintf(stderr, "before renorm5: p0:%e p2:%e s0:%e s1:%e s2:%e\n", p0, p1, s0, s1, s2);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1550
	m_renorm5(p0, p1, s0, s1, s2);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1551
	// fprintf(stderr, "after renorm5: p0:%e p2:%e s0:%e s1:%e s2:%e\n", p0, p1, s0, s1, s2);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1552
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1553
	fpu_fix_end(&savedCV);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1554
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1555
	__qNew_qdReal(newQD, p0, p1, s0, s1);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1556
	RETURN( newQD );
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1557
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1558
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1559
    ^ super productFromQDouble:aQDouble.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1560
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1561
    "
4387
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1562
     (QDouble fromFloat:1.0) * 2.0
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1563
     2.0 * (QDouble fromFloat:1.0)
4387
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1564
     (QDouble fromFloat:1.0) * (QDouble fromFloat:2.0)
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1565
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1566
     1e20 * (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1567
     (2.0 * (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1568
     (1e20 * (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1569
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1570
     (1e20 * (QDouble fromFloat:1.0) * 1e-20) asDoubleArray
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
  1571
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
  1572
     ( ((QDouble fromFloat:1.0) + (QDouble fromFloat:1e20)) * (QDouble fromFloat:2.0)) asDoubleArray
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1573
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1574
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1575
    "Created: / 13-06-2017 / 01:06:22 / cg"
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
  1576
    "Modified: / 14-06-2017 / 16:59:58 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1577
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1578
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1579
quotientFromQDouble:aQDouble
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1580
    "sloppy"
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1581
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1582
    |q0 q1 q2 q3 r|
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1583
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1584
    q0 := aQDouble d0 / self d0.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1585
    "/ Stdout showCR:('q0: %1 (a[0]=%2; b[0]=%3)\n' bindWith:q0 with:self d0 with:aQDouble d0).
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1586
    r := aQDouble - (self * q0).
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1587
    "/ Stdout showCR:('r: %1\n' bindWith:r asDoubleArray).
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1588
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1589
    q1 := r d0 / self d0.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1590
    "/ Stdout showCR:('q1: %1 (r[0]=%2; b[0]=%3)\n' bindWith:q1 with:r d0 with:aQDouble d0).
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1591
    r := r - (self * q1).
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1592
    "/ Stdout showCR:('r: %1\n' bindWith:r asDoubleArray).
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1593
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1594
    q2 := r d0 / self d0.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1595
    "/ Stdout showCR:('q2: %1 (r[0]=%2; b[0]=%3)\n' bindWith:q2 with:r d0 with:aQDouble d0).
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1596
    r := r - (self * q2).
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1597
    "/ Stdout showCR:('r: %1\n' bindWith:r asDoubleArray).
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1598
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1599
    q3 := r d0 / self d0.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1600
    "/ Stdout showCR:('q3: %1 (r[0]=%2; b[0]=%3)\n' bindWith:q3 with:r d0 with:aQDouble d0).
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1601
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1602
    r := self class d0:q0 d1:q1 d2:q2 d3:q3.
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1603
    "/ Stdout showCR:('before renorm: %1\n' bindWith:r asDoubleArray).
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1604
    r renorm.
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1605
    "/ Stdout showCR:('after renorm: %1\n' bindWith:r asDoubleArray).
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1606
    ^ r
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1607
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1608
    "
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1609
     2.0 / (QDouble fromFloat:2.0)
4387
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1610
     2.0 / (QDouble fromFloat:1.0)
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1611
     1e20 / (QDouble fromFloat:1.0)
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1612
     (2.0 / (QDouble fromFloat:1.0)) asFloat
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1613
     (1e20 / (QDouble fromFloat:1.0)) asFloat
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1614
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1615
     (QDouble fromFloat:2.0) / 2.0
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1616
     (QDouble fromFloat:1e20) / 2.0
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1617
     ((QDouble fromFloat:1.0) / 2.0) asFloat
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1618
     ((QDouble fromFloat:1e20 / 2.0)) asFloat
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1619
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1620
     ((1e20 + (QDouble fromFloat:1.0) + 1e-20) / 2.0) asDoubleArray
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1621
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1622
     ((QDouble fromFloat:10.0) quotientFromQDouble: (QDouble fromFloat:1.234)) asDoubleArray
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1623
     ((QDouble fromFloat:1.234) / (QDouble fromFloat:10.0)) asDoubleArray
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1624
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1625
q0: 1.234000e-01 (a[0]=1.234000e+00; b[0]=1.000000e+01)
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1626
a: 1.234000e+00/0.000000e+00/0.000000e+00/0.000000e+00
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1627
b: 1.000000e+01/0.000000e+00/0.000000e+00/0.000000e+00
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1628
(b * q0): 1.234000e+00/-2.775558e-17/0.000000e+00/0.000000e+00
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1629
r: 2.775558e-17/0.000000e+00/0.000000e+00/0.000000e+00
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1630
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1631
q1: 2.775558e-18 (r[0]=2.775558e-17; b[0]=1.000000e+01)
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1632
r: -1.540744e-33/0.000000e+00/0.000000e+00/0.000000e+00
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1633
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1634
q2: -1.540744e-34 (r[0]=-1.540744e-33; b[0]=1.000000e+01)
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1635
r: 8.552847e-50/0.000000e+00/0.000000e+00/0.000000e+00
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1636
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1637
q3: 8.552847e-51 (r[0]=8.552847e-50; b[0]=1.000000e+01)
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1638
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1639
before renorm: 1.234000e-01/2.775558e-18/-1.540744e-34/8.552847e-51
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1640
after renorm: 1.234000e-01/2.775558e-18/-1.540744e-34/8.552847e-51
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1641
1.234/10.0 is: 0.123400 / 0.000000 / -0.000000 / 0.000000
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1642
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1643
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1644
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1645
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1646
    "Created: / 13-06-2017 / 17:50:35 / cg"
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1647
    "Modified (comment): / 15-06-2017 / 01:02:05 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1648
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1649
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1650
sumFromFloat:aFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1651
%{
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1652
    if (__isFloatLike(aFloat)) {
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1653
	double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1654
	double b = __floatVal(aFloat);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1655
	double c0, c1, c2, c3;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1656
	double e;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1657
	OBJ newQD;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1658
	int savedCV;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1659
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1660
	fpu_fix_start(&savedCV);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1661
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1662
	m_two_sum(c0, a[0], b, e);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1663
	m_two_sum(c1 ,a[1], e, e);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1664
	m_two_sum(c2, a[2], e, e);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1665
	m_two_sum(c3, a[3], e, e);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1666
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1667
	m_renorm5(c0, c1, c2, c3, e);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1668
	fpu_fix_end(&savedCV);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1669
	__qNew_qdReal(newQD, c0, c1, c2, c3);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1670
	RETURN( newQD );
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1671
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1672
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1673
    ^ super sumFromFloat:aFloat.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1674
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1675
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1676
     1.0 + (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1677
     1e20 + (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1678
     (1.0 + (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1679
     (1e20 + (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1680
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1681
     (1.0 + (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1682
     (1e20 + (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1683
     (1e20 + (QDouble fromFloat:1.0) + 1e-20) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1684
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1685
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1686
    "Created: / 12-06-2017 / 17:16:41 / cg"
4387
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1687
    "Modified: / 14-06-2017 / 11:43:47 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1688
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1689
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1690
sumFromQDouble:aQDouble
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1691
%{
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1692
    if (__Class(aQDouble) == QDouble) {
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1693
        double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1694
        double *b = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1695
        OBJ newQD;
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1696
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1697
#ifndef QD_IEEE_ADD
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1698
        // sloppy_add...
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1699
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1700
# if 0
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1701
        double s0, s1, s2, s3;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1702
        double t0, t1, t2, t3;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1703
        int savedCV;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1704
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1705
        fpu_fix_start(&savedCV);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1706
        m_two_sum(s0, a[0], b[0], t0);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1707
        m_two_sum(s1, a[1], b[1], t1);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1708
        m_two_sum(s2, a[2], b[2], t2);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1709
        m_two_sum(s3, a[3], b[3], t3);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1710
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1711
        m_two_sum(s1, s1, t0, t0);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1712
        m_three_sum(s2, t0, t1);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1713
        m_three_sum2(s3, t0, t2);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1714
        t0 = t0 + t1 + t3;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1715
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1716
        m_renorm5(s0, s1, s2, s3, t0);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1717
        fpu_fix_end(&savedCV);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1718
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1719
        __qNew_qdReal(newQD, s0, s1, s2, s3);
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1720
# else
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1721
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1722
        /* Same as above, but addition re-organized to minimize
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1723
           data dependency ... unfortunately some compilers are
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1724
           not very smart to do this automatically */
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1725
        double s0, s1, s2, s3;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1726
        double t0, t1, t2, t3;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1727
        double v0, v1, v2, v3;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1728
        double u0, u1, u2, u3;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1729
        double w0, w1, w2, w3;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1730
        int savedCV;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1731
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1732
        fpu_fix_start(&savedCV);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1733
        s0 = a[0] + b[0];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1734
        s1 = a[1] + b[1];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1735
        s2 = a[2] + b[2];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1736
        s3 = a[3] + b[3];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1737
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1738
        v0 = s0 - a[0];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1739
        v1 = s1 - a[1];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1740
        v2 = s2 - a[2];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1741
        v3 = s3 - a[3];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1742
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1743
        u0 = s0 - v0;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1744
        u1 = s1 - v1;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1745
        u2 = s2 - v2;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1746
        u3 = s3 - v3;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1747
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1748
        w0 = a[0] - u0;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1749
        w1 = a[1] - u1;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1750
        w2 = a[2] - u2;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1751
        w3 = a[3] - u3;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1752
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1753
        u0 = b[0] - v0;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1754
        u1 = b[1] - v1;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1755
        u2 = b[2] - v2;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1756
        u3 = b[3] - v3;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1757
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1758
        t0 = w0 + u0;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1759
        t1 = w1 + u1;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1760
        t2 = w2 + u2;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1761
        t3 = w3 + u3;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1762
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1763
        m_two_sum(s1, s1, t0, t0);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1764
        m_three_sum(s2, t0, t1);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1765
        m_three_sum2(s3, t0, t2);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1766
        t0 = t0 + t1 + t3;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1767
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1768
        /* renormalize */
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1769
        m_renorm5(s0, s1, s2, s3, t0);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1770
        fpu_fix_end(&savedCV);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1771
        __qNew_qdReal(newQD, s0, s1, s2, s3);
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1772
# endif
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1773
#else
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1774
        // ieee_add...
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1775
        int i, j, k;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1776
        double s, t;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1777
        double u, v;   /* double-length accumulator */
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1778
        double x[4] = {0.0, 0.0, 0.0, 0.0};
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1779
        int savedCV;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1780
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1781
        fpu_fix_start(&savedCV);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1782
        i = j = k = 0;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1783
        if (abs(a[i]) > abs(b[j]))
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1784
          u = a[i++];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1785
        else
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1786
          u = b[j++];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1787
        if (abs(a[i]) > abs(b[j]))
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1788
          v = a[i++];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1789
        else
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1790
          v = b[j++];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1791
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1792
        u = quick_two_sum(u, v, v);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1793
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1794
        while (k < 4) {
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1795
          if (i >= 4 && j >= 4) {
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1796
            x[k] = u;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1797
            if (k < 3)
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1798
              x[++k] = v;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1799
            break;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1800
          }
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1801
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1802
          if (i >= 4)
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1803
            t = b[j++];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1804
          else if (j >= 4)
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1805
            t = a[i++];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1806
          else if (abs(a[i]) > abs(b[j])) {
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1807
            t = a[i++];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1808
          } else
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1809
            t = b[j++];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1810
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1811
          s = quick_three_accum(u, v, t);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1812
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1813
          if (s != 0.0) {
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1814
            x[k++] = s;
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1815
          }
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1816
        }
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1817
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1818
        /* add the rest. */
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1819
        for (k = i; k < 4; k++)
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1820
          x[3] += a[k];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1821
        for (k = j; k < 4; k++)
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1822
          x[3] += b[k];
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1823
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1824
        m_renorm4(x[0], x[1], x[2], x[3]);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1825
        fpu_fix_end(&savedCV);
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1826
        __qNew_qdReal(newQD, x[0], x[1], x[2], x[3]);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1827
#endif
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1828
        RETURN(newQD);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1829
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1830
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1831
    ^ super sumFromQDouble:aQDouble
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1832
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1833
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1834
     (QDouble fromFloat:1.0) + (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1835
     (QDouble fromFloat:1.0) + 1.0
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1836
     1.0 + (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1837
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1838
     ((QDouble fromFloat:1.0) + (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1839
     ((QDouble fromFloat:1.0) + 1.0) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1840
     (1.0 + (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1841
     (1e-20 + (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1842
     (1e20 + (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1843
   "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1844
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1845
    "Created: / 12-06-2017 / 21:15:43 / cg"
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1846
    "Modified: / 20-06-2017 / 00:04:06 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1847
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1848
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1849
!QDouble methodsFor:'inspecting'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1850
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1851
inspectorExtraAttributes
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1852
    "extra (pseudo instvar) entries to be shown in an inspector."
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1853
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1854
    ^ super inspectorExtraAttributes
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1855
	add:'-{doubles}' ->
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1856
	    [
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1857
		self asDoubleArray printString
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1858
	    ];
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1859
	yourself
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1860
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1861
    "Created: / 12-06-2017 / 23:43:05 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1862
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1863
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1864
!QDouble methodsFor:'mathematical functions'!
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1865
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1866
exp
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1867
    "/ Strategy:  We first reduce the size of x by noting that
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1868
    "/
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1869
    "/  exp(kr + m * log(2)) = 2^m * exp(r)^k
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1870
    "/
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1871
    "/     where m and k are integers.  By choosing m appropriately
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1872
    "/     we can make |kr| <= log(2) / 2 = 0.347.  Then exp(r) is
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1873
    "/     evaluated using the familiar Taylor series.  Reducing the
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1874
    "/     argument substantially speeds up the convergence.       */
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1875
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1876
    |k inv_k d0 m mul_pwr2 mul2 r
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  1877
     s p t thresh eps i|
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  1878
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  1879
    eps := 1.21543267145725e-63. "/ = 2^-209.
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  1880
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1881
    d0 := self d0.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1882
    (d0 <= -709.0) ifTrue:[
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1883
        ^ 0.0 asQDouble.
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  1884
    ].
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  1885
    (d0 >= 709.0) ifTrue:[
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1886
        ^ Infinity positive
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1887
    ].
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1888
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1889
    (d0 = 0.0) ifTrue:[
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1890
        ^ 1.0 asQDouble.
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  1891
    ].
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1892
    (d0 = 1.0) ifTrue:[
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1893
        self isOne ifTrue:[
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1894
            ^ self class e
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1895
        ].
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  1896
    ].
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1897
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1898
    k := 1.0 ldexp:16.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1899
    inv_k := 1.0 / k.
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1900
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1901
    "/  double m = std::floor(a.x[0] / qd_real::_log2.x[0] + 0.5);
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1902
    m := (d0 / Float ln2 + 0.5) floor.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1903
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1904
    mul_pwr2 := [:a :b | QDouble d0:(a d0 * b) d1:(a d1 * b) d2:(a d2 * b) d3:(a d3 * b) ].
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1905
    mul2 := [:a | QDouble d0:(a d0 * 2.0) d1:(a d1 * 2.0) d2:(a d2 * 2.0) d3:(a d3 * 2.0) ].
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1906
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1907
    "/  qd_real r = mul_pwr2(a - qd_real::_log2 * m, inv_k);
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1908
    r := mul_pwr2 value:(self - (self class ln2 * m)) value:inv_k.
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  1909
    thresh := inv_k * eps.
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1910
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1911
    p := r squared.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1912
    s := r + (mul_pwr2 value:p value:0.5).
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1913
    i := 1.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1914
    [
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1915
        p := p * r.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1916
        t := p * (self class invFact at:i).
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1917
        i := i+1.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1918
        s := s + t.
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1919
    ] doWhile:[ (t asFloat abs > thresh) and:[i < 10] ]. "/ (std::abs(to_double(t)) > thresh && i < 9);
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1920
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1921
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1922
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1923
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1924
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1925
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1926
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1927
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1928
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1929
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1930
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1931
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1932
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1933
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1934
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1935
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1936
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1937
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1938
    s := s + 1.0.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1939
    ^ s ldexp:m asInteger.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1940
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1941
    "
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1942
     1.0 exp -> 2.71828182845905
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1943
     1.0 asQDouble exp -> 2.71828182845905
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1944
    "
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1945
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1946
    "Created: / 19-06-2017 / 01:49:32 / cg"
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1947
    "Modified: / 19-06-2017 / 19:10:15 / cg"
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1948
!
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1949
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1950
floor
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1951
    "return the receiver truncated towards negative infinity"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1952
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1953
%{
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1954
    double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1955
    OBJ newQD;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1956
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1957
    double x0, x1, x2, x3;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1958
    x1 = x2 = x3 = 0.0;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1959
    x0 =floor(a[0]);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1960
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1961
    if (x0 == a[0]) {
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1962
	x1 = floor(a[1]);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1963
	if (x1 == a[1]) {
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1964
	    x2 = floor(a[2]);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1965
	    if (x2 == a[2]) {
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1966
		x3 = floor(a[3]);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1967
	    }
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1968
	}
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1969
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1970
	m_renorm4(x0, x1, x2, x3);
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1971
    }
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1972
    __qNew_qdReal(newQD, x0, x1, x2, x3);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1973
    RETURN( newQD );
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1974
%}.
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1975
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1976
    "
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1977
     (QDouble fromFloat:4.0) floor
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1978
     (QDouble fromFloat:4.1) floor
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1979
     (QDouble fromFloat:0.1) floor
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1980
     (0.1 + (QDouble fromFloat:1.0)) floor
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1981
     (1e20 + (QDouble fromFloat:1.0)) floor
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1982
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1983
     (QDouble fromFloat:1.5) floor
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1984
     (QDouble fromFloat:0.5) floor
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1985
     (QDouble fromFloat:-0.5) floor
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1986
     (QDouble fromFloat:-1.5) floor
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1987
    "
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1988
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1989
    "Created: / 13-06-2017 / 01:52:44 / cg"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1990
    "Modified (comment): / 13-06-2017 / 17:33:19 / cg"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1991
!
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1992
4415
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  1993
floor2
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  1994
    "return the receiver truncated towards negative infinity"
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  1995
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  1996
    |f0 f1 f2 f3|
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  1997
%{
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  1998
    double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  1999
    OBJ newQD;
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2000
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2001
    double x0, x1, x2, x3;
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2002
    x1 = x2 = x3 = 0.0;
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2003
    x0 =floor(a[0]);
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2004
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2005
    if (x0 == a[0]) {
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2006
	x1 = floor(a[1]);
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2007
	if (x1 == a[1]) {
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2008
	    x2 = floor(a[2]);
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2009
	    if (x2 == a[2]) {
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2010
		x3 = floor(a[3]);
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2011
	    }
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2012
	}
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2013
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2014
	m_renorm4(x0, x1, x2, x3);
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2015
    }
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2016
    __qMKFLOAT(f0, x0);
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2017
    __qMKFLOAT(f1, x1);
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2018
    __qMKFLOAT(f2, x2);
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2019
    __qMKFLOAT(f3, x3);
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2020
%}.
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2021
    ^ (f0 + f1 + f2 + f3) asInteger
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2022
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2023
    "
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2024
     (QDouble fromFloat:4.0) floor
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2025
     (QDouble fromFloat:4.1) floor
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2026
     (QDouble fromFloat:0.1) floor
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2027
     (0.1 + (QDouble fromFloat:1.0)) floor
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2028
     (1e20 + (QDouble fromFloat:1.0)) floor
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2029
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2030
     (QDouble fromFloat:1.5) floor
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2031
     (QDouble fromFloat:0.5) floor
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2032
     (QDouble fromFloat:-0.5) floor
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2033
     (QDouble fromFloat:-1.5) floor
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2034
    "
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2035
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2036
    "Created: / 13-06-2017 / 01:52:44 / cg"
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2037
    "Modified (comment): / 13-06-2017 / 17:33:19 / cg"
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2038
!
2b984cf54494 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2039
4411
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2040
ln
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2041
    |d0 x|
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2042
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2043
    d0 := self d0.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2044
    d0 = 1.0 ifTrue:[
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2045
        self isOne ifTrue:[ ^ self class zero ].
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2046
    ].
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2047
    d0 < 0.0 ifTrue:[
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2048
        ^ self class
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2049
            raise:#domainErrorSignal
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2050
            receiver:self
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2051
            selector:#ln
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2052
            arguments:#()
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2053
            errorString:'bad receiver in ln'
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2054
    ].
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2055
    d0 = 0.0 ifTrue:[
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2056
        ^ Infinity negative
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2057
    ].
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2058
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2059
    "/ initial approx.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2060
    x := d0 ln asQDouble.
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2061
    "/ three more iterations of taylor
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2062
    x := x + (self * (x negated exp)) - 1.0.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2063
    x := x + (self * (x negated exp)) - 1.0.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2064
    x := x + (self * (x negated exp)) - 1.0.
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2065
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2066
    ^ x
4411
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2067
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2068
    "
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2069
     -1 ln
4411
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2070
     1.0 asQDouble ln
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2071
    "
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2072
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2073
    "Created: / 18-06-2017 / 23:32:54 / cg"
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2074
    "Modified (comment): / 19-06-2017 / 19:01:25 / cg"
4411
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2075
!
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2076
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2077
negated
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2078
    ^ self class
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2079
	d0:(self d0) negated
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2080
	d1:(self d1) negated
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2081
	d2:(self d2) negated
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2082
	d3:(self d3) negated
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2083
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2084
    "
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2085
     (QDouble fromFloat:1.0) negated
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2086
     ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) negated asDoubleArray
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2087
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2088
     (((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0))
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2089
     + ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0))) asDoubleArray
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2090
    "
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2091
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2092
    "Created: / 12-06-2017 / 20:14:55 / cg"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2093
    "Modified (comment): / 12-06-2017 / 23:46:57 / cg"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2094
!
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2095
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2096
squared
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2097
%{
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2098
    double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2099
    double p0, p1, p2, p3, p4, p5;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2100
    double q0, q1, q2, q3;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2101
    double s0, s1;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2102
    double t0, t1;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2103
    double t;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2104
    OBJ newQD;
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2105
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2106
    m_two_sqr(p0, a[0], q0);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2107
    t = 2.0 * a[0];
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2108
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2109
    m_two_prod(p1, t, a[1], q1);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2110
    m_two_prod(p2, t, a[2], q2);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2111
    m_two_sqr(p3, a[1], q3);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2112
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2113
    m_two_sum(p1, q0, p1, q0);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2114
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2115
    m_two_sum(q0, q0, q1, q1);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2116
    m_two_sum(p2, p2, p3, p3);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2117
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2118
    m_two_sum(s0, q0, p2, t0);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2119
    m_two_sum(s1, q1, p3, t1);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2120
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2121
    m_two_sum(s1, s1, t0, t0);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2122
    t0 += t1;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2123
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2124
    m_quick_two_sum(s1, s1, t0, t0);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2125
    m_quick_two_sum(p2, s0, s1, t1);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2126
    m_quick_two_sum(p3, t1, t0, q0);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2127
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2128
    p4 = 2.0 * a[0] * a[3];
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2129
    p5 = 2.0 * a[1] * a[2];
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2130
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2131
    m_two_sum(p4, p4, p5, p5);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2132
    m_two_sum(q2, q2, q3, q3);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2133
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2134
    m_two_sum(t0, p4, q2, t1);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2135
    t1 = t1 + p5 + q3;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2136
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2137
    m_two_sum(p3, p3, t0, p4);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2138
    p4 = p4 + q0 + t1;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2139
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2140
    m_renorm5(p0, p1, p2, p3, p4);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2141
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2142
    __qNew_qdReal(newQD, p0, p1, s0, s1);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2143
    RETURN( newQD );
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2144
%}.
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2145
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2146
    "
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2147
     (QDouble fromFloat:4.0) squared
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2148
     (1e20 + (QDouble fromFloat:1.0)) squared
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2149
    "
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2150
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2151
    "Created: / 13-06-2017 / 01:27:58 / cg"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2152
! !
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2153
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2154
!QDouble methodsFor:'printing & storing'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2155
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2156
digitsWithPrecision:precision
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2157
    "generate digits and exponent.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2158
     if precision is >0, that many digits are generated.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2159
     If it is 0 the required number of digits is generated
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2160
     (but never more than the decimalPrecision, which is 65)"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2161
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2162
    |numDigits r exp i d out str|
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2163
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2164
    numDigits := precision+1. "/ number of digits
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2165
    r := self abs.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2166
    self d0 = 0.0 ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2167
	^ { String new:(precision max:1) withAll:$0 . 0 }
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2168
    ].
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2169
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2170
    out := WriteStream on:(String new:precision+5).
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2171
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2172
    "/ determine approx. exponent
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2173
    exp := self d0 abs log10 floor.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2174
    exp < -300 ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2175
	"/ 1e-305 asQDouble
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2176
	r := r * (10.0 raisedToInteger:300).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2177
	r := r / (10.0 raisedToInteger:(exp+300)).
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2178
    ] ifFalse:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2179
	exp > 300 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2180
	    "/ 1e305 asQDouble
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2181
	    "/ lexpr(x,exp) = x * 2 ^ exp
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2182
self halt.
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2183
	    r := r * (2 raisedTo:-53).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2184
	    r := r / (10.0 asQDouble raisedTo: exp).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2185
	    r := r * (2 raisedTo:53).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2186
	] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2187
	    r := r / (10.0 asQDouble raisedTo:exp).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2188
	]
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2189
    ].
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2190
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2191
    "/ Fix exponent if we are off by one
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2192
    (r >= 10.0) ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2193
	r := r / 10.0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2194
	exp := exp + 1.
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2195
    ] ifFalse:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2196
	(r < 1.0) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2197
	    r := r * 10.0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2198
	    exp := exp - 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2199
	]
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2200
    ].
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2201
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2202
    ((r >= 10.0) or:[ r < 1.0 ]) ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2203
	self error:'can''t compute exponent.'.
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2204
    ].
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2205
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2206
    "/
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2207
    "/ Extract the digits
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2208
    "/ notice, that the d1,d2 and d3 components might
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2209
    "/ be negative; therefore characters out of the 0..9 range
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2210
    "/ might be produced here
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2211
    "/
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2212
    i := 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2213
    [ (precision ~~ 0 and:[ i <= numDigits ])
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2214
    or:[ (precision == 0 and:[r d0 ~= 0.0])  ]] whileTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2215
	d := r d0 truncated.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2216
	r := r - d.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2217
	r := r * 10.0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2218
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2219
	out nextPut:($0 + d).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2220
	i := i + 1.
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2221
    ].
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2222
    numDigits := i-1.
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2223
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2224
    str := out contents.
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2225
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2226
    "/ Fix out-of-range digits.
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2227
    numDigits to:2 by:-1 do:[:i |
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2228
	(str at:i) < $0 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2229
	    str at:i-1 put:(str at:i-1) - 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2230
	    str at:i put:(str at:i) + 10.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2231
	] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2232
	    (str at:i) > $9 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2233
		str at:i-1 put:(str at:i-1) + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2234
		str at:i put:(str at:i) - 10.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2235
	    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2236
	].
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2237
    ].
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2238
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2239
    str first <= $0 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2240
	self error:'non-positive leading digit'
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2241
    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2242
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2243
    "/ Round, handle carry
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2244
    (str at:numDigits) >= $5 ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2245
	str at:numDigits-1 put:(str at:numDigits-1) + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2246
	i := numDigits-1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2247
	[i > 1 and:[(str at:i) > $9]] whileTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2248
	    str at:i put:(str at:i) - 10.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2249
	    i := i - 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2250
	    str at:i put:(str at:i) + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2251
	]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2252
    ].
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2253
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2254
    "/ If first digit is 10, shift everything.
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2255
    str first > $9 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2256
	exp := exp + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2257
	str at:1 put:$0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2258
	str := '1',str
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2259
    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2260
    ^ { (str copyTo:numDigits-1) . exp }
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2261
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2262
    "
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2263
     0 asQDouble digitsWithPrecision:1      -> #('0' 0)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2264
     0 asQDouble digitsWithPrecision:0      -> #('0' 0)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2265
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2266
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2267
     1.2345 printfPrintString:'%.4f'
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2268
     1.2345 asQDouble digitsWithPrecision:5 -> #('12345' 0)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2269
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2270
     --- but 1.2345 is not really what you think:
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2271
     1.2345 printfPrintString:'%.20f'
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2272
     1.2345 asQDouble digitsWithPrecision:20 -> #('12344999999999999307' 0)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2273
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2274
     12.345 asQDouble digitsWithPrecision:5 -> #('12345' 1)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2275
     12345 asQDouble digitsWithPrecision:5 -> #('12345' 4)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2276
     12345.1 asQDouble digitsWithPrecision:5 -> #('12345' 4)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2277
     12345.9 asQDouble digitsWithPrecision:5 -> #('12346' 4)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2278
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2279
     1.2345 asQDouble / 10.0 asQDouble
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2280
     1.2345 asQDouble / 10.0
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2281
    "
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2282
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2283
    "Created: / 15-06-2017 / 09:10:01 / cg"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2284
    "Modified: / 16-06-2017 / 10:01:03 / cg"
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2285
!
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2286
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2287
printOn:aStream
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2288
    "return a printed representation of the receiver.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2289
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2290
     Notice:
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2291
	this code was adapted from an ugly piece of c++ code,
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2292
	which was obviously hacked.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2293
	It does need a rework.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2294
	As an alternative, use the printf functions, which should also deal wth QDoubles"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2295
4404
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  2296
    PrintfScanf printf:'%f' on:aStream argument:self.
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2297
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2298
"/    self
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2299
"/        printOn:aStream precision:40 width:0
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2300
"/        fixed:true showPositive:false uppercase:false fillChar:(Character space)
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2301
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2302
    "
4404
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  2303
     (1.2345 asQDouble) printOn:Transcript    . Transcript cr.
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  2304
     (1.2345 asFloat) printOn:Transcript      . Transcript cr.
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  2305
     (1.2345 asLongFloat) printOn:Transcript  . Transcript cr.
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  2306
     (1.2345 asShortFloat) printOn:Transcript . Transcript cr.
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  2307
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2308
     ((QDouble fromFloat:1.2345) / 10.0) printOn:Transcript
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2309
    "
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2310
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2311
    "Created: / 15-06-2017 / 01:51:36 / cg"
4404
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  2312
    "Modified: / 17-06-2017 / 03:30:41 / cg"
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2313
!
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2314
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2315
printOn:aStream precision:precisionIn width:width
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2316
    fixed:fixed showPositive:showPositive uppercase:uppercase fillChar:fillChar
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2317
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2318
    "return a printed representation of the receiver.
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2319
     This is a parametrized entry, which can be used by printf-like functions.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2320
     Notice:
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2321
	this code was adapted from an ugly piece of c++ code,
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2322
	which was obviously hacked.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2323
	It does need a rework.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2324
	As an alternative, use the printf functions, which should also deal wth QDoubles
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2325
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2326
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2327
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2328
     1.2345 asQDouble printString
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2329
     12.345 asQDouble printString
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2330
     12345 asQDouble printString
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2331
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2332
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2333
    |sgn count delta exp precision|
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2334
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2335
"/    self d1 = 0.0 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2336
"/        self d0 printOn:aStream.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2337
"/        ^ self.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2338
"/    ].
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2339
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2340
    count := 0.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2341
    sgn := true.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2342
    exp := 0.
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2343
    precision := precisionIn.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2344
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2345
    self isInfinite ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2346
	self < 0 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2347
	    aStream nextPut:$-.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2348
	    count := 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2349
	] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2350
	    showPositive ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2351
		aStream nextPut:$+.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2352
		count := 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2353
	    ] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2354
		sgn := false.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2355
	    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2356
	].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2357
	uppercase ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2358
	    aStream nextPutAll:'INF'
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2359
	] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2360
	    aStream nextPutAll:'inf'
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2361
	].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2362
	count := count + 3.
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2363
    ] ifFalse:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2364
	self isNaN ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2365
	    uppercase ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2366
		aStream nextPutAll:'NAN'
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2367
	    ] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2368
		aStream nextPutAll:'nan'
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2369
	    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2370
	    count := count + 3.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2371
	] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2372
	    self < 0 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2373
		aStream nextPut:$-.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2374
		count := count + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2375
	    ] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2376
		showPositive ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2377
		    aStream nextPut:$+.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2378
		    count := count + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2379
		] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2380
		    sgn := false.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2381
		].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2382
	    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2383
	    self = 0.0 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2384
		aStream nextPut:$0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2385
		count := count + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2386
		precision > 0 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2387
		    aStream nextPut:$..
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2388
		    count := count + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2389
		    precision timesRepeat:[ aStream nextPut:$0 ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2390
		    count := count + precision.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2391
		].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2392
		self halt.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2393
	    ] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2394
		|off d d_width_extra|
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2396
		"/ non-zero case
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2397
		off := fixed
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2398
			ifTrue:[ 1 + self asFloat abs log10 floor asInteger ]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2399
			ifFalse:[1].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2400
		d := precision + off.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2401
		d_width_extra := d.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2402
		fixed ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2403
		    d_width_extra := 40 max:d.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2404
		].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2405
		"/ highly special case - fixed mode, precision is zero, abs(*this) < 1.0
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2406
		"/ without this trap a number like 0.9 printed fixed with 0 precision prints as 0
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2407
		"/ should be rounded to 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2408
		(fixed and:[ (precision == 0) and:[ (self abs < 1.0) ]]) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2409
		    (self abs >= 0.5) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2410
			aStream nextPut:$1
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2411
		    ] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2412
			aStream nextPut:$0
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2413
		    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2414
		    ^ self
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2415
		].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2416
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2417
		"/ handle near zero to working precision (but not exactly zero)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2418
		(fixed and:[ d <= 0 ]) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2419
		    aStream nextPut:$0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2420
		    (precision > 0) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2421
			aStream nextPut:$. .
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2422
			aStream next:precision put:$0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2423
		    ]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2424
		] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2425
		    "/ default
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2426
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2427
		    |t j|
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2428
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2429
		    t := self digitsWithPrecision:(fixed ifTrue:[d_width_extra] ifFalse:[d])+1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2430
		    exp := t second.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2431
		    t := t first.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2432
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2433
		    fixed ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2434
			"/ fix the string if it's been computed incorrectly
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2435
			"/ round here in the decimal string if required
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2436
			t := self round_string_qd:t at:(d + 1) offset:off.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2437
			precision := t at:3.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2438
			off := t at:2.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2439
			t := t at:1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2440
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2441
			(off > 0) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2442
			    aStream next:off putAll:t startingAt:1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2443
			    (precision > 0) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2444
				aStream nextPut:$. .
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2445
				aStream next:precision-1 putAll:t startingAt:off+1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2446
			    ]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2447
			] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2448
			    aStream nextPutAll:'0.'.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2449
			    (off < 0) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2450
				aStream next:off negated put:$0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2451
			    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2452
			    aStream next:d putAll:t startingAt:0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2453
			]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2454
		    ] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2455
			aStream nextPut:(t at:1).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2456
			(precision > 0) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2457
			    aStream nextPut:$. .
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2458
			].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2459
			aStream next:precision putAll:t startingAt:2.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2460
		    ]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2461
		].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2462
	    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2463
	]
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2464
    ].
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2465
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2466
    "/ trap for improper offset with large values
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2467
    "/ without this trap, output of values of the for 10^j - 1 fail for j > 28
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2468
    "/ and are output with the point in the wrong place, leading to a dramatically off value
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2469
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2470
"/    (fixed and:[ (precision > 0) ]) ifTrue:[
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2471
"/        "/ make sure that the value isn't dramatically larger
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2472
"/        from_string = atof(s.c_str());
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2473
"/
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2474
"/        // if this ratio is large, then we've got problems
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2475
"/        if( fabs( from_string / this->x[0] ) > 3.0 ){
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2476
"/
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2477
"/                int point_position;
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2478
"/                char temp;
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2479
"/
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2480
"/                // loop on the string, find the point, move it up one
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2481
"/                // don't act on the first character
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2482
"/                for(i=1; i < s.length(); i++){
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2483
"/                        if(s[i] == '.'){
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2484
"/                                s[i] = s[i-1] ;
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2485
"/                                s[i-1] = '.' ;
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2486
"/                                break;
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2487
"/                        }
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2488
"/                }
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2489
"/
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2490
"/                from_string = atof(s.c_str());
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2491
"/                // if this ratio is large, then the string has not been fixed
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2492
"/                if( fabs( from_string / this->x[0] ) > 3.0 ){
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2493
"/                        dd_real::error("Re-rounding unsuccessful in large number fixed point trap.") ;
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2494
"/                }
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2495
"/        }
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2496
"/    }
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2497
"/
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2498
    fixed ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2499
      "/ Fill in exponent part
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2500
      aStream nextPut:(uppercase ifTrue:[$E] ifFalse:[$e]).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2501
      aStream print:exp.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2502
    ].
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2503
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2504
    "/ fill in the blanks
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2505
    (delta := width-count) > 0 ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2506
	self halt.
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2507
"/    if (fmt & ios_base::internal) {
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2508
"/      if (sgn)
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2509
"/        s.insert(static_cast<string::size_type>(1), delta, fill);
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2510
"/      else
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2511
"/        s.insert(static_cast<string::size_type>(0), delta, fill);
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2512
"/    } else if (fmt & ios_base::left) {
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2513
"/      s.append(delta, fill);
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2514
"/    } else {
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2515
"/      s.insert(static_cast<string::size_type>(0), delta, fill);
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2516
"/    }
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2517
"/  }
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2518
    ].
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2519
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2520
    "Created: / 15-06-2017 / 02:37:31 / cg"
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2521
    "Modified (comment): / 16-06-2017 / 14:48:30 / cg"
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2522
!
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2523
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2524
printString
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2525
    "return a printed representation of the receiver"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2526
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2527
    ^ String streamContents:[:s | self printOn:s]
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2528
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2529
    "Created: / 12-06-2017 / 23:41:04 / cg"
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2530
    "Modified: / 15-06-2017 / 01:53:46 / cg"
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2531
!
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2532
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2533
round_string_qd:str at:precisionIn offset:offsetIn
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2534
    "returns a triple of: { new-str . new-offset . new-precision }"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2535
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2536
    "/
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2537
    "/ Input string must be all digits or errors will occur.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2538
    "/
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2539
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2540
    |i numDigits offsetOut precisionOut|
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2541
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2542
    numDigits := precisionIn.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2543
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2544
    offsetOut := offsetIn.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2545
    precisionOut := precisionIn.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2546
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2547
    "/ Round, handle carry
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2548
    ((str at:numDigits) >= $5) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2549
	str at:numDigits-1 put:(str at:numDigits-1)+1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2550
	i := numDigits-1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2551
	[ i > 1 and:[ (str at:i) > $9] ] whileTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2552
	    str at:i put:(str at:i)-10.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2553
	    i := i - 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2554
	    str at:i put:(str at:i)+1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2555
	]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2556
    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2557
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2558
    "/ If first digit is 10, shift everything.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2559
    (str at:1) > $9 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2560
	"/ e++; // don't modify exponent here
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2561
	str replaceFrom:2 with:str startingAt:1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2562
	str at:1 put:$1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2563
	str at:2 put:$0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2564
	offsetOut := offsetOut + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2565
	precisionOut := precisionOut + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2566
    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2567
    ^ { (str copyTo:precisionOut) . offsetOut . precisionOut }
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2568
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2569
    "Created: / 16-06-2017 / 10:12:39 / cg"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2570
    "Modified (comment): / 16-06-2017 / 11:22:03 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2571
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2572
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2573
!QDouble methodsFor:'private accessing'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2574
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2575
d0
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2576
    "the most significant (and highest valued) 53 bits of precision"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2577
%{
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2578
    RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[0]) );
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2579
%}
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2580
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2581
    "Created: / 12-06-2017 / 20:15:12 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2582
    "Modified (comment): / 13-06-2017 / 17:59:47 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2583
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2584
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2585
d1
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2586
    "the next most significant (and next highest valued) 53 bits of precision"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2587
%{
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2588
    RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[1]) );
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2589
%}
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2590
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2591
    "Created: / 12-06-2017 / 20:15:12 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2592
    "Modified (comment): / 13-06-2017 / 18:00:00 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2593
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2594
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2595
d2
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2596
%{
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2597
    RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[2]) );
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2598
%}
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2599
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2600
    "Created: / 12-06-2017 / 20:15:29 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2601
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2602
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2603
d3
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2604
    "the least significant (and smallest valued) 53 bits of precision"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2605
%{
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2606
    RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[3]) );
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2607
%}
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2608
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2609
    "Created: / 12-06-2017 / 20:15:32 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2610
    "Modified (comment): / 13-06-2017 / 18:00:18 / cg"
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2611
!
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2612
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2613
renorm
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2614
    "destructive renormalization"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2615
%{
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2616
    double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2617
    double c0, c1, c2, c3;
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2618
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2619
    c0 = a[0];
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2620
    c1 = a[1];
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2621
    c2 = a[2];
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2622
    c3 = a[3];
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2623
    m_renorm4(c0, c1, c2, c3);
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2624
    a[0] = c0;
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2625
    a[1] = c1;
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2626
    a[2] = c2;
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2627
    a[3] = c3;
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2628
    RETURN( self );
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2629
%}.
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2630
    ^ self error.
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2631
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2632
    "
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2633
     (QDouble fromFloat:1.0) renorm
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2634
    "
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2635
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2636
    "Created: / 13-06-2017 / 18:05:33 / cg"
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2637
    "Modified: / 15-06-2017 / 00:12:59 / cg"
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2638
! !
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2639
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2640
!QDouble methodsFor:'testing'!
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2641
4404
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  2642
isFinite
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  2643
    ^ self d0 isFinite
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  2644
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  2645
    "Created: / 17-06-2017 / 03:40:30 / cg"
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  2646
!
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  2647
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2648
isInfinite
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2649
    ^ self d0 isInfinite
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2650
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2651
    "Created: / 15-06-2017 / 01:57:57 / cg"
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2652
!
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2653
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2654
isNaN
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2655
    ^ self d0 isNaN
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2656
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2657
    "Created: / 15-06-2017 / 01:57:35 / cg"
4411
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2658
!
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2659
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2660
isOne
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2661
    ^ self d0 = 1.0
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2662
    and:[ self d1 = 0.0
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2663
    and:[ self d2 = 0.0
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2664
    and:[ self d3 = 0.0 ]]]
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2665
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2666
    "Created: / 18-06-2017 / 23:29:07 / cg"
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2667
!
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2668
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2669
isZero
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2670
    ^ self d0 = 0.0
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2671
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2672
    "Created: / 18-06-2017 / 23:29:25 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2673
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2674
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2675
!QDouble class methodsFor:'documentation'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2676
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2677
version
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2678
    ^ '$Header$'
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2679
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2680
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2681
version_CVS
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2682
    ^ '$Header$'
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2683
! !
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  2684