QDouble.st
author Claus Gittinger <cg@exept.de>
Wed, 27 Nov 2019 11:16:07 +0100
changeset 5306 819725b85a08
parent 5304 f61106094adc
child 5308 d992975959ab
permissions -rw-r--r--
#BUGFIX by exept class: QDouble added: #asLargeFloat #asLongFloat #sign removed: #truncated comment/format in: #asQDouble #truncatedAsFloat changed: #asFloat #exp_withAccuracy: #ln
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
     1
"{ Encoding: utf8 }"
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
     2
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 2017 by eXept Software AG
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
     5
	      All Rights Reserved
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
"{ NameSpace: Smalltalk }"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
LimitedPrecisionReal variableByteSubclass:#QDouble
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:''
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
    20
	classVariableNames:'DefaultPrintFormat E Epsilon FMax FMin InvFact Ln10 Ln2 NaN Pi
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
    21
		QDoubleOne QDoubleZero'
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	poolDictionaries:''
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
	category:'Magnitude-Numbers'
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
!QDouble primitiveDefinitions!
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    27
%{
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    28
#include <stdio.h>
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    29
#include <errno.h>
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    30
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    31
#define __USE_ISOC9X 1
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    32
#define __USE_ISOC99 1
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    33
#include <math.h>
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    34
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
 * 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
    37
 */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    38
#ifndef errno
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    39
 extern errno;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    40
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    41
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    42
#if !defined (__win32__)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    43
# include <locale.h>
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    44
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    45
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    46
#if defined (__aix__)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    47
# include <float.h>
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    48
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    49
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    50
#if defined(__irix__) || defined(__solaris__) || defined(__sunos__)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    51
# include <nan.h>
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    52
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    53
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    54
#if defined(__linux__)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    55
# ifndef NAN
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    56
#  include <bits/nan.h>
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    57
# endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    58
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    59
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    60
#ifdef __win32__
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    61
# ifndef isinf
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    62
#  define isinf(x) \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    63
	((((unsigned int *)(&x))[0] == 0x00000000) && \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    64
	 ((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000))
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    65
# endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    66
#endif
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
#if defined(__x86__) || defined(__x86_64__)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    69
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    70
# ifndef _FPU_EXTENDED
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    71
#  define _FPU_EXTENDED 0x0300
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    72
# endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    73
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    74
# ifndef _FPU_DOUBLE
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    75
#  define _FPU_DOUBLE 0x0200
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    76
# endif
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
# if defined( __win32__ ) && (defined( __BORLANDC__ ) || defined( __VISUALC__ ))
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
#  define fpu_fix_start(old_cw_ptr)\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    81
    {\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    82
	*old_cw_ptr = _control87(0, 0); \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    83
	_control87(_FPU_DOUBLE, _FPU_EXTENDED);\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    84
    }
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
#  define fpu_fix_end(old_cw_ptr)\
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
	_control87(*old_cw_ptr, _FPU_EXTENDED);\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    89
    }
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
# else // assume MINGW, GCC or CLANG
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    92
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    93
#  ifndef _FPU_GETCW
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    94
#   define _FPU_GETCW(x) asm volatile ("fnstcw %0":"=m" (x));
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    95
#  endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    96
#  ifndef _FPU_SETCW
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    97
#   define _FPU_SETCW(x) asm volatile ("fldcw %0": :"m" (x));
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
    98
#  endif
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
#  define fpu_fix_start(old_cw_ptr)\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   101
    {\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   102
	volatile unsigned short cw, new_cw;\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   103
	_FPU_GETCW(cw);\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   104
	new_cw = (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE;\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   105
	_FPU_SETCW(new_cw);\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   106
	*old_cw_ptr = cw;\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   107
    }
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
#  define fpu_fix_end(old_cw_ptr)\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   110
    {\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   111
	volatile unsigned short cw = *old_cw_ptr;\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   112
	_FPU_SETCW(cw);\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   113
    }
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
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   118
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   119
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   120
struct qd_real {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   121
    double x[4];    /* The Components. */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   122
};
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   123
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   124
struct __quadDoubleStruct {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   125
	STX_OBJ_HEADER
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   126
#ifdef __NEED_DOUBLE_ALIGN
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   127
	__FILLTYPE_DOUBLE f_filler;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   128
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   129
	double d_quadDoubleValue[4];
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   130
};
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
#define __QuadDoubleInstPtr(obj)      ((struct __quadDoubleStruct *)(__objPtr(obj)))
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   133
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   134
#ifndef __isQuadDouble
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   135
# define __isQuadDouble(o) \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   136
	(__Class(o) == @global(QuadDouble))
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   137
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   138
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   139
#ifndef __qIsQuadDouble
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   140
# define __qIsQuadDouble(o) \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   141
	(__qClass(o) == @global(QuadDouble))
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   142
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   143
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   144
#define __qNew_qdReal(newQD, d0,d1,d2,d3) { \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   145
    __qNew(newQD, sizeof(struct __quadDoubleStruct)); \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   146
    __stx_setClass(newQD, QDouble);                \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   147
    __QuadDoubleInstPtr(newQD)->d_quadDoubleValue[0] = d0;   \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   148
    __QuadDoubleInstPtr(newQD)->d_quadDoubleValue[1] = d1;   \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   149
    __QuadDoubleInstPtr(newQD)->d_quadDoubleValue[2] = d2;   \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   150
    __QuadDoubleInstPtr(newQD)->d_quadDoubleValue[3] = d3;   \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   151
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   152
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   153
// sigh: not all compilers (borland) support inline functions;
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   154
// therefore we have to use macros...
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   155
// sigh2: c-macros are unhygienic - to avoid catching/hiding variable bindings,
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   156
// use different names in each macros (i.e. a_xxx)
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   157
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   158
// qd_real(c0, c1, c2, c3);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   159
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   160
#define _QD_SPLITTER 134217729.0               // = 2^27 + 1
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   161
#define _QD_SPLIT_THRESH 6.69692879491417e+299 // = 2^996
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   162
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   163
#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
   164
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   165
    double s_1 = (a_1) + (b_1);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   166
    (err_1) = (b_1) - (s_1 - (a_1));\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   167
    (rslt_1) = s_1; \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   168
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   169
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   170
#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
   171
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   172
    double s_2 = (a_2) - (b_2);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   173
    (err_2) = ((a_2) - s_2) - (b_2);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   174
    (rslt_2) = s_2;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   175
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   176
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   177
#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
   178
{\
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   179
    double s_3 = (a_3) + (b_3);\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   180
    double v_3 = s_3 - (a_3);\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   181
    (err_3) = ((a_3) - (s_3 - v_3)) + ((b_3) - v_3);\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   182
    (rslt_3) = s_3;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   183
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   184
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   185
/* Computes fl(a-b) and err(a-b).  */
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   186
#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
   187
{\
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   188
    double s_4 = (a_4) - (b_4);\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   189
    double bb_4 = s_4 - (a_4);\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   190
    (err_4) = ((a_4) - (s_4 - bb_4)) - ((b_4) + bb_4);\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   191
    (rslt_4) = s_4;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   192
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   193
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   194
#define m_three_sum(a_5, b_5, c_5)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   195
{ \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   196
    double t1_5, t2_5, t3_5; \
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   197
    m_two_sum(t1_5, (a_5), (b_5), t2_5); \
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   198
    m_two_sum((a_5), (c_5), t1_5, t3_5); \
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   199
    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
   200
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   201
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   202
#define m_three_sum2(a_6, b_6, c_6)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   203
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   204
    double t1_6, t2_6, t3_6;\
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   205
    m_two_sum(t1_6, (a_6), (b_6), t2_6);\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   206
    m_two_sum((a_6), (c_6), t1_6, t3_6);\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   207
    (b_6) = t2_6 + t3_6;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   208
}
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
#ifndef QD_FMS
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   211
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   212
/* Computes high word and lo word of a */
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   213
#define m_split(a_7, hi_7, lo_7)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   214
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   215
    double temp_7;\
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   216
    double thi_7, tlo_7;\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   217
    if ((a_7) > _QD_SPLIT_THRESH || (a_7) < -_QD_SPLIT_THRESH) {\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   218
	(a_7) *= 3.7252902984619140625e-09;\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   219
	temp_7 = _QD_SPLITTER * (a_7);\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   220
	thi_7 = temp_7 - (temp_7 - (a_7));\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   221
	tlo_7 = (a_7) - thi_7;\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   222
	thi_7 *= 268435456.0;\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   223
	tlo_7 *= 268435456.0;\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   224
    } else {\
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   225
	temp_7 = _QD_SPLITTER * (a_7);\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   226
	thi_7 = temp_7 - (temp_7 - (a_7));\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   227
	tlo_7 = (a_7) - thi_7;\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   228
    }\
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   229
    (hi_7) = thi_7; \
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   230
    (lo_7) = tlo_7; \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   231
}
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
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   234
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   235
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   236
#ifdef QD_FMS
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   237
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   238
/* Computes fl(a*b) and err(a*b). */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   239
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   240
#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
   241
{\
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   242
    double p_8 = (a_8) * (b_8);\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   243
    err_8 = QD_FMS((a_8), (b_8), p_8);\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   244
    rslt_8 = p_8; \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   245
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   246
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   247
#else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   248
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   249
#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
   250
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   251
    double a_hi_8, a_lo_8, b_hi_8, b_lo_8;\
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   252
    double p_8 = (a_8) * (b_8);\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   253
    m_split(a_8, a_hi_8, a_lo_8);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   254
    m_split(b_8, b_hi_8, b_lo_8);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   255
    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
   256
    rslt_8 = p_8; \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   257
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   258
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   259
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   260
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   261
#ifdef QD_FMS
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   262
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   263
#define m_two_sqr(rslt_9, a_9, err_9)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   264
{\
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   265
    double p_9 = (a_9) * (a_9);\
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   266
    err_9 = QD_FMS((a_9), (a_9), p_9);\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   267
    rslt_9 = p_9;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   268
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   269
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   270
#else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   271
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   272
#define m_two_sqr(rslt_9, a_9, err_9)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   273
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   274
    double hi_9, lo_9;\
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   275
    double q_9 = (a_9) * (a_9);\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   276
    m_split(a_9, hi_9, lo_9);\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   277
    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
   278
    rslt_9 = q_9;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   279
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   280
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   281
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   282
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   283
#define m_renorm4(c0_10, c1_10, c2_10, c3_10)\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   284
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   285
    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
   286
\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   287
    if (! isinf(c0_10)) { \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   288
\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   289
	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
   290
	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
   291
	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
   292
\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   293
	s0_10 = c0_10;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   294
	s1_10 = c1_10;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   295
	if (s1_10 != 0.0) {\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   296
	     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
   297
	    if (s2_10 != 0.0) {\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   298
		 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
   299
	    } else {\
4420
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
	    }\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   302
	} else {\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   303
	    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
   304
	    if (s1_10 != 0.0) {\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   305
		 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
   306
	    } else {\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   307
		 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
   308
	    }\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   309
	}\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   310
\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   311
	c0_10 = s0_10;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   312
	c1_10 = s1_10;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   313
	c2_10 = s2_10;\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   314
	c3_10 = s3_10;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   315
    }\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   316
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   317
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   318
#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
   319
{\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   320
    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
   321
\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   322
    if (! isinf(c0_11)) { \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   323
	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
   324
	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
   325
	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
   326
	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
   327
\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   328
	s0_11 = c0_11; \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   329
	s1_11 = c1_11; \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   330
\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   331
	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
   332
	if (s1_11 != 0.0) { \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   333
	    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
   334
	    if (s2_11 != 0.0) { \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   335
		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
   336
		if (s3_11 != 0.0) {\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   337
		    s3_11 += c4_11; \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   338
		} else {\
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   339
		    s2_11 += c4_11;\
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   340
		}\
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   341
	    } else { \
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   342
		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
   343
		if (s2_11 != 0.0) {\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   344
		    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
   345
		} else { \
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   346
		    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
   347
		} \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   348
	    } \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   349
	} else { \
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   350
	    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
   351
	    if (s1_11 != 0.0) { \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   352
		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
   353
		if (s2_11 != 0.0) {\
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   354
		    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
   355
		} else { \
4420
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
		} \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   358
	    } else { \
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   359
		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
   360
		if (s1_11 != 0.0) { \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   361
		    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
   362
		} else { \
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   363
		    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
   364
		} \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   365
	    } \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   366
	} \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   367
 \
4420
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   368
	c0_11 = s0_11; \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   369
	c1_11 = s1_11; \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   370
	c2_11 = s2_11; \
2ec5ce5062eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
   371
	c3_11 = s3_11; \
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   372
    } \
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   373
}
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
%}
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
!QDouble primitiveFunctions!
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   379
%{
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   380
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   381
#if 0
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   382
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   383
/*********** Basic Functions ************/
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   384
/* 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
   385
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   386
quick_two_sum(double a, double b, double *errPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   387
  double s = a + b;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   388
  *errPtr = b - (s - a);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   389
  return s;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   390
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   391
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   392
/* 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
   393
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   394
quick_two_diff(double a, double b, double *errPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   395
  double s = a - b;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   396
  *errPtr = (a - s) - b;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   397
  return s;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   398
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   399
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   400
/* Computes fl(a+b) and err(a+b).  */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   401
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   402
two_sum(double a, double b, double *errPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   403
  double s = a + b;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   404
  double bb = s - a;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   405
  *errPtr = (a - (s - bb)) + (b - bb);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   406
  return s;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   407
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   408
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   409
/* Computes fl(a-b) and err(a-b).  */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   410
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   411
two_diff(double a, double b, double *errPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   412
  double s = a - b;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   413
  double bb = s - a;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   414
  *errPtr = (a - (s - bb)) - (b + bb);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   415
  return s;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   416
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   417
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   418
#ifndef QD_FMS
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   419
/* Computes high word and lo word of a */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   420
inline void
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   421
split(double a, double *hiPtr, double *loPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   422
  double temp;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   423
  if (a > _QD_SPLIT_THRESH || a < -_QD_SPLIT_THRESH) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   424
    a *= 3.7252902984619140625e-09;  // 2^-28
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   425
    temp = _QD_SPLITTER * a;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   426
    *hiPtr = temp - (temp - a);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   427
    *loPtr = a - *hiPtr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   428
    *hiPtr *= 268435456.0;          // 2^28
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   429
    *loPtr *= 268435456.0;          // 2^28
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   430
  } else {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   431
    temp = _QD_SPLITTER * a;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   432
    *hiPtr = temp - (temp - a);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   433
    *loPtr = a - *hiPtr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   434
  }
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   435
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   436
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   437
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   438
/* Computes fl(a*b) and err(a*b). */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   439
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   440
two_prod(double a, double b, double *errPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   441
#ifdef QD_FMS
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
  *errPtr = QD_FMS(a, b, p);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   444
  return p;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   445
#else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   446
  double a_hi, a_lo, b_hi, b_lo;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   447
  double p = a * b;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   448
  split(a, &a_hi, &a_lo);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   449
  split(b, &b_hi, &b_lo);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   450
  *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
   451
  return p;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   452
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   453
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   454
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   455
/* 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
   456
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   457
two_sqr(double a, double *errPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   458
#ifdef QD_FMS
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   459
  double p = a * a;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   460
  *errPtr = QD_FMS(a, a, p);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   461
  return p;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   462
#else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   463
  double hi, lo;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   464
  double q = a * a;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   465
  split(a, &hi, &lo);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   466
  *errPtr = ((hi * hi - q) + 2.0 * hi * lo) + lo * lo;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   467
  return q;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   468
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   469
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   470
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   471
/* Computes the nearest integer to d. */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   472
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   473
nint(double d) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   474
  if (d == floor(d))
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   475
    return d;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   476
  return floor(d + 0.5);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   477
}
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
/* Computes the truncated integer. */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   480
inline double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   481
aint(double d) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   482
  return (d >= 0.0) ? floor(d) : ceil(d);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   483
}
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
inline void
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   486
renorm4(double *c0Ptr, double *c1Ptr, double *c2Ptr, double *c3Ptr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   487
  double s0, s1, s2 = 0.0, s3 = 0.0;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   488
  double c0 = *c0Ptr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   489
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   490
  if (isinf(c0)) return;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   491
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   492
  s0 = quick_two_sum(*c2Ptr, *c3Ptr, c3Ptr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   493
  s0 = quick_two_sum(*c1Ptr, s0, c2Ptr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   494
  c0 = quick_two_sum(c0, s0, c1Ptr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   495
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   496
  s0 = c0;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   497
  s1 = *c1Ptr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   498
  if (s1 != 0.0) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   499
    s1 = quick_two_sum(s1, *c2Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   500
    if (s2 != 0.0)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   501
      s2 = quick_two_sum(s2, *c3Ptr, &s3);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   502
    else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   503
      s1 = quick_two_sum(s1, *c3Ptr, &s2);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
  } else {
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
    s0 = quick_two_sum(s0, *c2Ptr, &s1);
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   506
    if (s1 != 0.0)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   507
      s1 = quick_two_sum(s1, *c3Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   508
    else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   509
      s0 = quick_two_sum(s0, *c3Ptr, &s1);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   510
  }
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
  *c0Ptr = s0;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   513
  *c1Ptr = s1;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   514
  *c2Ptr = s2;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   515
  *c3Ptr = s3;
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
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   518
inline void
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   519
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
   520
  double s0, s1, s2 = 0.0, s3 = 0.0;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   521
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   522
  if (isinf(*c0Ptr)) return;
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 = quick_two_sum(*c3Ptr, *c4Ptr, c4Ptr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   525
  s0 = quick_two_sum(*c2Ptr, s0, c3Ptr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   526
  s0 = quick_two_sum(*c1Ptr, s0, c2Ptr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   527
  *c0Ptr = quick_two_sum(*c0Ptr, s0, c1Ptr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   528
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   529
  s0 = *c0Ptr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   530
  s1 = *c1Ptr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   531
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   532
  s0 = quick_two_sum(*c0Ptr, *c1Ptr, &s1);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   533
  if (s1 != 0.0) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   534
    s1 = quick_two_sum(s1, *c2Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   535
    if (s2 != 0.0) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   536
      s2 =quick_two_sum(s2, *c3Ptr, &s3);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   537
      if (s3 != 0.0)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   538
	s3 += *c4Ptr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   539
      else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   540
	s2 += *c4Ptr;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   541
    } else {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   542
      s1 = quick_two_sum(s1, *c3Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   543
      if (s2 != 0.0)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   544
	s2 = quick_two_sum(s2, *c4Ptr, &s3);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   545
      else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   546
	s1 = quick_two_sum(s1, *c4Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   547
    }
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   548
  } else {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   549
    s0 = quick_two_sum(s0, *c2Ptr, &s1);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   550
    if (s1 != 0.0) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   551
      s1 = quick_two_sum(s1, *c3Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   552
      if (s2 != 0.0)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   553
	s2 = quick_two_sum(s2, *c4Ptr, &s3);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   554
      else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   555
	s1 = quick_two_sum(s1, *c4Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   556
    } else {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   557
      s0 = quick_two_sum(s0, *c3Ptr, &s1);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   558
      if (s1 != 0.0)
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   559
	s1 = quick_two_sum(s1, *c4Ptr, &s2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   560
      else
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   561
	s0 = quick_two_sum(s0, *c4Ptr, &s1);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   562
    }
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   563
  }
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
  *c0Ptr = s0;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   566
  *c1Ptr = s1;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   567
  *c2Ptr = s2;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   568
  *c3Ptr = s3;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   569
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   570
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   571
inline void
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   572
three_sum(double *aPtr, double *bPtr, double *cPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   573
  double t1, t2, t3;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   574
  t1 = two_sum(*aPtr, *bPtr, &t2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   575
  *aPtr  = two_sum(*cPtr, t1, &t3);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   576
  *bPtr  = two_sum(t2, t3, cPtr);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   577
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   578
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   579
inline void three_sum2(double *aPtr, double *bPtr, double *cPtr) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   580
  double t1, t2, t3;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   581
  t1 = two_sum(*aPtr, *bPtr, &t2);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   582
  *aPtr  = two_sum(*cPtr, t1, &t3);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   583
  *bPtr = t2 + t3;
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   584
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   585
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   586
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   587
#if 0
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   588
/* These are provided to give consistent
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   589
   interface for double with double-double and quad-double. */
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   590
inline void
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   591
sincosh(double t, double &sinh_t, double &cosh_t) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   592
  sinh_t = sinh(t);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   593
  cosh_t = cosh(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
sqr(double t) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   598
  return t * t;
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 double
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   602
to_double(double a) {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   603
    return 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
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   606
inline int
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   607
to_int(double a)    {
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   608
    return static_cast<int>(a);
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   609
}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   610
#endif
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   611
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   612
%}
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
   613
! !
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   614
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   615
!QDouble class methodsFor:'documentation'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   616
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   617
copyright
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   618
"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   619
 COPYRIGHT (c) 2017 by eXept Software AG
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   620
	      All Rights Reserved
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   621
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   622
 This software is furnished under a license and may be used
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
 only in accordance with the terms of that license and with the
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   624
 inclusion of the above copyright notice.   This software may not
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   625
 be provided or otherwise made available to, or used by, any
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   626
 other person.  No title to or ownership of the software is
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   627
 hereby transferred.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   628
"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   629
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   630
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   631
documentation
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   632
"
4391
f2ece85e1ae3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
   633
    ATTENTION: ongoing, unfinished work.
4450
c832d7890dda #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4447
diff changeset
   634
    No warranty that this works correctly...
4391
f2ece85e1ae3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
   635
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   636
    QDoubles represent rational numbers with extended, but still limited precision.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   637
4451
1550f45dc062 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4450
diff changeset
   638
    In contrast to Floats (which use the C-compiler's native 64bit 'double' format),
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
   639
    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
   640
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   641
    Representation:
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   642
        QDoubles use 4 IEEE doubles, each keeping 53 bits of precision.
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   643
        A qDouble's value is the sum of those 4 doubles,
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   644
        and a qDouble keeps this unevaluated sum as its state.
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
   645
        (due to overlap and rounding, the final precision is less than 53*4)
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   646
        The exponent range is still the double exponent range,
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
   647
        but the number of mantissa bits is rougly multiplied by 4.
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   648
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
    Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   650
    The number of decmal digits:
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   651
        QDouble decimalPrecision     -> 61
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   652
        LongFloat decimalPrecision   -> 19
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   653
        Float decimalPrecision       -> 16
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   654
        ShortFloat decimalPrecision  -> 7
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   655
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   656
    The number of bits:
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   657
        QDouble precision            -> 204
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   658
        LongFloat precision          -> 64
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   659
        Float precision              -> 53
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   660
        ShortFloat precision         -> 24
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   661
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   662
    Notice:
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   663
        when assigning a converted double precision number as in:
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   664
            qd := 1.0 asQDouble.
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   665
        you still get only a regular double precision approximation to 0.1
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   666
        because the error is already inherit in the double.
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   667
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   668
        For a full precision constant, you (currently) need to convert from a string
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   669
        (because the compilers do not know about them, yet):
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   670
            qd := QDouble readFrom:'0.1'.
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   671
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   672
        To see the error of the double precision version, compute:
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   673
            (0.1 asQDouble) - (QDouble readFrom:'0.1') 
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   674
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   675
    [author:]
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   676
        Claus Gittinger
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   677
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   678
    [see also:]
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   679
        Number
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   680
        Float ShortFloat LongFloat
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   681
        Fraction FixedPoint Integer Complex
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
   682
        FloatArray DoubleArray
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   683
"
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   684
!
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   685
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   686
examples
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   687
"
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   688
  Floats, LongFloats suffer from loosing bits:
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   689
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   690
     (Float readFrom:'0.3333333333333333333333333333333333333333333333333333333333')
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   691
    -(Float readFrom:'0.333333333333333333333333333333333333333333333333333333333')
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   692
	-> 0.0
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   693
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   694
       (Float readFrom:'0.3333333333333333333333333333333333333333333333333333333333')
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   695
     = (Float readFrom:'0.333333333333333333333333333333333333333333333333333333333')
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   696
	-> true
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   697
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   698
       (Float readFrom:'0.33333333333333333333333333333333333333333333333333333333333333333333')
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   699
     = (Float readFrom:'0.3333333333333333333333333333333333333333333333333333333333333333333')
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   700
	-> true
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   701
1000 0110 1000 0101 1000 0101 1000 0101 1000 0101 1000 0101 1101 0101 0011 1111
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   702
       (Float readFrom:'0.3333333333333333333333333333333333333333333333333333333333')
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   703
     = (Float readFrom:'0.3333333333333333333333333333333333333333333333333333333333333333333')
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   704
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   705
     (LongFloat readFrom:'0.3333333333333333333333333333333333333333333333333333333333')
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   706
    -(LongFloat readFrom:'0.333333333333333333333333333333333333333333333333333333333')
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   707
	-> 0.0
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   708
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   709
      (LongFloat readFrom:'0.3333333333333333333333333333333333333333333333333333333333')
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   710
    = (LongFloat readFrom:'0.333333333333333333333333333333333333333333333333333333333')
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   711
	-> 0.0
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   712
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   713
 (QDouble readFrom:'0.3333333333333333333333333333333333333333333333333333333333')
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   714
-(QDouble readFrom:'0.333333333333333333333333333333333333333333333333333333333')
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   715
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   716
 (QDouble readFrom:'0.33333333333333333333333333333333333333333333333333333333333')
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   717
-(QDouble readFrom:'0.3333333333333333333333333333333333333333333333333333333333')
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   718
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   719
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   720
 (QDouble readFrom:'0.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333')
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   721
-(QDouble readFrom:'0.3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333')
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   722
"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   723
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   724
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   725
!QDouble class methodsFor:'instance creation'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   726
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   727
basicNew
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   728
    "return a new quad-precision double - here we return 0.0
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   729
     Notice that numbers are usually NOT created this way ...
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   730
     It's implemented here to allow things like binary store & load
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   731
     of floats. (but even this support will go away eventually, it's not
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   732
     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
   733
     totally different representation - so floats should be
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   734
     binary stored in a device independent format."
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   735
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   736
%{  /* NOCONTEXT */
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   737
#ifdef __SCHTEAM__
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
    ERROR("trying to instantiate a quad double");
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   739
#else
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   740
    OBJ newFloat;
4404
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
   741
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   742
    __qNew(newFloat, sizeof(struct __quadDoubleStruct));
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   743
    __stx_setClass(newFloat, QDouble);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   744
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[0] = 0.0;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   745
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[1] = 0.0;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   746
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[2] = 0.0;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   747
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[3] = 0.0;
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   748
    RETURN (newFloat);
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   749
#endif /* not SCHTEAM */
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
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   753
     self basicNew
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   754
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   755
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   756
    "Created: / 12-06-2017 / 16:00:38 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   757
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   758
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   759
d0:d0 d1:d1 d2:d2 d3:d3
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   760
    "return a new quad-precision double from individual double components"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   761
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   762
%{  /* NOCONTEXT */
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   763
#ifdef __SCHTEAM__
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   764
    ERROR("trying to instantiate a quad double");
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   765
#else
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   766
    OBJ newQD;
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   767
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   768
    if (__isFloatLike(d0)
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   769
     && __isFloatLike(d1)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   770
     && __isFloatLike(d2)
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   771
     && __isFloatLike(d3)) {
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   772
	__qNew_qdReal(newQD, __floatVal(d0), __floatVal(d1),
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   773
			     __floatVal(d2), __floatVal(d3));
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   774
	RETURN (newQD);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   775
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   776
#endif
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   777
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   778
    self error:'invalid argument'
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   779
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   780
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   781
     self d0: 3.141592653589793116e+00
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   782
	  d1: 1.224646799147353207e-16
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   783
	  d2: -2.994769809718339666e-33
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   784
	  d3: 1.112454220863365282e-49
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   785
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   786
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   787
    "Created: / 12-06-2017 / 20:17:14 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   788
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   789
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   790
fromDoubleArray:aDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   791
    "return a new quad-precision double from coercing a double array"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   792
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   793
%{  /* NOCONTEXT */
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   794
#ifdef __SCHTEAM__
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   795
    ERROR("trying to instantiate a quad double");
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   796
#else
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   797
    OBJ newQD;
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   798
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   799
    if (__isDoubleArray(aDoubleArray)) {
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   800
	__qNew_qdReal(newQD,
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   801
		    __DoubleArrayInstPtr(aDoubleArray)->d_element[0],
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   802
		    __DoubleArrayInstPtr(aDoubleArray)->d_element[1],
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   803
		    __DoubleArrayInstPtr(aDoubleArray)->d_element[2],
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   804
		    __DoubleArrayInstPtr(aDoubleArray)->d_element[3]);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   805
	RETURN (newQD);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   806
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   807
#endif
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   808
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   809
    self error:'invalid argument'
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   810
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
    "
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   812
     self fromDoubleArray(DoubleArray
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   813
				with: 3.141592653589793116e+00
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   814
				with: 1.224646799147353207e-16
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   815
				with: -2.994769809718339666e-33
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   816
				with: 1.112454220863365282e-49)
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   817
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   818
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   819
    "Created: / 12-06-2017 / 18:25:32 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   820
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   821
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   822
fromFloat:aFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   823
    "return a new quad-precision double from coercing aFloat"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   824
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   825
%{  /* NOCONTEXT */
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   826
#ifdef __SCHTEAM__
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   827
    ERROR("trying to instantiate a quad double");
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   828
#else
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   829
    double dVal;
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   830
    OBJ newFloat;
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   831
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   832
    if (__isFloatLike(aFloat)) {
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   833
	dVal = __floatVal(aFloat);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   834
    } else if (__isShortFloat(aFloat)) {
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   835
	dVal = __shortFloatVal(aFloat);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   836
    } else {
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   837
	goto badArg;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   838
    }
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   839
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   840
    __qNew(newFloat, sizeof(struct __quadDoubleStruct));
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   841
    __stx_setClass(newFloat, QDouble);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   842
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[0] = dVal;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   843
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[1] = 0.0;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   844
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[2] = 0.0;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   845
    __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[3] = 0.0;
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   846
    RETURN (newFloat);
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   847
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   848
badArg: ;
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   849
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   850
#endif
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   851
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   852
    self error:'invalid argument'
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   853
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   854
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   855
     self fromFloat:1.0
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   856
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   857
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   858
    "Created: / 12-06-2017 / 16:06:54 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   859
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   860
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   861
fromInteger:anInteger
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   862
    "return a new quad-precision double from coercing anInteger"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   863
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   864
%{  /* NOCONTEXT */
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   865
#ifndef __SCHTEAM__
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   866
    OBJ newFloat;
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   867
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   868
    if (__isSmallInteger(anInteger)) {
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   869
	INT iVal = __smallIntegerVal(anInteger);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   870
	double *a;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   871
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   872
	__qNew(newFloat, sizeof(struct __quadDoubleStruct));
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   873
	__stx_setClass(newFloat, QDouble);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   874
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   875
	a = __QuadDoubleInstPtr(newFloat)->d_quadDoubleValue;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   876
	a[1] = 0.0;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   877
	a[2] = 0.0;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   878
	a[3] = 0.0;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   879
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   880
	// need more than 52bits?
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   881
	if ((sizeof(INT) > 52)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   882
	 && ((iVal > 0xFFFFFFFFFFFFF)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   883
	     || (iVal < -0xFFFFFFFFFFFFF))) {
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   884
	    a[0] = (double)(iVal & ~0xFFFFFFFF);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   885
	    a[1] = (double)(iVal & 0xFFFFFFFF);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   886
	    // m_renorm4(a[0], a[1], a[2], a[3]);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   887
	} else {
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   888
	    a[0] = (double)iVal;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   889
	}
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   890
	RETURN (newFloat);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   891
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   892
#endif
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   893
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   894
    ^ super fromInteger:anInteger
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   895
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   896
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   897
     self fromInteger:2
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   898
     self fromInteger:16rFFFFFFFF            -- 32bit 4294967295.0
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   899
     self fromInteger:16rFFFFFFFFFFFF        -- 48bit 281474976710655.0
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   900
     self fromInteger:16rFFFFFFFFFFFFF       -- 52bit 4503599627370495.0
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   901
     self fromInteger:16rFFFFFFFFFFFFFF      -- 56bit 72057594037927935.0
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   902
     self fromInteger:16rFFFFFFFFFFFFFFF     -- 60bit 1152921504606846975.0
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   903
     self fromInteger:16r1FFFFFFFFFFFFFFF    -- 61bit 2305843009213693951.0
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   904
     self fromInteger:16r3FFFFFFFFFFFFFFF    -- 62bit 4611686018427387903.0
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   905
     self fromInteger:16r7FFFFFFFFFFFFFFF    -- 63bit 9223372036854775807.0
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   906
     self fromInteger:16rFFFFFFFFFFFFFFFF    -- 64bit 18446744073709551615.0
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   907
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   908
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   909
    "Created: / 12-06-2017 / 16:10:10 / cg"
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
   910
    "Modified: / 04-07-2017 / 12:51:52 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   911
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   912
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   913
!QDouble class methodsFor:'coercing & converting'!
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   914
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   915
coerce:aNumber
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   916
    "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
   917
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   918
    ^ aNumber asQDouble
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   919
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   920
    "Created: / 12-06-2017 / 17:13:47 / cg"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   921
    "Modified: / 12-06-2017 / 21:09:06 / cg"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   922
! !
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   923
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   924
!QDouble class methodsFor:'constants'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   925
4440
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
   926
NaN
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
   927
    "return a QDouble which represents not-a-Number (i.e. an invalid number)"
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
   928
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
   929
    NaN isNil ifTrue:[
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
   930
	NaN := self d0:(Float NaN) d1:(Float NaN) d2:(Float NaN) d3:(Float NaN)
4440
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
   931
    ].
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
   932
    ^ NaN
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
   933
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
   934
    "Created: / 21-06-2017 / 20:44:57 / cg"
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
   935
!
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
   936
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   937
e
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   938
    "return the constant e as quad precision double.
4433
37d85359188d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4431
diff changeset
   939
     (returns approx. 200 bits of precision)"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   940
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   941
    E isNil ifTrue:[
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
   942
        E := self d0: 2.718281828459045091e+00
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
   943
                  d1: 1.445646891729250158e-16
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
   944
                  d2: -2.127717108038176765e-33
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
   945
                  d3: 1.515630159841218954e-49
4388
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
   946
    ].
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   947
    ^ E
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   948
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   949
    "
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
   950
     self e printfPrintString:'%.61f'  
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
   951
       -> '2.7182818284590452353602874713526624977572470936999595749669676'
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
   952
     Wolfram says:
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
   953
           2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   954
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   955
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   956
    "Created: / 12-06-2017 / 18:29:36 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   957
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   958
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   959
fmax
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   960
    "return the constant e as quad precision double.
4433
37d85359188d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4431
diff changeset
   961
     (returns approx. 200 bits of precision)"
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   962
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   963
    FMax isNil ifTrue:[
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
   964
        FMax := self d0: 1.797693134862314E+308
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
   965
                     d1: 9.97920154767359795037e+291
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
   966
                     d2: 5.53956966280111259858e+275
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
   967
                     d3: 3.07507889307840487279e+259
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   968
    ].
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   969
    ^ FMax
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   970
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   971
    "
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   972
     Float fmax
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   973
     self fmax
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   974
    "
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   975
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   976
    "Created: / 14-06-2017 / 19:14:18 / cg"
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   977
!
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   978
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   979
fmin
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   980
    "return the smallest representable instance of this class"
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   981
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   982
    FMin isNil ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
   983
	FMin := 1.6259745436952323e-260 asQDouble
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   984
    ].
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   985
    ^ FMin
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   986
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   987
    "
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   988
     QDouble fmin
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   989
     Float fmin
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   990
    "
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   991
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   992
    "Created: / 14-06-2017 / 19:14:49 / cg"
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   993
!
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
   994
4411
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   995
infinity
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   996
    ^ Infinity positive
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   997
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   998
    "Created: / 18-06-2017 / 23:41:07 / cg"
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
   999
!
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  1000
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1001
invFact
4436
d296533a3eaa #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4433
diff changeset
  1002
    "table returning 1/n!!
d296533a3eaa #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4433
diff changeset
  1003
     (for taylor series)"
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1004
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1005
    InvFact isNil ifTrue:[
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1006
	InvFact := Array new:15.
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1007
	InvFact at:1 put:(self d0:1.66666666666666657e-01 d1:9.25185853854297066e-18 d2:5.13581318503262866e-34 d3:2.85094902409834186e-50).
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1008
	InvFact at:2 put:(self d0:4.16666666666666644e-02 d1:2.31296463463574266e-18 d2:1.28395329625815716e-34 d3:7.12737256024585466e-51).
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1009
	InvFact at:3 put:(self d0:8.33333333333333322e-03 d1:1.15648231731787138e-19 d2:1.60494162032269652e-36 d3:2.22730392507682967e-53).
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1010
	InvFact at:4 put:(self d0:1.38888888888888894e-03 d1:-5.30054395437357706e-20 d2:-1.73868675534958776e-36 d3:-1.63335621172300840e-52).
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1011
	InvFact at:5 put:(self d0:1.98412698412698413e-04 d1:1.72095582934207053e-22 d2:1.49269123913941271e-40 d3:1.29470326746002471e-58).
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1012
	InvFact at:6 put:(self d0:2.48015873015873016e-05 d1:2.15119478667758816e-23 d2:1.86586404892426588e-41 d3:1.61837908432503088e-59).
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1013
	InvFact at:7 put:(self d0:2.75573192239858925e-06 d1:-1.85839327404647208e-22 d2:8.49175460488199287e-39 d3:-5.72661640789429621e-55).
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1014
	InvFact at:8 put:(self d0:2.75573192239858883e-07 d1:2.37677146222502973e-23 d2:-3.26318890334088294e-40 d3:1.61435111860404415e-56).
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1015
	InvFact at:9 put:(self d0:2.50521083854417202e-08 d1:-1.44881407093591197e-24 d2:2.04267351467144546e-41 d3:-8.49632672007163175e-58).
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1016
	InvFact at:10 put:(self d0:2.08767569878681002e-09 d1:-1.20734505911325997e-25 d2:1.70222792889287100e-42 d3:1.41609532150396700e-58).
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1017
	InvFact at:11 put:(self d0:1.60590438368216133e-10 d1:1.25852945887520981e-26 d2:-5.31334602762985031e-43 d3:3.54021472597605528e-59).
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1018
	InvFact at:12 put:(self d0:1.14707455977297245e-11 d1:2.06555127528307454e-28 d2:6.88907923246664603e-45 d3:5.72920002655109095e-61).
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1019
	InvFact at:13 put:(self d0:7.64716373181981641e-13 d1:7.03872877733453001e-30 d2:-7.82753927716258345e-48 d3:1.92138649443790242e-64).
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1020
	InvFact at:14 put:(self d0:4.77947733238738525e-14 d1:4.39920548583408126e-31 d2:-4.89221204822661465e-49 d3:1.20086655902368901e-65).
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1021
	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
  1022
    ].
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1023
    ^ InvFact
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1024
4436
d296533a3eaa #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4433
diff changeset
  1025
    "
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1026
     1.0 / (3 factorial)  0.166666666666667
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1027
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1028
     1 asQDouble / (3 factorial) - (self invFact at:1)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1029
     1 asQDouble / (4 factorial) - (self invFact at:2)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1030
     1 asQDouble / (5 factorial) - (self invFact at:3)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1031
     1 asQDouble / (6 factorial) - (self invFact at:4)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1032
     1 asQDouble / (7 factorial) - (self invFact at:5)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1033
     1 asQDouble / (8 factorial) - (self invFact at:6)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1034
     1 asQDouble / (9 factorial) - (self invFact at:7)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1035
     1 asQDouble / (10 factorial) - (self invFact at:8)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1036
     1 asQDouble / (11 factorial) - (self invFact at:9)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1037
     1 asQDouble / (12 factorial) - (self invFact at:10)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1038
     1 asQDouble / (13 factorial) - (self invFact at:11)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1039
     1 asQDouble / (14 factorial) - (self invFact at:12)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1040
     1 asQDouble / (15 factorial) - (self invFact at:13)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1041
     1 asQDouble / (16 factorial) - (self invFact at:14)
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1042
     1 asQDouble / (17 factorial) - (self invFact at:15)
4436
d296533a3eaa #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4433
diff changeset
  1043
    "
d296533a3eaa #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4433
diff changeset
  1044
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1045
    "Created: / 19-06-2017 / 02:22:23 / cg"
4436
d296533a3eaa #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4433
diff changeset
  1046
    "Modified (comment): / 20-06-2017 / 13:04:54 / cg"
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1047
!
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1048
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1049
ln10
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1050
    "return the constant e as quad precision double.
4433
37d85359188d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4431
diff changeset
  1051
     (returns approx. 200 bits of precision)"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1052
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1053
    Ln10 isNil ifTrue:[
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1054
        Ln10 := self d0: 2.302585092994045901e+00
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1055
                     d1: -2.170756223382249351e-16
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1056
                     d2: -9.984262454465776570e-33
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1057
                     d3: -4.023357454450206379e-49
4388
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  1058
    ].
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1059
    ^ Ln10
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1060
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1061
    "
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1062
     self ln10 printfPrintString:'%.61f' 
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1063
        -> '2.3025850929940456840179914546843642076011014886287729760333279'
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1064
     Wolfram says:
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1065
            2.30258509299404568401799145468436420760110148862877297603332790096757260967735248023599720508959829834196778404228...
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1066
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1067
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1068
    "Created: / 12-06-2017 / 18:32:29 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1069
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1070
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1071
ln2
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1072
    "return the constant e as quad precision double.
4433
37d85359188d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4431
diff changeset
  1073
     (returns approx. 200 bits of precision)"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1074
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1075
    Ln2 isNil ifTrue:[
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1076
        Ln2 := self d0: 6.931471805599452862e-01
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1077
                    d1: 2.319046813846299558e-17
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1078
                    d2: 5.707708438416212066e-34
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1079
                    d3: -3.582432210601811423e-50
4388
742f099741bf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  1080
    ].
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1081
    ^ Ln2
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1082
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1083
    "
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1084
     self ln2 printfPrintString:'%.61f' 
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1085
        -> '0.6931471805599452709398341558750792990469129794959648865081141'
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1086
     Wolfram says:
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1087
            0.69314718055994530941723212145817656807550013436025525412068000949339362196969471560586332699641868754200148102057...
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1088
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1089
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1090
    "Created: / 12-06-2017 / 18:31:34 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1091
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1092
4411
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  1093
negativeInfinity
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  1094
    ^ Infinity negative
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  1095
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  1096
    "Created: / 18-06-2017 / 23:40:47 / cg"
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  1097
!
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  1098
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1099
pi
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1100
    "return the constant pi as quad precision double.
4433
37d85359188d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4431
diff changeset
  1101
     (returns approx. 200 bits of precision)"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1102
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1103
    Pi isNil ifTrue:[
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1104
        Pi := self d0: 3.141592653589793116e+00
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1105
                   d1: 1.224646799147353207e-16
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1106
                   d2: -2.994769809718339666e-33
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1107
                   d3: 1.112454220863365282e-49
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1108
    ].                                    
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1109
    ^ Pi
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1110
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1111
    "
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1112
     self pi printfPrintString:'%.60f'  
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1113
          '3.141592653589793238462643383279502884197169399375105820974945'
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1114
     Wolfram says:
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1115
           3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1116
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1117
     (QDouble readFrom:'3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253')
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1118
     printfPrintString:'%.60f' 
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1119
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1120
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1121
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1122
    "Created: / 12-06-2017 / 18:27:13 / cg"
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1123
!
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1124
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1125
unity
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1126
    "return the neutral element for multiplication (1.0) as QDouble"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1127
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1128
    QDoubleOne isNil ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1129
	QDoubleOne := 1.0 asQDouble.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1130
    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1131
    ^ QDoubleOne
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1132
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1133
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1134
     self unity
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1135
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1136
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1137
    "Created: / 15-06-2017 / 11:45:22 / cg"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1138
!
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1139
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1140
zero
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1141
    "return the neutral element for addition (0.0) as QDouble"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1142
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1143
    QDoubleZero isNil ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1144
	QDoubleZero := 0.0 asQDouble
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1145
    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1146
    ^ QDoubleZero
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1147
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1148
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1149
     self zero
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1150
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1151
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1152
    "Created: / 15-06-2017 / 11:44:13 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1153
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1154
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1155
!QDouble class methodsFor:'queries'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1156
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1157
defaultPrintPrecision
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1158
    "return the number of decimal digits printed by default"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1159
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1160
    ^ 30
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1161
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1162
    "
5273
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1163
     ShortFloat defaultPrintPrecision  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1164
     Float defaultPrintPrecision       
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1165
     LongFloat defaultPrintPrecision   
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1166
     QDouble defaultPrintPrecision     
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1167
     QuadFloat defaultPrintPrecision   
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1168
     OctaFloat defaultPrintPrecision   
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1169
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1170
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1171
    "Created: / 17-06-2017 / 02:58:51 / cg"
4440
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  1172
    "Modified: / 21-06-2017 / 13:39:08 / cg"
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1173
!
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1174
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1175
epsilon
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1176
    "return the maximum relative spacing of instances of mySelf
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  1177
     (i.e. the value-delta of the least significant bit)
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  1178
     see https://en.wikipedia.org/wiki/Machine_epsilon"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1179
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1180
    "/ ^ 1.2154326714572500565324311366323150942261000827598106963711353e-63
5273
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1181
    Epsilon isNil ifTrue:[
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1182
        Epsilon := self computeEpsilon.
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1183
    ].
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1184
    ^ Epsilon
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1185
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1186
    "
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  1187
     Float epsilon       -> 2.22044604925031E-16  
4440
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  1188
     ShortFloat epsilon  -> 1.19209289550781E-07
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  1189
     LongFloat epsilon   -> 1.0842021724855E-19
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1190
     QDouble epsilon     -> 7.77876909732643E-62 / (1.215432671457250056532e-63 read comment in precision)
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:52:44 / cg"
4443
1a8440a32671 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4442
diff changeset
  1194
    "Modified: / 22-06-2017 / 15:34:56 / 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
numBitsInExponent
5275
e9d0b744512a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5273
diff changeset
  1198
    "answer the number of bits in the exponent.
e9d0b744512a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5273
diff changeset
  1199
     I use regular IEEE doubles to store the value,
e9d0b744512a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5273
diff changeset
  1200
     thus my exponent bits are the same as double's exponent bits"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1201
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1202
    ^ Float numBitsInExponent
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1203
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1204
    "
4963
51f6cd13f43b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
  1205
     1.0 asQDouble numBitsInExponent
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1206
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1207
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1208
    "Created: / 12-06-2017 / 11:11:04 / cg"
4963
51f6cd13f43b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
  1209
    "Modified (comment): / 28-05-2019 / 08:55:04 / Claus Gittinger"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1210
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1211
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1212
numBitsInMantissa
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1213
    "answer the number of bits in the mantissa.
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1214
     Here, a fake number is returned"
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1215
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1216
    ^ (Float numBitsInMantissa - 1) * 4
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1217
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1218
    "
4963
51f6cd13f43b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
  1219
     1.0 asFloat numBitsInMantissa
51f6cd13f43b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
  1220
     1.0 asShortFloat numBitsInMantissa
51f6cd13f43b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
  1221
     1.0 asLongFloat numBitsInMantissa
51f6cd13f43b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
  1222
     1.0 asQDouble numBitsInMantissa
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1223
     1.0 asQDouble class numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1224
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1225
     Float numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1226
     ShortFloat numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1227
     QDouble numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1228
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1229
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1230
    "Created: / 12-06-2017 / 11:13:44 / cg"
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1231
    "Modified (comment): / 20-06-2017 / 11:05:26 / cg"
4963
51f6cd13f43b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4962
diff changeset
  1232
    "Modified (comment): / 28-05-2019 / 09:07:07 / Claus Gittinger"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1233
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1234
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1235
precision
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1236
    "answer the number of bits in the mantissa"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1237
4431
a7e1399f418e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4430
diff changeset
  1238
    "/ subtract some due to overlap in the component numbers
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1239
    "/ actual precision seems to be more like: 
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1240
    "/ ^ (Float precision) * 4 - 3 + 1.
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1241
    "/ but I am a bit conservative here:
4431
a7e1399f418e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4430
diff changeset
  1242
    ^ (Float precision - 2) * 4
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1243
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1244
    "
5273
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1245
     ShortFloat precision  -> 24
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1246
     Float precision       -> 53
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1247
     LongFloat precision   -> 64
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1248
     QDouble precision     -> 204        
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1249
     QuadFloat precision   -> 113
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1250
     OctaFloat precision   -> 237
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1251
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1252
     1.0 class numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1253
     1.0 asShortFloat class numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1254
     1.0 asLongFloat class numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1255
     1.0 asQDouble class numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1256
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1257
     Float numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1258
     ShortFloat numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1259
     QDouble numBitsInMantissa
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1260
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1261
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1262
    "Created: / 12-06-2017 / 18:49:11 / cg"
4431
a7e1399f418e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4430
diff changeset
  1263
    "Modified (comment): / 20-06-2017 / 12:59:00 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1264
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1265
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1266
radix
5057
cc72e91af490 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
  1267
    "answer the radix of a QDouble's exponent
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1268
     This is an IEEE float, which is represented as binary"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1269
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1270
    ^ Float radix
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1271
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1272
    "Created: / 12-06-2017 / 18:50:04 / cg"
5057
cc72e91af490 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
  1273
    "Modified (comment): / 19-07-2019 / 17:28:25 / Claus Gittinger"
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 methodsFor:'arithmetic'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1277
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1278
* aNumber
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1279
    "return the product of the receiver and the argument, aNumber"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1280
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1281
    ^ aNumber productFromQDouble:self
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1282
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1283
    "
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
  1284
     (((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) * (QDouble fromFloat:2.0)) asDoubleArray
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1285
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1286
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1287
    "Created: / 13-06-2017 / 01:00:47 / cg"
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
  1288
    "Modified (comment): / 14-06-2017 / 12:08:50 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1289
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1290
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1291
+ aNumber
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1292
    "return the sum of the receiver and the argument, aNumber"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1293
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1294
    ^ aNumber sumFromQDouble:self
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1295
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1296
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1297
     ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1298
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1299
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1300
    "Created: / 12-06-2017 / 16:17:46 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1301
    "Modified: / 12-06-2017 / 23:06:22 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1302
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1303
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1304
- aNumber
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1305
    "return the sum of the receiver and the argument, aNumber"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1306
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1307
    ^ self + (aNumber negated)
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1308
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1309
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1310
     (QDouble fromFloat:1e20) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1311
     ((QDouble fromFloat:1e20) - (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1312
     (QDouble fromFloat:1e-20) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1313
     ((QDouble fromFloat:1e-20) - (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1314
     ((QDouble fromFloat:2.0) - (QDouble fromFloat:1.0)) asDoubleArray
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1315
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1316
     ((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
  1317
     ((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
  1318
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1319
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1320
    "Created: / 12-06-2017 / 23:41:39 / cg"
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1321
    "Modified (comment): / 15-06-2017 / 00:34:41 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1322
!
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1323
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1324
/ aNumber
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1325
    "return the quotient of the receiver and the argument, aNumber"
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1326
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1327
    ^ aNumber quotientFromQDouble:self
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1328
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1329
    "
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1330
     ((QDouble fromFloat:1e20) / (QDouble fromFloat:2.0)) asDoubleArray
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1331
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1332
     ((QDouble fromFloat:1.2345) / (QDouble fromFloat:10.0)) asDoubleArray
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1333
     ((QDouble fromFloat:1.2345) / 10.0) asDoubleArray
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1334
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1335
    "
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1336
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1337
    "Created: / 13-06-2017 / 17:59:09 / cg"
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1338
    "Modified (comment): / 15-06-2017 / 00:14:26 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1339
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1340
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1341
!QDouble methodsFor:'coercing & converting'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1342
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1343
asDoubleArray
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1344
    ^ DoubleArray
5273
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1345
            with:self d0
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1346
            with:self d1
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1347
            with:self d2
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1348
            with:self d3.
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1349
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1350
    "
5273
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1351
     (QDouble fromFloat:1.0) asDoubleArray  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1352
     (1.0 asQDouble + 1e-40) asDoubleArray   
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1353
     (QDouble fromFloat:2.0) asDoubleArray
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1354
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1355
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1356
    "Created: / 12-06-2017 / 18:19:19 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1357
    "Modified (comment): / 13-06-2017 / 17:58:09 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1358
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1359
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1360
asFloat
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1361
    ^ self d0 + self d1
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1362
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1363
    "
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1364
     (QDouble fromFloat:1.0) asFloat  -> 1.0
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1365
     (QDouble fromFloat:2.0) asFloat  -> 2.0
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1366
     (2.0 asQDouble + 1e-14) asFloat  -> 2.00000000000001
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1367
     (2.0 + 1e-14) - 2.0              -> 1.02140518265514E-14
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1368
     (2.0 + 1e-15) - 2.0              -> 8.88178419700125E-16
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1369
     (2.0 + 1e-16) - 2.0              -> 0.0
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1370
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1371
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1372
    "Created: / 12-06-2017 / 18:15:27 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1373
    "Modified: / 13-06-2017 / 17:56:50 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1374
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1375
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1376
asInteger
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1377
    ^ self d0 asInteger
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1378
    + self d1 asInteger
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1379
    + self d2 asInteger
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1380
    + self d3 asInteger
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1381
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1382
    "Created: / 19-06-2017 / 18:07:17 / cg"
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1383
!
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1384
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1385
asLargeFloat
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1386
    ^ (self d0 asLargeFloat precision:self precision) + self d1 + self d2 + self d3
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1387
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1388
    "
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1389
     (QDouble fromFloat:1.0) asLargeFloat    -> 1.000000000000000000000000000000
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1390
     (QDouble fromFloat:2.0) asLargeFloat    -> 2.000000000000000000000000000000
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1391
     (2.0 asQDouble + 1e-14) asLargeFloat    -> 2.000000000000010214051826551440
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1392
     (2.0 asLargeFloat + 1e-14) - 2.0        -> 0.000000000000010214051826551440
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1393
     (2.0  + 1e-14) - 2.0                   -> 1.02140518265514E-14
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1394
     (2.0 asLargeFloat + 1e-14) - 2.0       -> 0.000000000000010214051826551440
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1395
     (2.0 asLargeFloat + 1e-15) - 2.0       -> 0.000000000000000888178419700125
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1396
     (2.0 asLargeFloat + 1e-16) - 2.0       -> 0.0
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1397
     (2QL + 1QL-14) - 2QL                   -> 0.000000000000010000000000000000
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1398
    "
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1399
!
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1400
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1401
asLongFloat
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1402
    ^ self d0 asLongFloat + self d1
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1403
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1404
    "
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1405
     (QDouble fromFloat:1.0) asLongFloat    -> 1.0
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1406
     (QDouble fromFloat:2.0) asLongFloat    -> 2.0
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1407
     (2.0 asQDouble + 1e-14) asLongFloat    -> 2.00000000000001
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1408
     (2.0 asLongFloat + 1e-14) - 2.0        -> 1.00000303177028016E-14
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1409
     (2.0  + 1e-14) - 2.0                   -> 1.02140518265514E-14
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1410
     (2.0 asLargeFloat + 1e-14) - 2.0       -> 0.000000000000010214051826551440
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1411
     (2.0 asLargeFloat + 1e-15) - 2.0       -> 0.000000000000000888178419700125
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1412
     (2.0 asLargeFloat + 1e-16) - 2.0       -> 0.0
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1413
     (2QL + 1QL-14) - 2QL                   -> 0.000000000000010000000000000000
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1414
    "
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1415
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1416
    "Created: / 12-06-2017 / 18:15:27 / cg"
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1417
    "Modified: / 13-06-2017 / 17:56:50 / cg"
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1418
!
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1419
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1420
asQDouble
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1421
    "return a QDouble with same value as myself."
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1422
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1423
    ^ self
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1424
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  1425
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1426
!
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1427
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1428
asTrueFraction
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1429
self halt.
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1430
    ^ self d0 asTrueFraction
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1431
    + self d1 asTrueFraction
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1432
    + self d2 asTrueFraction
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1433
    + self d3 asTrueFraction
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1434
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1435
    "
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1436
     1e10 asTrueFraction        -> 10000000000
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1437
     1e20 asTrueFraction        -> 100000000000000000000
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1438
     (1e20 + 1) asTrueFraction  -> 100000000000000000000 ouch!!
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1439
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1440
     1e10 asQDouble asTrueFraction       -> 10000000000
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1441
     1e20 asQDouble asTrueFraction       -> 100000000000000000000
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1442
     (1e20 asQDouble + 1) asTrueFraction -> 100000000000000000001
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1443
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1444
     (1e40 asQDouble + 1e20 + 1) asTrueFraction -> 10000000000000000303886028427003666890753
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1445
     (1e40 asQDouble + 1e20) asTrueFraction
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1446
    "
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1447
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1448
    "Created: / 20-06-2017 / 11:09:03 / cg"
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1449
!
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1450
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1451
coerce:aNumber
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1452
    "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
  1453
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1454
    ^ aNumber asQDouble
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1455
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1456
    "Created: / 12-06-2017 / 17:13:47 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1457
    "Modified: / 12-06-2017 / 21:09:06 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1458
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1459
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1460
exponent
5275
e9d0b744512a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5273
diff changeset
  1461
    "extract a normalized float's (unbiased) exponent.
e9d0b744512a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5273
diff changeset
  1462
     The returned value depends on the float-representation of
e9d0b744512a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5273
diff changeset
  1463
     the underlying machine and is therefore highly unportable.
e9d0b744512a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5273
diff changeset
  1464
     This is not for general use.
e9d0b744512a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5273
diff changeset
  1465
     This assumes that the mantissa is normalized to
e9d0b744512a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5273
diff changeset
  1466
     0.5 .. 1.0 and the float's value is: mantissa * 2^exp"
e9d0b744512a #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5273
diff changeset
  1467
4430
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1468
    ^ self d0 exponent
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1469
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1470
    "Created: / 20-06-2017 / 11:06:02 / cg"
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1471
!
2abefbc21260 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4427
diff changeset
  1472
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1473
generality
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1474
    "return the generality value - see ArithmeticValue>>retry:coercing:"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1475
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1476
    ^ 95
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1477
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1478
    "Created: / 12-06-2017 / 17:13:14 / cg"
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1479
!
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1480
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1481
mantissa
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1482
    "extract a normalized float's mantissa.
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1483
     The returned value depends on the float-representation of
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1484
     the underlying machine and is therefore highly unportable.
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1485
     This is not for general use.
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1486
     This assumes that the mantissa is normalized to
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1487
     0.5 .. 1.0 and the float's value is mantissa * 2^exp"
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1488
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1489
    "/ fake it here
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1490
    ^ self / (2 raisedTo:self exponent)
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1491
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1492
    "
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1493
     1.0 exponent        -> 1
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1494
     1.0 mantissa        -> 0.5
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1495
     12345.0 exponent    -> 14
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1496
     12345.0 mantissa    -> 0.75347900390625
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1497
     -1.0 exponent       -> 1
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1498
     -1.0 mantissa       -> -0.5
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1499
     -12345.0 exponent   -> 14
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1500
     -12345.0 mantissa   -> -0.75347900390625
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1501
     (1e40 + 1e-40) exponent   -> 133
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1502
     (1e40 + 1e-40) mantissa   -> 0.918354961579912
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1503
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1504
     1.0 asQDouble exponent        -> 1
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1505
     1.0 asQDouble mantissa        -> 0.5
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1506
     12345.0 asQDouble exponent    -> 14
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1507
     12345.0 asQDouble mantissa    -> 0.75347900390625
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1508
     -1.0 asQDouble exponent       -> 1
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1509
     -1.0 asQDouble mantissa       -> -0.5
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1510
     -12345.0 asQDouble exponent   -> 14
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1511
     -12345.0 asQDouble mantissa   -> -0.75347900390625
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1512
     (1e40 + 1e-40) asQDouble exponent   -> 133
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1513
     (1e40 + 1e-40) asQDouble mantissa   -> 0.918354961579912
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1514
    "
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1515
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  1516
    "Created: / 20-06-2017 / 11:06:02 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1517
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1518
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1519
!QDouble methodsFor:'comparing'!
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1520
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1521
< aNumber
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1522
    "return true, if the argument, aNumber is greater than the receiver"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1523
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1524
    ^ aNumber lessFromQDouble:self
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1525
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1526
    "Created: / 13-06-2017 / 16:58:53 / cg"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1527
!
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1528
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1529
= aNumber
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1530
    "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
  1531
5273
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1532
%{
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1533
    if (__Class(aNumber) == QDouble) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1534
        double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1535
        double *b = __QuadDoubleInstPtr(aNumber)->d_quadDoubleValue;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1536
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1537
        RETURN ((a[0] == b[0]
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1538
                && a[1] == b[1]
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1539
                && a[2] == b[2]
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1540
                && a[3] == b[3]) ? true : false);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1541
    }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1542
    if (__Class(aNumber) == Float) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1543
        double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1544
        double b = __floatVal(aNumber);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1545
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1546
        RETURN ((a[0] == b
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1547
                && a[1] == 0.0
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1548
                && a[2] == 0.0
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1549
                && a[3] == 0.0) ? true : false);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1550
    }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1551
    if (__isSmallInteger(aNumber)) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1552
        double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1553
        double b = (double)(__intVal(aNumber));
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1554
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1555
        RETURN ((a[0] == b
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1556
                && a[1] == 0.0
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1557
                && a[2] == 0.0
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1558
                && a[3] == 0.0) ? true : false);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1559
    }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1560
%}.
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1561
    ^ aNumber equalFromQDouble:self
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1562
5273
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1563
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1564
     1.0 asQDouble = 1.0 asQDouble 
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1565
     1.0 asQDouble = 1.0           
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1566
     1.0 asQDouble = 1           
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1567
     1.0 asQDouble = 2           
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1568
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  1569
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1570
    "Created: / 13-06-2017 / 17:12:09 / cg"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1571
! !
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1572
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1573
!QDouble methodsFor:'double dispatching'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1574
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1575
differenceFromFloat:aFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1576
    "aFloat - self"
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1577
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1578
    ^ aFloat + (self negated)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1579
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1580
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1581
     1.0 - (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1582
     1e20 - (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1583
     (1.0 - (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1584
     (1e20 - (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1585
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1586
     (1.0 - (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1587
     (1e20 - (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1588
     (1e20 - (QDouble fromFloat:1.0) + 1e-20) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1589
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1590
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1591
    "Created: / 12-06-2017 / 23:38:05 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1592
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1593
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1594
differenceFromQDouble:aQDouble
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1595
    "aQDouble - self"
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1596
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1597
    ^ aQDouble + (self negated)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1598
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1599
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1600
     1.0 - (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1601
     1e20 - (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1602
     (1.0 - (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1603
     (1e20 - (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1604
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1605
     (1.0 - (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1606
     (1e20 - (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1607
     (1e20 - (QDouble fromFloat:1.0) + 1e-20) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1608
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1609
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1610
    "Created: / 12-06-2017 / 23:38:19 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1611
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1612
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1613
equalFromQDouble:aQDouble
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1614
%{
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1615
    if (__Class(aQDouble) == QDouble) {
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1616
	double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1617
	double *b = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1618
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1619
	RETURN ((a[0] == b[0]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1620
		&& a[1] == b[1]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1621
		&& a[2] == b[2]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1622
		&& a[3] == b[3]) ? true : false);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1623
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1624
%}.
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1625
    ^ (aQDouble d0 = self d0)
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1626
    and:[ (aQDouble d1 = self d1)
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1627
    and:[ (aQDouble d2 = self d2)
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1628
    and:[ (aQDouble d3 = self d3) ]]]
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1629
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1630
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1631
     (QDouble fromFloat:1.0) = (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1632
     (QDouble fromFloat:1.0) = 1.0
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1633
     1.0 = (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1634
   "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1635
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1636
    "Created: / 13-06-2017 / 03:01:19 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1637
    "Modified: / 13-06-2017 / 18:01:52 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1638
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1639
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1640
lessFromQDouble:aQDouble
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1641
    "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
  1642
     Return true if aQDouble < self"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1643
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1644
%{
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1645
    if (__Class(aQDouble) == QDouble) {
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1646
	double *a = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1647
	double *b = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1648
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1649
	// now compare if a < b!
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1650
	RETURN
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1651
	    ((a[0] < b[0] ||
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1652
	      (a[0] == b[0] && (a[1] < b[1] ||
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1653
		(a[1] == b[1] && (a[2] < b[2] ||
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1654
		  (a[2] == b[2] && a[3] < b[3])))))) ? true : false);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1655
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1656
%}.
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1657
    ^ super lessFromQDouble:aQDouble
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1658
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1659
    "
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1660
     (1.0 + 1e-40) > 1.0
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1661
     ((QDouble fromFloat:1.0) + (QDouble fromFloat:1e-40)) > (QDouble fromFloat:1.0)
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1662
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1663
     (QDouble fromFloat:1.0) > (QDouble fromFloat:1.0)
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1664
     (QDouble fromFloat:1.1) > (QDouble fromFloat:1.0)
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1665
     (QDouble fromFloat:1.0) > 1.0
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1666
     (QDouble fromFloat:1.1) > 1.0
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1667
     1.0 > (QDouble fromFloat:1.0)
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1668
   "
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1669
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1670
    "Created: / 13-06-2017 / 17:07:47 / cg"
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
productFromFloat: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
    if (__isFloatLike(aFloat)) {
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1676
	double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1677
	double b = __floatVal(aFloat);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1678
	double p0, p1, p2, p3;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1679
	double q0, q1, q2;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1680
	double s0, s1, s2, s3, s4;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1681
	OBJ newQD;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1682
	int savedCV;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1683
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1684
	fpu_fix_start(&savedCV);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1685
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1686
	m_two_prod(p0, a[0], b, q0);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1687
	m_two_prod(p1, a[1], b, q1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1688
	m_two_prod(p2, a[2], b, q2);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1689
	p3 = a[3] * b;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1690
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1691
	s0 = p0;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1692
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1693
	m_two_sum(s1, q0, p1, s2);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1694
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1695
	m_three_sum(s2, q1, p2);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1696
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1697
	m_three_sum2(q1, q2, p3);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1698
	s3 = q1;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1699
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1700
	s4 = q2 + p2;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1701
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1702
	m_renorm5(s0, s1, s2, s3, s4);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1703
	fpu_fix_end(&savedCV);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1704
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1705
	__qNew_qdReal(newQD, s0, s1, s2, s3);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1706
	RETURN( newQD );
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1707
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1708
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1709
    ^ super productFromFloat:aFloat.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1710
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1711
    "
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1712
     loosing bits here:
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1713
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1714
     (1e20+1.0)*2.0
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1715
     (1e20+1.0)*1e20
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1716
     (1e40+1.0)*2.0
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1717
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1718
     but not here:
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1719
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1720
     (1.0 asQDouble) * 2.0
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1721
     ((1e20 asQDouble) + (1.0)) * 2.0
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1722
     ((1e20 asQDouble) + (1.0)) * 100.0    10000000000000000000100.0
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1723
     ((1e20 asQDouble) + (1.0)) * 1000.0
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1724
     ((1e40 asQDouble) + (1.0)) * 2.0
4387
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1725
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1726
     2.0 * (QDouble fromFloat:1.0)
4387
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1727
     2.0 * (QDouble fromFloat:3.0)
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1728
     (QDouble fromFloat:2.0) * (QDouble fromFloat:3.0)
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1729
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1730
     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
  1731
     2.0 * QDouble ln2 DoubleArray(1.38629436111989 4.6380936276926E-17 1.14154168768324E-33 -7.16486442120362E-50)
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1732
     QDouble ln2 * 2.0
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1733
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1734
     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
  1735
     ((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
  1736
     ((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
  1737
     (QDouble fromFloat:2.0) * ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) DoubleArray(2E+20 4E+20 0.0 0.0)
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1738
4387
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1739
     (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
  1740
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1741
     (2.0 * (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1742
     (1e20 * (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1743
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1744
     (1e20 * (QDouble fromFloat:1.0) * 1e-20) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1745
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1746
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1747
    "Created: / 13-06-2017 / 00:58:56 / cg"
4421
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1748
    "Modified: / 19-06-2017 / 16:48:18 / cg"
2603ea13cb5c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4420
diff changeset
  1749
    "Modified (comment): / 19-06-2017 / 18:11:43 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1750
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1751
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1752
productFromQDouble:aQDouble
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1753
%{
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1754
    if (__Class(aQDouble) == QDouble) {
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1755
	double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1756
	double *b = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1757
	OBJ newQD;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1758
	int savedCV;
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  1759
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  1760
#define QD_IEEE_MUL
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  1761
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  1762
#ifndef QD_IEEE_MUL
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1763
	// sloppy
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1764
	double p0, p1, p2, p3, p4, p5;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1765
	double q0, q1, q2, q3, q4, q5;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1766
	double t0, t1;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1767
	double s0, s1, s2;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1768
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1769
	fpu_fix_start(&savedCV);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1770
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1771
	m_two_prod(p0, a[0], b[0], q0);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1772
	// fprintf(stderr, "%f * %f -> %f, %f\n", a[0], b[0], p0, q0);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1773
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1774
	m_two_prod(p1, a[0], b[1], q1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1775
	m_two_prod(p2, a[1], b[0], q2);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1776
	// fprintf(stderr, "%f * %f -> %f, %f\n", a[0], b[1], p1, q1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1777
	// fprintf(stderr, "%f * %f -> %f, %f\n", a[1], b[0], p2, q2);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1778
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1779
	m_two_prod(p3, a[0], b[2], q3);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1780
	m_two_prod(p4, a[1], b[1], q4);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1781
	m_two_prod(p5, a[2], b[0], q5);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1782
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1783
	// fprintf(stderr, "%f * %f -> %f, %f\n", a[0], b[2], p3, q3);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1784
	// fprintf(stderr, "%f * %f -> %f, %f\n", a[1], b[1], p4, q4);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1785
	// fprintf(stderr, "%f * %f -> %f, %f\n", a[2], b[0], p5, q5);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1786
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1787
	/* Start Accumulation */
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1788
	m_three_sum(p1, p2, q0);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1789
	// fprintf(stderr, "mul7: after three_sum: p1:%e p2:%e q0:%e\n", p1, p2, q0);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1790
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1791
	/* Six-Three Sum  of p2, q1, q2, p3, p4, p5. */
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1792
	m_three_sum(p2, q1, q2);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1793
	// fprintf(stderr, "mul8: after three_sum: p2:%e q1:%e q2:%e\n", p2, q1, q2);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1794
	m_three_sum(p3, p4, p5);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1795
	// fprintf(stderr, "mul9: after three_sum: p3:%e p4:%e p5:%e\n", p3, p4, p5);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1796
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1797
	/* compute (s0, s1, s2) = (p2, q1, q2) + (p3, p4, p5). */
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1798
	m_two_sum(s0, p2, p3, t0);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1799
	// fprintf(stderr, "mul10: after two_sum: s0:%e p2:%e p3:%e t0:%e\n", s0, p2, p3, t0);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1800
	m_two_sum(s1, q1, p4, t1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1801
	// fprintf(stderr, "mul11: after two_sum: s1:%e q1:%e p4:%e t1:%e\n", s1, q1, p4, t1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1802
	s2 = q2 + p5;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1803
	m_two_sum(s1, s1, t0, t0);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1804
	// fprintf(stderr, "mul12: after two_sum: s1:%e s1:%e t0:%e t0:%e\n", s1, s1, t0, t0);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1805
	s2 += (t0 + t1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1806
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1807
	/* O(eps^3) order terms */
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1808
	s1 += a[0]*b[3] + a[1]*b[2] + a[2]*b[1] + a[3]*b[0] + q0 + q3 + q4 + q5;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1809
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1810
	// fprintf(stderr, "before renorm5: p0:%e p2:%e s0:%e s1:%e s2:%e\n", p0, p1, s0, s1, s2);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1811
	m_renorm5(p0, p1, s0, s1, s2);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1812
	// fprintf(stderr, "after renorm5: p0:%e p2:%e s0:%e s1:%e s2:%e\n", p0, p1, s0, s1, s2);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1813
	fpu_fix_end(&savedCV);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1814
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1815
	__qNew_qdReal(newQD, p0, p1, s0, s1);
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  1816
#else
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1817
	// accurate
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1818
	double p0, p1, p2, p3, p4, p5;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1819
	double q0, q1, q2, q3, q4, q5;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1820
	double p6, p7, p8, p9;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1821
	double q6, q7, q8, q9;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1822
	double r0, r1;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1823
	double t0, t1;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1824
	double s0, s1, s2;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1825
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1826
	fpu_fix_start(&savedCV);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1827
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1828
	m_two_prod(p0, a[0], b[0], q0);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1829
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1830
	m_two_prod(p1, a[0], b[1], q1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1831
	m_two_prod(p2, a[1], b[0], q2);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1832
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1833
	m_two_prod(p3, a[0], b[2], q3);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1834
	m_two_prod(p4, a[1], b[1], q4);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1835
	m_two_prod(p5, a[2], b[0], q5);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1836
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1837
	/* Start Accumulation */
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1838
	m_three_sum(p1, p2, q0);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1839
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1840
	/* Six-Three Sum  of p2, q1, q2, p3, p4, p5. */
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1841
	m_three_sum(p2, q1, q2);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1842
	m_three_sum(p3, p4, p5);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1843
	/* compute (s0, s1, s2) = (p2, q1, q2) + (p3, p4, p5). */
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1844
	m_two_sum(s0, p2, p3, t0);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1845
	m_two_sum(s1, q1, p4, t1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1846
	s2 = q2 + p5;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1847
	m_two_sum(s1, s1, t0, t0);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1848
	s2 += (t0 + t1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1849
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1850
	/* O(eps^3) order terms */
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1851
	m_two_prod(p6, a[0], b[3], q6);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1852
	m_two_prod(p7, a[1], b[2], q7);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1853
	m_two_prod(p8, a[2], b[1], q8);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1854
	m_two_prod(p9, a[3], b[0], q9);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1855
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1856
	/* Nine-Two-Sum of q0, s1, q3, q4, q5, p6, p7, p8, p9. */
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1857
	m_two_sum(q0, q0, q3, q3);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1858
	m_two_sum(q4, q4, q5, q5);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1859
	m_two_sum(p6, p6, p7, p7);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1860
	m_two_sum(p8, p8, p9, p9);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1861
	/* Compute (t0, t1) = (q0, q3) + (q4, q5). */
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1862
	m_two_sum(t0, q0, q4, t1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1863
	t1 += (q3 + q5);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1864
	/* Compute (r0, r1) = (p6, p7) + (p8, p9). */
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1865
	m_two_sum(r0, p6, p8, r1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1866
	r1 += (p7 + p9);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1867
	/* Compute (q3, q4) = (t0, t1) + (r0, r1). */
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1868
	m_two_sum(q3, t0, r0, q4);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1869
	q4 += (t1 + r1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1870
	/* Compute (t0, t1) = (q3, q4) + s1. */
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1871
	m_two_sum(t0, q3, s1, t1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1872
	t1 += q4;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1873
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1874
	/* O(eps^4) terms -- Nine-One-Sum */
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1875
	t1 += a[1] * b[3] + a[2] * b[2] + a[3] * b[1] + q6 + q7 + q8 + q9 + s2;
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1876
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1877
	// fprintf(stderr, "before accur-renorm5: p0:%e p1:%e s0:%e t0:%e t1:%e\n", p0, p1, s0, t0, t1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1878
	m_renorm5(p0, p1, s0, t0, t1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1879
	// fprintf(stderr, "after accur-renorm5: p0:%e p1:%e s0:%e t0:%e t1:%e\n", p0, p1, s0, t0, t1);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1880
	fpu_fix_end(&savedCV);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1881
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1882
	__qNew_qdReal(newQD, p0, p1, s0, t0);
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1883
#endif
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  1884
	RETURN( newQD );
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1885
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1886
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1887
    ^ super productFromQDouble:aQDouble.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1888
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1889
    "
4387
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1890
     (QDouble fromFloat:1.0) * 2.0
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1891
     2.0 * (QDouble fromFloat:1.0)
4387
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1892
     (QDouble fromFloat:1.0) * (QDouble fromFloat:2.0)
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1893
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1894
     1e20 * (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1895
     (2.0 * (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1896
     (1e20 * (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1897
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1898
     (1e20 * (QDouble fromFloat:1.0) * 1e-20) asDoubleArray
4392
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
  1899
a64fe2606d82 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4391
diff changeset
  1900
     ( ((QDouble fromFloat:1.0) + (QDouble fromFloat:1e20)) * (QDouble fromFloat:2.0)) asDoubleArray
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1901
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1902
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1903
    "Created: / 13-06-2017 / 01:06:22 / cg"
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  1904
    "Modified: / 05-07-2017 / 11:07:16 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1905
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1906
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1907
quotientFromQDouble:aQDouble
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1908
    "sloppy"
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1909
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1910
    |q0 q1 q2 q3 r|
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1911
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1912
    q0 := aQDouble d0 / self d0.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1913
    "/ 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
  1914
    r := aQDouble - (self * q0).
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1915
    "/ Stdout showCR:('r: %1\n' bindWith:r asDoubleArray).
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1916
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1917
    q1 := r d0 / self d0.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1918
    "/ 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
  1919
    r := r - (self * q1).
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1920
    "/ Stdout showCR:('r: %1\n' bindWith:r asDoubleArray).
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1921
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1922
    q2 := r d0 / self d0.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1923
    "/ 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
  1924
    r := r - (self * q2).
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1925
    "/ Stdout showCR:('r: %1\n' bindWith:r asDoubleArray).
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1926
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1927
    q3 := r d0 / self d0.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1928
    "/ 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
  1929
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1930
    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
  1931
    "/ Stdout showCR:('before renorm: %1\n' bindWith:r asDoubleArray).
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1932
    r renorm.
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1933
    "/ Stdout showCR:('after renorm: %1\n' bindWith:r asDoubleArray).
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1934
    ^ r
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1935
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1936
    "
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1937
     2.0 / (QDouble fromFloat:2.0)
4387
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  1938
     2.0 / (QDouble fromFloat:1.0)
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1939
     1e20 / (QDouble fromFloat:1.0)
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1940
     (2.0 / (QDouble fromFloat:1.0)) asFloat
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1941
     (1e20 / (QDouble fromFloat:1.0)) asFloat
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1942
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1943
     (QDouble fromFloat:2.0) / 2.0
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1944
     (QDouble fromFloat:1e20) / 2.0
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1945
     ((QDouble fromFloat:1.0) / 2.0) asFloat
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1946
     ((QDouble fromFloat:1e20 / 2.0)) asFloat
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1947
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1948
     ((1e20 + (QDouble fromFloat:1.0) + 1e-20) / 2.0) asDoubleArray
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1949
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1950
     ((QDouble fromFloat:10.0) quotientFromQDouble: (QDouble fromFloat:1.234)) asDoubleArray
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1951
     ((QDouble fromFloat:1.234) / (QDouble fromFloat:10.0)) asDoubleArray
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  1952
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1953
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
  1954
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
  1955
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
  1956
(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
  1957
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
  1958
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1959
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
  1960
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
  1961
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1962
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
  1963
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
  1964
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1965
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
  1966
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1967
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
  1968
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
  1969
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
  1970
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1971
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1972
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1973
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  1974
    "Created: / 13-06-2017 / 17:50:35 / cg"
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  1975
    "Modified (comment): / 15-06-2017 / 01:02:05 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1976
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1977
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1978
quotientFromQDouble_accurate:aQDouble   
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1979
    |q0 q1 q2 q3 q4 r|
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1980
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1981
%{
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1982
/* Computes fl(a+b) and err(a+b).  Assumes |a| >= |b|. */
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1983
#define quick_two_sum(s, a, b, err) \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1984
    {                            \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1985
        s = a + b;               \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1986
        err = b - (s - a);       \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1987
    }
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1988
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1989
#define renorm5(c0, c1, c2, c3, c4) \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1990
    { \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1991
      double s0, s1, s2 = 0.0, s3 = 0.0;    \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1992
                                            \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1993
      quick_two_sum(s0, c3, c4, c4);      \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1994
      quick_two_sum(s0, c2, s0, c3);      \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1995
      quick_two_sum(s0, c1, s0, c2);      \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1996
      quick_two_sum(c0, c0, s0, c1);      \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1997
                                          \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1998
      s0 = c0;                            \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  1999
      s1 = c1;                            \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2000
                                          \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2001
      quick_two_sum(s0, c0, c1, s1);      \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2002
      if (s1 != 0.0) {                    \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2003
          quick_two_sum(s1, s1, c2, s2);  \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2004
          if (s2 != 0.0) {                \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2005
              quick_two_sum(s2, s2, c3, s3);      \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2006
              if (s3 != 0.0) {                    \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2007
                  s3 += c4;                       \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2008
              } else {                            \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2009
                  s2 += c4;                       \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2010
              }                                   \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2011
          } else {                                \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2012
              quick_two_sum(s1, s1, c3, s2);      \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2013
              if (s2 != 0.0) {                    \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2014
                  quick_two_sum(s2, s2, c4, s3);  \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2015
              } else {                            \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2016
                  quick_two_sum(s1, s1, c4, s2);  \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2017
              }                                   \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2018
          }                                       \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2019
      } else {                                    \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2020
          quick_two_sum(s0, s0, c2, s1);          \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2021
          if (s1 != 0.0) {                        \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2022
              quick_two_sum(s1, s1, c3, s2);      \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2023
              if (s2 != 0.0) {                    \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2024
                  quick_two_sum(s2, s2, c4, s3);  \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2025
              } else {                            \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2026
                  quick_two_sum(s1, s1, c4, s2);  \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2027
              }                                   \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2028
          } else {                                \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2029
              quick_two_sum(s0, s0, c3, s1);      \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2030
              if (s1 != 0.0) {                    \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2031
                  quick_two_sum(s1, s1, c4, s2);  \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2032
              } else {                            \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2033
                  quick_two_sum(s0, s0, c4, s1);  \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2034
              }                                   \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2035
          }                                       \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2036
      }                                           \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2037
                                                  \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2038
      c0 = s0;                                    \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2039
      c1 = s1;                                    \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2040
      c2 = s2;                                    \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2041
      c3 = s3;                                    \
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2042
    }
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2043
%}.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2044
    q0 := aQDouble d0 / self d0.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2045
    r := aQDouble - (self * q0).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2046
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2047
    q1 := r d0 / self d0.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2048
    r := r - (self * q1).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2049
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2050
    q2 := r d0 / self d0.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2051
    r := r - (self * q2).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2052
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2053
    q3 := r d0 / self d0.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2054
    r := r - (self * q3).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2055
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2056
    q4 := r d0 / self d0.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2057
    q0 isFinite ifTrue:[
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2058
%{
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2059
        double cq0, cq1, cq2, cq3, cq4;
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2060
        cq0 = __floatVal(q0);
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2061
        cq1 = __floatVal(q1);
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2062
        cq2 = __floatVal(q2);
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2063
        cq3 = __floatVal(q3);
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2064
        cq4 = __floatVal(q4);
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2065
        renorm5(cq0, cq1, cq2, cq3, cq4) 
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2066
        {
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2067
            OBJ newQD;
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2068
            __qNew_qdReal(newQD, cq0, cq1, cq2, cq3);
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2069
            RETURN (newQD);
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2070
        }
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2071
#undef quick_two_sum
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2072
#undef renorm5
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2073
%}.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2074
    ].
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2075
    ^ self class d0:q0 d1:0.0 d2:0.0 d3:0.0 
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2076
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2077
    "
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2078
     2.0 / (QDouble fromFloat:2.0)
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2079
     2.0 / (QDouble fromFloat:1.0)
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2080
     1e20 / (QDouble fromFloat:1.0)
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2081
     (2.0 / (QDouble fromFloat:1.0)) asFloat
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2082
     (1e20 / (QDouble fromFloat:1.0)) asFloat
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2083
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2084
     (QDouble fromFloat:2.0) / 2.0
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2085
     (QDouble fromFloat:1e20) / 2.0
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2086
     ((QDouble fromFloat:1.0) / 2.0) asFloat
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2087
     ((QDouble fromFloat:1e20 / 2.0)) asFloat
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2088
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2089
     ((1e20 + (QDouble fromFloat:1.0) + 1e-20) / 2.0) asDoubleArray
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2090
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2091
     ((QDouble fromFloat:10.0) quotientFromQDouble: (QDouble fromFloat:1.234)) asDoubleArray
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2092
     ((QDouble fromFloat:1.234) / (QDouble fromFloat:10.0)) asDoubleArray
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2093
    "
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2094
!
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2095
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2096
quotientFromQDouble_sloppy:aQDouble
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2097
    "sloppy"
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2098
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2099
    |q0 q1 q2 q3 r|
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2100
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2101
    q0 := aQDouble d0 / self d0.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2102
    "/ Stdout showCR:('q0: %1 (a[0]=%2; b[0]=%3)\n' bindWith:q0 with:self d0 with:aQDouble d0).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2103
    r := aQDouble - (self * q0).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2104
    "/ Stdout showCR:('r: %1\n' bindWith:r asDoubleArray).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2105
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2106
    q1 := r d0 / self d0.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2107
    "/ Stdout showCR:('q1: %1 (r[0]=%2; b[0]=%3)\n' bindWith:q1 with:r d0 with:aQDouble d0).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2108
    r := r - (self * q1).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2109
    "/ Stdout showCR:('r: %1\n' bindWith:r asDoubleArray).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2110
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2111
    q2 := r d0 / self d0.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2112
    "/ Stdout showCR:('q2: %1 (r[0]=%2; b[0]=%3)\n' bindWith:q2 with:r d0 with:aQDouble d0).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2113
    r := r - (self * q2).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2114
    "/ Stdout showCR:('r: %1\n' bindWith:r asDoubleArray).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2115
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2116
    q3 := r d0 / self d0.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2117
    "/ Stdout showCR:('q3: %1 (r[0]=%2; b[0]=%3)\n' bindWith:q3 with:r d0 with:aQDouble d0).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2118
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2119
    r := self class d0:q0 d1:q1 d2:q2 d3:q3.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2120
    "/ Stdout showCR:('before renorm: %1\n' bindWith:r asDoubleArray).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2121
    r renorm.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2122
    "/ Stdout showCR:('after renorm: %1\n' bindWith:r asDoubleArray).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2123
    ^ r
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2124
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2125
    "
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2126
     2.0 / (QDouble fromFloat:2.0)
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2127
     2.0 / (QDouble fromFloat:1.0)
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2128
     1e20 / (QDouble fromFloat:1.0)
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2129
     (2.0 / (QDouble fromFloat:1.0)) asFloat
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2130
     (1e20 / (QDouble fromFloat:1.0)) asFloat
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2131
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2132
     (QDouble fromFloat:2.0) / 2.0
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2133
     (QDouble fromFloat:1e20) / 2.0
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2134
     ((QDouble fromFloat:1.0) / 2.0) asFloat
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2135
     ((QDouble fromFloat:1e20 / 2.0)) asFloat
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2136
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2137
     ((1e20 + (QDouble fromFloat:1.0) + 1e-20) / 2.0) asDoubleArray
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2138
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2139
     ((QDouble fromFloat:10.0) quotientFromQDouble: (QDouble fromFloat:1.234)) asDoubleArray
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2140
     ((QDouble fromFloat:1.234) / (QDouble fromFloat:10.0)) asDoubleArray
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2141
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2142
q0: 1.234000e-01 (a[0]=1.234000e+00; b[0]=1.000000e+01)
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2143
a: 1.234000e+00/0.000000e+00/0.000000e+00/0.000000e+00
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2144
b: 1.000000e+01/0.000000e+00/0.000000e+00/0.000000e+00
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2145
(b * q0): 1.234000e+00/-2.775558e-17/0.000000e+00/0.000000e+00
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2146
r: 2.775558e-17/0.000000e+00/0.000000e+00/0.000000e+00
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2147
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2148
q1: 2.775558e-18 (r[0]=2.775558e-17; b[0]=1.000000e+01)
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2149
r: -1.540744e-33/0.000000e+00/0.000000e+00/0.000000e+00
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2150
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2151
q2: -1.540744e-34 (r[0]=-1.540744e-33; b[0]=1.000000e+01)
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2152
r: 8.552847e-50/0.000000e+00/0.000000e+00/0.000000e+00
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2153
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2154
q3: 8.552847e-51 (r[0]=8.552847e-50; b[0]=1.000000e+01)
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2155
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2156
before renorm: 1.234000e-01/2.775558e-18/-1.540744e-34/8.552847e-51
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2157
after renorm: 1.234000e-01/2.775558e-18/-1.540744e-34/8.552847e-51
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2158
1.234/10.0 is: 0.123400 / 0.000000 / -0.000000 / 0.000000
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2159
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2160
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2161
    "
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2162
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2163
    "Created: / 13-06-2017 / 17:50:35 / cg"
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2164
    "Modified (comment): / 15-06-2017 / 01:02:05 / cg"
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2165
!
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2166
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2167
sumFromFloat:aFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2168
%{
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2169
    if (__isFloatLike(aFloat)) {
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2170
	double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2171
	double b = __floatVal(aFloat);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2172
	double c0, c1, c2, c3;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2173
	double e;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2174
	OBJ newQD;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2175
	int savedCV;
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2176
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2177
	fpu_fix_start(&savedCV);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2178
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2179
	m_two_sum(c0, a[0], b, e);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2180
	m_two_sum(c1 ,a[1], e, e);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2181
	m_two_sum(c2, a[2], e, e);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2182
	m_two_sum(c3, a[3], e, e);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2183
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2184
	m_renorm5(c0, c1, c2, c3, e);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2185
	fpu_fix_end(&savedCV);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2186
	__qNew_qdReal(newQD, c0, c1, c2, c3);
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2187
	RETURN( newQD );
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2188
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2189
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2190
    ^ super sumFromFloat:aFloat.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2191
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2192
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2193
     1.0 + (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2194
     1e20 + (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2195
     (1.0 + (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2196
     (1e20 + (QDouble fromFloat:1.0)) asFloat
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2197
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2198
     (1.0 + (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2199
     (1e20 + (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2200
     (1e20 + (QDouble fromFloat:1.0) + 1e-20) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2201
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2202
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2203
    "Created: / 12-06-2017 / 17:16:41 / cg"
4387
879309cae427 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  2204
    "Modified: / 14-06-2017 / 11:43:47 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2205
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2206
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2207
sumFromInteger:anInteger
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2208
    ^ self sumFromFloat:(anInteger asFloat)
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2209
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2210
    "
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2211
     1 + (QDouble fromFloat:1.0)
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2212
     1e20 asInteger + (QDouble fromFloat:1.0)
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2213
     (1 + (QDouble fromFloat:1.0)) asFloat
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2214
     (1e20 asInteger + (QDouble fromFloat:1.0)) asFloat
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2215
    "
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2216
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2217
    "Created: / 03-07-2017 / 10:35:46 / cg"
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2218
!
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2219
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2220
sumFromQDouble:aQDouble
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2221
%{
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2222
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2223
/* s = quick_three_accum(a, b, c) adds c to the dd-pair (a, b).
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2224
 * If the result does not fit in two doubles, then the sum is
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2225
 * output into s and (a,b) contains the remainder.  Otherwise
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2226
 * s is zero and (a,b) contains the sum. */
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2227
# define m_quick_three_accum(q3_outRef, q3_a, q3_b, q3_c) \
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2228
{ \
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2229
    double s0, s;\
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2230
    int za, zb;\
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2231
\
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2232
    m_two_sum(s0, q3_b, q3_c, q3_b); \
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2233
    m_two_sum(s, q3_a, s0, q3_a); \
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2234
\
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2235
    za = (q3_a != 0.0);\
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2236
    zb = (q3_b != 0.0);\
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2237
\
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2238
    if (za && zb) {\
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2239
        q3_outRef = s;\
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2240
    } else {\
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2241
        if (!zb) {\
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2242
            q3_b = q3_a;\
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2243
            q3_a = s;\
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2244
        } else {\
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2245
            q3_a = s;\
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2246
        }\
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2247
        q3_outRef = 0.0;\
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2248
    }\
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2249
}
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2250
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2251
    if (__Class(aQDouble) == QDouble) {
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2252
        double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2253
        double *b = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2254
        OBJ newQD;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2255
        int savedCV;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2256
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2257
#define SLOPPY_ADD
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2258
#ifdef SLOPPY_ADD
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2259
        /* Addition re-organized to minimize
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2260
           data dependency ... unfortunately some compilers are
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2261
           not very smart to do this automatically */
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2262
        double s0, s1, s2, s3;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2263
        double t0, t1, t2, t3;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2264
        double v0, v1, v2, v3;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2265
        double u0, u1, u2, u3;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2266
        double w0, w1, w2, w3;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2267
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2268
        fpu_fix_start(&savedCV);
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2269
        s0 = a[0] + b[0];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2270
        s1 = a[1] + b[1];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2271
        s2 = a[2] + b[2];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2272
        s3 = a[3] + b[3];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2273
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2274
        v0 = s0 - a[0];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2275
        v1 = s1 - a[1];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2276
        v2 = s2 - a[2];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2277
        v3 = s3 - a[3];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2278
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2279
        u0 = s0 - v0;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2280
        u1 = s1 - v1;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2281
        u2 = s2 - v2;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2282
        u3 = s3 - v3;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2283
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2284
        w0 = a[0] - u0;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2285
        w1 = a[1] - u1;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2286
        w2 = a[2] - u2;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2287
        w3 = a[3] - u3;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2288
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2289
        u0 = b[0] - v0;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2290
        u1 = b[1] - v1;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2291
        u2 = b[2] - v2;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2292
        u3 = b[3] - v3;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2293
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2294
        t0 = w0 + u0;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2295
        t1 = w1 + u1;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2296
        t2 = w2 + u2;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2297
        t3 = w3 + u3;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2298
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2299
        m_two_sum(s1, s1, t0, t0);
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2300
        m_three_sum(s2, t0, t1);
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2301
        m_three_sum2(s3, t0, t2);
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2302
        t0 = t0 + t1 + t3;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2303
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2304
        /* renormalize */
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2305
        m_renorm5(s0, s1, s2, s3, t0);
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2306
        fpu_fix_end(&savedCV);
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2307
        __qNew_qdReal(newQD, s0, s1, s2, s3);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2308
#else
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2309
        // ieee_add...
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2310
        int i, j, k;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2311
        double s, t;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2312
        double u, v;   /* double-length accumulator */
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2313
        double x[4] = {0.0, 0.0, 0.0, 0.0};
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2314
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2315
        fpu_fix_start(&savedCV);
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2316
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2317
        i = j = k = 0;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2318
        if (abs(a[i]) > abs(b[j]))
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2319
            u = a[i++];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2320
        else
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2321
            u = b[j++];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2322
        if (abs(a[i]) > abs(b[j]))
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2323
            v = a[i++];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2324
        else
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2325
            v = b[j++];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2326
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2327
        m_quick_two_sum(u, u, v, v);
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2328
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2329
        while (k < 4) {
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2330
            if (i >= 4 && j >= 4) {
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2331
                x[k] = u;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2332
                if (k < 3) {
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2333
                    x[++k] = v;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2334
                }
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2335
                break;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2336
            }
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2337
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2338
            if (i >= 4) {
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2339
                t = b[j++];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2340
            } else if (j >= 4) {
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2341
                t = a[i++];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2342
            } else if (abs(a[i]) > abs(b[j])) {
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2343
                t = a[i++];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2344
            } else {
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2345
                t = b[j++];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2346
            }
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2347
            m_quick_three_accum(s, u, v, t);
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2348
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2349
            if (s != 0.0) {
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2350
                x[k++] = s;
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2351
            }
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2352
        }
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2353
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2354
        /* add the rest. */
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2355
        for (k = i; k < 4; k++) {
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2356
            x[3] += a[k];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2357
        }
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2358
        for (k = j; k < 4; k++) {
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2359
            x[3] += b[k];
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2360
        }
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2361
        m_renorm4(x[0], x[1], x[2], x[3]);
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2362
        fpu_fix_end(&savedCV);
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2363
        __qNew_qdReal(newQD, x[0], x[1], x[2], x[3]);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2364
#endif
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2365
        RETURN(newQD);
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2366
    }
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2367
%}.
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2368
    ^ super sumFromQDouble:aQDouble
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2369
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2370
    "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2371
     (QDouble fromFloat:1.0) + (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2372
     (QDouble fromFloat:1.0) + 1.0
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2373
     1.0 + (QDouble fromFloat:1.0)
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2374
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2375
     ((QDouble fromFloat:1.0) + (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2376
     ((QDouble fromFloat:1.0) + 1.0) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2377
     (1.0 + (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2378
     (1e-20 + (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2379
     (1e20 + (QDouble fromFloat:1.0)) asDoubleArray
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2380
   "
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2381
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2382
    "Created: / 12-06-2017 / 21:15:43 / cg"
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2383
    "Modified: / 03-07-2017 / 23:09:11 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2384
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2385
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2386
!QDouble methodsFor:'inspecting'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2387
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2388
inspectorExtraAttributes
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2389
    "extra (pseudo instvar) entries to be shown in an inspector."
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2390
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2391
    ^ super inspectorExtraAttributes
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2392
	add:'-{doubles}' -> [ self asDoubleArray printString ];
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2393
	yourself
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2394
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2395
    "Created: / 12-06-2017 / 23:43:05 / cg"
4478
010c2cd47df3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  2396
    "Modified (format): / 18-07-2017 / 19:54:48 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2397
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2398
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2399
!QDouble methodsFor:'mathematical functions'!
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2400
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2401
exp
4440
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2402
    "/ the exp_sloppy code is the algorithm from the original C++ qd package;
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2403
    "/ however, it is inexact in the 37th digit
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2404
    "/ Therefore, use the inherited code, which is slow, but more precise.
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2405
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2406
    ^ super exp
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2407
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2408
    "
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2409
     2.0 exp                -> 7.38905609893065
4440
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2410
     2.0 asQDouble exp      -> 7.38905609893065022723
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2411
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2412
     2 asQDouble exp printfPrintString:'%70.68f'
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2413
	    -> 7.389056098930650227230427460575007813180315570551847324087127822432669
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2414
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2415
     actual result:
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2416
	    -> 7.3890560989306502272304274605750078131803155705518473240871278225225737960790577633843124850791217947737531612654...
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2417
4440
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2418
    "
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2419
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2420
    "Created: / 19-06-2017 / 01:49:32 / cg"
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2421
    "Modified (comment): / 22-06-2017 / 14:32:53 / cg"
4440
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2422
!
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2423
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2424
exp_sloppy
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2425
    "/ this is the algorithm from the qd C++ package;
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2426
    "/ however, it is inexact in the 37th digit
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2427
    "/
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2428
    "/ the inherited exp code is much slower, but more precise.
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2429
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2430
    "/ Strategy:  We first reduce the size of x by noting that
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2431
    "/
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2432
    "/  exp(kr + m * log(2)) = 2^m * exp(r)^k
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2433
    "/
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2434
    "/     where m and k are integers.  By choosing m appropriately
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2435
    "/     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
  2436
    "/     evaluated using the familiar Taylor series.  Reducing the
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2437
    "/     argument substantially speeds up the convergence.       */
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2438
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2439
    |k inv_k d0 m mul_pwr2 mul2 r
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  2440
     s p t thresh eps i|
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  2441
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  2442
    eps := 1.21543267145725e-63. "/ = 2^-209.
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  2443
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2444
    d0 := self d0.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2445
    (d0 <= -709.0) ifTrue:[
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2446
        ^ 0.0 asQDouble.
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  2447
    ].
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  2448
    (d0 >= 709.0) ifTrue:[
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2449
        ^ Infinity positive
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2450
    ].
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2451
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2452
    (d0 = 0.0) ifTrue:[
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2453
        ^ 1.0 asQDouble.
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  2454
    ].
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2455
    (d0 = 1.0) ifTrue:[
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2456
        self isOne ifTrue:[
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2457
            ^ self class e
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2458
        ].
4413
e3ee8be3627f oops - cvs messed it
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  2459
    ].
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2460
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2461
    k := 65536.0. "/ 1.0 ldexp:16. 
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2462
    inv_k := 1.0 / k.
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2463
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2464
    m := (d0 / Float ln2 + 0.5) floor.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2465
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2466
    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
  2467
    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
  2468
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2469
    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
  2470
    thresh := inv_k * eps.
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2471
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2472
    p := r squared.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2473
    s := r + (mul_pwr2 value:p value:0.5).
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2474
    i := 1.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2475
    [
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2476
        p := p * r.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2477
        t := p * (self class invFact at:i).
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2478
        i := i+1.
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2479
        s := s + t.
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2480
    ] doWhile:[ (t asFloat abs > thresh) and:[i < 10] ].
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2481
4427
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2482
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2483
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2484
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2485
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2486
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2487
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2488
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2489
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2490
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2491
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2492
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2493
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2494
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2495
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2496
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2497
    s := (mul2 value:s) + s squared.
15d052db3e6e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  2498
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2499
    s := s + 1.0.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2500
    ^ s ldexp:m asInteger.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2501
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2502
    "
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2503
     1.0 exp -> 2.71828182845905
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2504
     1.0 asQDouble exp        -> 2.718281828459045235360287471353
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2505
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2506
     10.0 exp -> 22026.4657948067
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2507
     10.0 asQDouble exp -> 22026.46579480671651695790064528
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2508
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2509
     Wolfram:
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2510
        22026.46579480671651695790064528424436635351261855678107423...
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2511
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2512
     1000.0 exp -> INF
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2513
     1000.0 asQDouble exp -> 22026.46579480671651695790064528
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2514
    "
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2515
4440
590547e4049d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4439
diff changeset
  2516
    "Created: / 21-06-2017 / 13:48:27 / cg"
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2517
!
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2518
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2519
exp_withAccuracy:epsilon
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2520
    "compute e^x of the receiver using a taylor series approximation.
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2521
     This method is only invoked for limitedPrecisionReal classes, which do not compute
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2522
     exp themself (i.e. QDouble)"
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2523
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2524
    "/ uses taylor series:
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2525
    "/             x    x^2   x^3
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2526
    "/  e^x = 1 + --- + --- + --- ...
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2527
    "/             1!!    2!!    3!!
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2528
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2529
    |x2 n num den approx delta|
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2530
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2531
    x2 := self asLimitedPrecisionReal squared.
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2532
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2533
    num := x2.
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2534
    den := self coerce:2.
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2535
    n := 3.
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2536
    approx := self + 1 + (num / den).
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2537
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2538
    [
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2539
        n := n + 1.
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2540
        den := den * n.
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2541
        num := num * self.
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2542
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2543
        delta := num / den.
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2544
        "/ Transcript showCR:delta.
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2545
        delta isNaN ifTrue:[self halt:'nan when dividing for delta'. num / den].
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2546
        delta = 0 ifTrue:[self halt:'zero delta'].
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2547
        approx := approx + delta.
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2548
    ] doUntil:[delta abs <= epsilon].
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2549
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2550
    ^ approx
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2551
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2552
    "
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2553
     wolfram:
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2554
                                                        7.389056098930650227230427460575007813180315570551847324087
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2555
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2556
     2 asQDouble exp_withAccuracy:QDouble epsilon       7.38905609893065022723
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2557
     2 asQDouble exp_withAccuracy:LongFloat epsilon     7.38905609893065022723
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2558
     2 asQDouble exp_withAccuracy:Float epsilon         7.38905609893065022489
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2559
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2560
                                                        2.718281828459045235360287471352662497757247093699959574966...
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2561
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2562
     1 asQDouble exp_withAccuracy:QDouble epsilon       2.71828182845904523536
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2563
     1 asQDouble exp_withAccuracy:LongFloat epsilon     2.71828182845904523536
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2564
     1 asQDouble exp_withAccuracy:Float epsilon         2.71828182845904522671
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2565
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2566
                                                        1.7392749415205010473946813036112352261479840577250084... × 10^18
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2567
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2568
     42 asQDouble exp_withAccuracy:QDouble epsilon      NAN
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2569
     42 asQDouble exp_withAccuracy:LongFloat epsilon    1.73927494152050104739e18
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2570
     42 asQDouble exp_withAccuracy:Float epsilon        1.73927494152050104739e18
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2571
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2572
    "
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2573
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2574
    "Created: / 04-07-2017 / 11:58:26 / cg"
4522
4c586a5945df #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4519
diff changeset
  2575
    "Modified: / 10-10-2017 / 16:03:34 / cg"
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2576
!
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2577
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2578
ldexp:exp
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2579
    "multiply the receiver by an integral power of 2.
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2580
     I.e. return self * (2 ^ exp).
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2581
     This is also the operation to reconstruct the original float from its
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2582
     mantissa and exponent: (f mantissa ldexp:f exponent) = f"
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2583
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2584
    ^ self class
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2585
        d0:(self d0 ldexp:exp)
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2586
        d1:(self d1 ldexp:exp)
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2587
        d2:(self d2 ldexp:exp)
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2588
        d3:(self d3 ldexp:exp)
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2589
    "
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2590
     |f| f := 1 asQDouble. (f mantissa ldexp:f exponent) -> 1.0 
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2591
     |f| f := (1e40 asQDouble + 1e-40). (f mantissa ldexp:f exponent) -> (1e40 asQDouble + 1e-40) 
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2592
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2593
     1.0 ldexp:16            -> 65536.0
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2594
     1.0 asQDouble ldexp:16  -> 65536.0
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2595
     1.0 ldexp:100           -> 1.26765060022823E+30
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2596
     1.0 asQDouble ldexp:100 -> 1.26765060022823E+30
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2597
    "
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2598
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2599
    "Created: / 19-06-2017 / 01:43:35 / cg"
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2600
!
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2601
4411
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2602
ln
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2603
    "return the natural logarithm of myself.
4445
5267aa3922e4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4444
diff changeset
  2604
     Raises an exception, if the receiver is less or equal to zero.
5267aa3922e4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4444
diff changeset
  2605
5267aa3922e4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4444
diff changeset
  2606
     Not sure if this is really faster than using a taylor right away:
5267aa3922e4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4444
diff changeset
  2607
     the three exp-computations at the end are done in qDouble and are tailors themself..."
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2608
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2609
    |d0 x|
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2610
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2611
    "/ ^ super ln.
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2612
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2613
    d0 := self d0.
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2614
    d0 = 1.0 ifTrue:[
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2615
        self isOne ifTrue:[ ^ self class zero ].
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2616
    ].
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2617
    d0 > 0.0 ifTrue:[
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2618
        "/ initial approx.
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2619
        x := d0 ln asQDouble.
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2620
        "/ three more iterations of newton...
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2621
        x := x + (self / (x exp)) - 1.0.
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2622
        x := x + (self / (x exp)) - 1.0.
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2623
        x := x + (self / (x exp)) - 1.0.
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2624
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2625
        ^ x
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2626
    ].
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2627
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2628
    "/ now done via trapInfinity; was:
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2629
    "/ d0 = 0.0 ifTrue:[
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2630
    "/     ^ Infinity negative
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2631
    "/ ].
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2632
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2633
    "/ if you need -INF for a zero receiver, try Number trapInfinity:[...]
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2634
    ^ self class
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2635
        raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal])
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2636
        receiver:self
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2637
        selector:#ln
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2638
        arguments:#()
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2639
        errorString:'bad receiver in ln (not strictly positive)'
4411
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2640
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2641
    "
4412
ad38e01db51a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  2642
     -1 ln
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2643
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2644
     -1.0 asQDouble ln
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2645
     0.0 asQDouble ln
4411
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2646
     1.0 asQDouble ln
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2647
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2648
     3.0 ln printfPrintString:'%60.58lf'
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2649
            -> 1.0986122886681097821082175869378261268138885498046875000000'
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2650
                                ^
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2651
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2652
     3.0 asQDouble ln printfPrintString:'%60.58f'
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2653
            -> 1.0986122886681096913952452369225257046474905578227494517347
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2654
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2655
     3.0 asQDouble ln printfPrintString:'%70.68f'
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2656
            -> 1.09861228866810969139524523692252570464749055782274945173469433364779
4443
1a8440a32671 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4442
diff changeset
  2657
1a8440a32671 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4442
diff changeset
  2658
     (3.0 asQDouble ln_withAccuracy:1e-64) printfPrintString:'%70.68f'
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2659
               1.09861228866810969139524523692252570464749055782274945173469433364475
4443
1a8440a32671 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4442
diff changeset
  2660
     (3.0 asQDouble ln_withAccuracy:1e-100) printfPrintString:'%70.68f'
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2661
              '1.098612288668109691395245236922525704647490557822749451734694333656909'
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2662
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2663
     actual result:
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  2664
            -> 1.0986122886681096913952452369225257046474905578227494517346943336374942932186089668736157548137320887879700290659...
4411
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
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2667
    "Created: / 18-06-2017 / 23:32:54 / cg"
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2668
    "Modified: / 04-07-2017 / 11:46:27 / cg"
4411
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2669
!
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  2670
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2671
negated
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2672
    ^ self class
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2673
	d0:(self d0) negated
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2674
	d1:(self d1) negated
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2675
	d2:(self d2) negated
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2676
	d3:(self d3) negated
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2677
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2678
    "
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2679
     (QDouble fromFloat:1.0) negated
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2680
     ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) negated asDoubleArray
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2681
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2682
     (((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0))
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2683
     + ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0))) asDoubleArray
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2684
    "
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2685
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2686
    "Created: / 12-06-2017 / 20:14:55 / cg"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2687
    "Modified (comment): / 12-06-2017 / 23:46:57 / cg"
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2688
!
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2689
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2690
sqrt
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2691
    "Return the square root of the receiver"
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2692
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2693
    "this computes a roughly 65 digits precision result,
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2694
     using sqrt from the double as an initial guess"
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2695
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2696
    |guess|
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2697
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2698
    guess := self d0 sqrt asQDouble.
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2699
    ^ self sqrt_withAccuracy:(self epsilon) fromInitialGuess:guess
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2700
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2701
    "FloatD is only correct in roughly 17 digits
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2702
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2703
     2 sqrt printfPrintString:'%50.48f'
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2704
            -> 1.414213562373095145474621858738828450441360473633
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2705
                               ^
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2706
     QDouble gives you much more:
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2707
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2708
     2 asQDouble sqrt printfPrintString:'%50.48f' 
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2709
            -> 1.414213562373095048801688724209698078569671875377
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2710
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2711
     2 asQDouble sqrt printfPrintString:'%60.58f'
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2712
            -> 1.4142135623730950488016887242096980785696718753769480731767'
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2713
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2714
     2 asQDouble sqrt printfPrintString:'%70.68f'
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2715
            -> 1.41421356237309504880168872420969807856967187537694807317667973799602
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2716
5304
f61106094adc #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5288
diff changeset
  2717
     actual digits (wolfram):
5288
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2718
            -> 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309...
cd5e44b99011 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5275
diff changeset
  2719
    "         
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2720
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2721
    "Created: / 22-06-2017 / 13:53:47 / cg"
4447
cbe19db976ec #OTHER by mawalch
mawalch
parents: 4446
diff changeset
  2722
    "Modified: / 22-06-2017 / 17:08:06 / mawalch"
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2723
    "Modified (format): / 03-07-2017 / 12:09:04 / cg"
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2724
!
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2725
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2726
squared
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2727
    "return receiver * receiver"
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2728
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2729
%{
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2730
    double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2731
    double p0, p1, p2, p3, p4, p5;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2732
    double q0, q1, q2, q3;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2733
    double s0, s1;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2734
    double t0, t1;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2735
    double t;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2736
    OBJ newQD;
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2737
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2738
    // code makes use of some symetries to avoid a few multiplications...
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2739
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2740
    m_two_sqr(p0, a[0], q0);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2741
    t = 2.0 * a[0];
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2742
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2743
    m_two_prod(p1, t, a[1], q1);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2744
    m_two_prod(p2, t, a[2], q2);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2745
    m_two_sqr(p3, a[1], q3);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2746
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2747
    m_two_sum(p1, q0, p1, q0);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2748
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2749
    m_two_sum(q0, q0, q1, q1);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2750
    m_two_sum(p2, p2, p3, p3);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2751
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2752
    m_two_sum(s0, q0, p2, t0);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2753
    m_two_sum(s1, q1, p3, t1);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2754
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2755
    m_two_sum(s1, s1, t0, t0);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2756
    t0 += t1;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2757
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2758
    m_quick_two_sum(s1, s1, t0, t0);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2759
    m_quick_two_sum(p2, s0, s1, t1);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2760
    m_quick_two_sum(p3, t1, t0, q0);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2761
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2762
    p4 = 2.0 * a[0] * a[3];
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2763
    p5 = 2.0 * a[1] * a[2];
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2764
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2765
    m_two_sum(p4, p4, p5, p5);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2766
    m_two_sum(q2, q2, q3, q3);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2767
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2768
    m_two_sum(t0, p4, q2, t1);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2769
    t1 = t1 + p5 + q3;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2770
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2771
    m_two_sum(p3, p3, t0, p4);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2772
    p4 = p4 + q0 + t1;
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2773
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2774
    m_renorm5(p0, p1, p2, p3, p4);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2775
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2776
    __qNew_qdReal(newQD, p0, p1, s0, s1);
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2777
    RETURN( newQD );
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2778
%}.
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2779
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2780
    "
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2781
     (QDouble fromFloat:4.0) squared
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2782
     (1e20 + (QDouble fromFloat:1.0)) squared
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2783
    "
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2784
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2785
    "Created: / 13-06-2017 / 01:27:58 / cg"
4442
ef3082dc3d1c #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4440
diff changeset
  2786
    "Modified: / 22-06-2017 / 14:08:31 / cg"
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2787
! !
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2788
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2789
!QDouble methodsFor:'printing & storing'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2790
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2791
digitsWithPrecision:precision
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2792
    <resource: #obsolete>
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2793
    "generate digits and exponent.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2794
     if precision is >0, that many digits are generated.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2795
     If it is 0 the required number of digits is generated
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2796
     (but never more than the decimalPrecision, which is 65)"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2797
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2798
    |numDigits r exp i d out str|
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2799
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2800
    numDigits := precision+1. "/ number of digits
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2801
    r := self abs.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2802
    self d0 = 0.0 ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2803
	^ { String new:(precision max:1) withAll:$0 . 0 }
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2804
    ].
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2805
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2806
    out := WriteStream on:(String new:precision+5).
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2807
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2808
    "/ determine approx. exponent
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2809
    exp := self d0 abs log10 floor.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2810
    exp < -300 ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2811
	"/ 1e-305 asQDouble
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2812
	r := r * (10.0 raisedToInteger:300).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2813
	r := r / (10.0 raisedToInteger:(exp+300)).
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2814
    ] ifFalse:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2815
	exp > 300 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2816
	    "/ 1e305 asQDouble
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2817
	    "/ lexpr(x,exp) = x * 2 ^ exp
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2818
self halt.
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2819
	    r := r * (2 raisedTo:-53).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2820
	    r := r / (10.0 asQDouble raisedTo: exp).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2821
	    r := r * (2 raisedTo:53).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2822
	] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2823
	    r := r / (10.0 asQDouble raisedTo:exp).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2824
	]
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2825
    ].
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2826
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2827
    "/ Fix exponent if we are off by one
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2828
    (r >= 10.0) ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2829
	r := r / 10.0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2830
	exp := exp + 1.
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2831
    ] ifFalse:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2832
	(r < 1.0) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2833
	    r := r * 10.0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2834
	    exp := exp - 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2835
	]
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2836
    ].
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2837
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2838
    ((r >= 10.0) or:[ r < 1.0 ]) ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2839
	self error:'can''t compute exponent.'.
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2840
    ].
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2841
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2842
    "/
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2843
    "/ Extract the digits
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2844
    "/ notice, that the d1,d2 and d3 components might
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2845
    "/ be negative; therefore characters out of the 0..9 range
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2846
    "/ might be produced here
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2847
    "/
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2848
    i := 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2849
    [ (precision ~~ 0 and:[ i <= numDigits ])
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2850
    or:[ (precision == 0 and:[r d0 ~= 0.0])  ]] whileTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2851
	d := r d0 truncated.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2852
	r := r - d.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2853
	r := r * 10.0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2854
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2855
	out nextPut:($0 + d).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2856
	i := i + 1.
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2857
    ].
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2858
    numDigits := i-1.
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2859
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2860
    str := out contents.
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2861
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2862
    "/ Fix out-of-range digits.
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2863
    numDigits to:2 by:-1 do:[:i |
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2864
	(str at:i) < $0 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2865
	    str at:i-1 put:(str at:i-1) - 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2866
	    str at:i put:(str at:i) + 10.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2867
	] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2868
	    (str at:i) > $9 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2869
		str at:i-1 put:(str at:i-1) + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2870
		str at:i put:(str at:i) - 10.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2871
	    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2872
	].
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2873
    ].
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2874
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2875
    str first <= $0 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2876
	self error:'non-positive leading digit'
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2877
    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2878
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2879
    "/ Round, handle carry
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2880
    (str at:numDigits) >= $5 ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2881
	str at:numDigits-1 put:(str at:numDigits-1) + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2882
	i := numDigits-1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2883
	[i > 1 and:[(str at:i) > $9]] whileTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2884
	    str at:i put:(str at:i) - 10.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2885
	    i := i - 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2886
	    str at:i put:(str at:i) + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2887
	]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2888
    ].
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2889
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2890
    "/ If first digit is 10, shift everything.
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2891
    str first > $9 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2892
	exp := exp + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2893
	str at:1 put:$0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2894
	str := '1',str
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2895
    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2896
    ^ { (str copyTo:numDigits-1) . exp }
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2897
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2898
    "
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2899
     0 asQDouble digitsWithPrecision:1      -> #('0' 0)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2900
     0 asQDouble digitsWithPrecision:0      -> #('0' 0)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2901
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2902
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2903
     1.2345 printfPrintString:'%.4f'
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2904
     1.2345 asQDouble digitsWithPrecision:5 -> #('12345' 0)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2905
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2906
     --- but 1.2345 is not really what you think:
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2907
     1.2345 printfPrintString:'%.20f'
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2908
     1.2345 asQDouble digitsWithPrecision:20 -> #('12344999999999999307' 0)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2909
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2910
     12.345 asQDouble digitsWithPrecision:5 -> #('12345' 1)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2911
     12345 asQDouble digitsWithPrecision:5 -> #('12345' 4)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2912
     12345.1 asQDouble digitsWithPrecision:5 -> #('12345' 4)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2913
     12345.9 asQDouble digitsWithPrecision:5 -> #('12346' 4)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2914
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2915
     1.2345 asQDouble / 10.0 asQDouble
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2916
     1.2345 asQDouble / 10.0
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2917
    "
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2918
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2919
    "Created: / 15-06-2017 / 09:10:01 / cg"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2920
    "Modified: / 16-06-2017 / 10:01:03 / cg"
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2921
!
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2922
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2923
printOn:aStream
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2924
    "return a printed representation of the receiver.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2925
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2926
     Notice:
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2927
        this code was adapted from an ugly piece of c++ code,
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2928
        which was obviously hacked.
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2929
        It does need a rework.
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2930
        As an alternative, use the printf functions, which should also deal wth QDoubles"
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2931
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2932
    self d1 = 0.0 ifTrue:[
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2933
        self d0 printOn:aStream.
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2934
        ^ self
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2935
    ].
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2936
    thisContext isRecursive ifTrue:[
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2937
        aStream nextPutAll:'aQDouble (error while printing)'.
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2938
        ^ self.
4978
99f7c90223f2 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4963
diff changeset
  2939
    ].
4981
952fad400b5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4978
diff changeset
  2940
4438
e5665b676a65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4437
diff changeset
  2941
    PrintfScanf printf:'%g' on:aStream argument:self.
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2942
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2943
"/    self
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2944
"/        printOn:aStream precision:40 width:0
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2945
"/        fixed:true showPositive:false uppercase:false fillChar:(Character space)
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2946
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2947
    "
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2948
     (1.2345 asQDouble) printString   
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2949
     (2 asQDouble squared) printString   
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2950
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2951
     (1.2345 asQDouble) printString.   
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2952
     (1.2345 asFloat) printString.     
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2953
     (1.2345 asLongFloat) printString. 
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2954
     (1.2345 asShortFloat) printString.
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2955
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2956
     ((QDouble fromFloat:1.2345) / 10.0) printString  
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2957
     ((QDouble fromFloat:1.2345) / 10000.0) printString   
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2958
     ((QDouble fromFloat:1.2345) / 1000000000.0) printString -> '0.0000123449999999999987156270014193593714e-4'
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  2959
     (1.2345 / 1000000000.0) printString                     -> '1.2345E-09'
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2960
    "
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2961
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2962
    "Created: / 15-06-2017 / 01:51:36 / cg"
4439
4c6520416d7d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4438
diff changeset
  2963
    "Modified (comment): / 21-06-2017 / 09:55:10 / cg"
4978
99f7c90223f2 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4963
diff changeset
  2964
    "Modified: / 05-06-2019 / 20:38:58 / Claus Gittinger"
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2965
!
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2966
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2967
printOn:aStream precision:precisionIn width:width
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2968
    fixed:fixed showPositive:showPositive uppercase:uppercase fillChar:fillChar
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  2969
    <resource: #obsolete>
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2970
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2971
    "return a printed representation of the receiver.
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2972
     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
  2973
     Notice:
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2974
	this code was adapted from an ugly piece of c++ code,
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2975
	which was obviously hacked.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2976
	It does need a rework.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2977
	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
  2978
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2979
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2980
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2981
     1.2345 asQDouble printString
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2982
     12.345 asQDouble printString
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2983
     12345 asQDouble printString
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2984
    "
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2985
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2986
    |sgn count delta exp precision|
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2987
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2988
"/    self d1 = 0.0 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2989
"/        self d0 printOn:aStream.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2990
"/        ^ self.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2991
"/    ].
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  2992
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2993
    count := 0.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2994
    sgn := true.
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2995
    exp := 0.
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2996
    precision := precisionIn.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2997
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  2998
    self isInfinite ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  2999
	self < 0 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3000
	    aStream nextPut:$-.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3001
	    count := 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3002
	] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3003
	    showPositive ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3004
		aStream nextPut:$+.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3005
		count := 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3006
	    ] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3007
		sgn := false.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3008
	    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3009
	].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3010
	uppercase ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3011
	    aStream nextPutAll:'INF'
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3012
	] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3013
	    aStream nextPutAll:'inf'
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3014
	].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3015
	count := count + 3.
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  3016
    ] ifFalse:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3017
	self isNaN ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3018
	    uppercase ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3019
		aStream nextPutAll:'NAN'
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3020
	    ] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3021
		aStream nextPutAll:'nan'
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3022
	    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3023
	    count := count + 3.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3024
	] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3025
	    self < 0 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3026
		aStream nextPut:$-.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3027
		count := count + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3028
	    ] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3029
		showPositive ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3030
		    aStream nextPut:$+.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3031
		    count := count + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3032
		] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3033
		    sgn := false.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3034
		].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3035
	    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3036
	    self = 0.0 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3037
		aStream nextPut:$0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3038
		count := count + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3039
		precision > 0 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3040
		    aStream nextPut:$..
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3041
		    count := count + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3042
		    precision timesRepeat:[ aStream nextPut:$0 ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3043
		    count := count + precision.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3044
		].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3045
		self halt.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3046
	    ] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3047
		|off d d_width_extra|
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3048
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3049
		"/ non-zero case
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3050
		off := fixed
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3051
			ifTrue:[ 1 + self asFloat abs log10 floor asInteger ]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3052
			ifFalse:[1].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3053
		d := precision + off.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3054
		d_width_extra := d.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3055
		fixed ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3056
		    d_width_extra := 40 max:d.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3057
		].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3058
		"/ 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
  3059
		"/ 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
  3060
		"/ should be rounded to 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3061
		(fixed and:[ (precision == 0) and:[ (self abs < 1.0) ]]) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3062
		    (self abs >= 0.5) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3063
			aStream nextPut:$1
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3064
		    ] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3065
			aStream nextPut:$0
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3066
		    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3067
		    ^ self
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3068
		].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3069
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3070
		"/ handle near zero to working precision (but not exactly zero)
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3071
		(fixed and:[ d <= 0 ]) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3072
		    aStream nextPut:$0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3073
		    (precision > 0) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3074
			aStream nextPut:$. .
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3075
			aStream next:precision put:$0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3076
		    ]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3077
		] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3078
		    "/ default
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3079
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3080
		    |t j|
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3081
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3082
		    t := self digitsWithPrecision:(fixed ifTrue:[d_width_extra] ifFalse:[d])+1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3083
		    exp := t second.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3084
		    t := t first.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3085
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3086
		    fixed ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3087
			"/ fix the string if it's been computed incorrectly
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3088
			"/ round here in the decimal string if required
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3089
			t := self round_string_qd:t at:(d + 1) offset:off.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3090
			precision := t at:3.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3091
			off := t at:2.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3092
			t := t at:1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3093
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3094
			(off > 0) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3095
			    aStream next:off putAll:t startingAt:1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3096
			    (precision > 0) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3097
				aStream nextPut:$. .
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3098
				aStream next:precision-1 putAll:t startingAt:off+1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3099
			    ]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3100
			] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3101
			    aStream nextPutAll:'0.'.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3102
			    (off < 0) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3103
				aStream next:off negated put:$0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3104
			    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3105
			    aStream next:d putAll:t startingAt:0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3106
			]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3107
		    ] ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3108
			aStream nextPut:(t at:1).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3109
			(precision > 0) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3110
			    aStream nextPut:$. .
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3111
			].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3112
			aStream next:precision putAll:t startingAt:2.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3113
		    ]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3114
		].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3115
	    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3116
	]
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  3117
    ].
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3118
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3119
    "/ trap for improper offset with large values
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3120
    "/ 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
  3121
    "/ 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
  3122
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3123
"/    (fixed and:[ (precision > 0) ]) ifTrue:[
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3124
"/        "/ make sure that the value isn't dramatically larger
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3125
"/        from_string = atof(s.c_str());
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3126
"/
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3127
"/        // if this ratio is large, then we've got problems
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3128
"/        if( fabs( from_string / this->x[0] ) > 3.0 ){
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3129
"/
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3130
"/                int point_position;
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3131
"/                char temp;
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3132
"/
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3133
"/                // loop on the string, find the point, move it up one
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3134
"/                // don't act on the first character
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3135
"/                for(i=1; i < s.length(); i++){
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3136
"/                        if(s[i] == '.'){
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3137
"/                                s[i] = s[i-1] ;
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3138
"/                                s[i-1] = '.' ;
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3139
"/                                break;
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3140
"/                        }
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3141
"/                }
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3142
"/
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3143
"/                from_string = atof(s.c_str());
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3144
"/                // 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
  3145
"/                if( fabs( from_string / this->x[0] ) > 3.0 ){
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3146
"/                        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
  3147
"/                }
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3148
"/        }
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3149
"/    }
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3150
"/
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3151
    fixed ifFalse:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3152
      "/ Fill in exponent part
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3153
      aStream nextPut:(uppercase ifTrue:[$E] ifFalse:[$e]).
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3154
      aStream print:exp.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3155
    ].
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3156
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3157
    "/ fill in the blanks
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3158
    (delta := width-count) > 0 ifTrue:[
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3159
	self halt.
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3160
"/    if (fmt & ios_base::internal) {
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3161
"/      if (sgn)
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3162
"/        s.insert(static_cast<string::size_type>(1), delta, fill);
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3163
"/      else
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3164
"/        s.insert(static_cast<string::size_type>(0), delta, fill);
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3165
"/    } else if (fmt & ios_base::left) {
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3166
"/      s.append(delta, fill);
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3167
"/    } else {
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3168
"/      s.insert(static_cast<string::size_type>(0), delta, fill);
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3169
"/    }
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3170
"/  }
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3171
    ].
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3172
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3173
    "Created: / 15-06-2017 / 02:37:31 / cg"
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3174
    "Modified (comment): / 16-06-2017 / 14:48:30 / cg"
4385
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  3175
!
3bfafdde1cb5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  3176
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3177
round_string_qd:str at:precisionIn offset:offsetIn
4454
f9079c08585a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4451
diff changeset
  3178
    <resource: #obsolete>
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3179
    "returns a triple of: { new-str . new-offset . new-precision }"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3180
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3181
    "/
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3182
    "/ Input string must be all digits or errors will occur.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3183
    "/
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3184
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3185
    |i numDigits offsetOut precisionOut|
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3186
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3187
    numDigits := precisionIn.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3188
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3189
    offsetOut := offsetIn.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3190
    precisionOut := precisionIn.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3191
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3192
    "/ Round, handle carry
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3193
    ((str at:numDigits) >= $5) ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3194
	str at:numDigits-1 put:(str at:numDigits-1)+1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3195
	i := numDigits-1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3196
	[ i > 1 and:[ (str at:i) > $9] ] whileTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3197
	    str at:i put:(str at:i)-10.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3198
	    i := i - 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3199
	    str at:i put:(str at:i)+1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3200
	]
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3201
    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3202
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3203
    "/ If first digit is 10, shift everything.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3204
    (str at:1) > $9 ifTrue:[
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3205
	"/ e++; // don't modify exponent here
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3206
	str replaceFrom:2 with:str startingAt:1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3207
	str at:1 put:$1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3208
	str at:2 put:$0.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3209
	offsetOut := offsetOut + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3210
	precisionOut := precisionOut + 1.
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3211
    ].
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3212
    ^ { (str copyTo:precisionOut) . offsetOut . precisionOut }
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3213
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3214
    "Created: / 16-06-2017 / 10:12:39 / cg"
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3215
    "Modified (comment): / 16-06-2017 / 11:22:03 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3216
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3217
5273
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3218
!QDouble methodsFor:'private'!
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3219
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3220
nintAsFloat
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3221
    "return the receiver truncated towards negative infinity"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3222
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3223
%{
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3224
    /* Computes the nearest integer to d. */
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3225
#define nint(d) (((d) == floor(d)) ? (d) : floor((d) + 0.5)) 
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3226
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3227
    double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3228
    OBJ newQD;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3229
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3230
    double x0, x1, x2, x3;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3231
    x0 = nint(a[0]);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3232
    x1 = x2 = x3 = 0.0;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3233
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3234
    if (x0 == a[0]) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3235
        /* First double is already an integer. */
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3236
        x1 = nint(a[1]);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3237
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3238
        if (x1 == a[1]) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3239
            /* Second double is already an integer. */
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3240
            x2 = nint(a[2]);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3241
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3242
            if (x2 == a[2]) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3243
                /* Third double is already an integer. */
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3244
                x3 = nint(a[3]);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3245
            } else {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3246
                if (abs(x2 - a[2]) == 0.5 && a[3] < 0.0) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3247
                    x2 -= 1.0;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3248
                }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3249
            }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3250
        } else {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3251
            if (abs(x1 - a[1]) == 0.5 && a[2] < 0.0) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3252
                x1 -= 1.0;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3253
            }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3254
        }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3255
    } else {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3256
        /* First double is not an integer. */
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3257
        if (abs(x0 - a[0]) == 0.5 && a[1] < 0.0) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3258
            x0 -= 1.0;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3259
        }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3260
    }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3261
    m_renorm4(x0, x1, x2, x3);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3262
    __qNew_qdReal(newQD, x0, x1, x2, x3);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3263
    RETURN( newQD );
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3264
%}.
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3265
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3266
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3267
     (QDouble fromFloat:4.0) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3268
     (QDouble fromFloat:4.6) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3269
     (QDouble fromFloat:4.50000001) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3270
     (QDouble fromFloat:4.5) roundedAsFloat        
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3271
     (QDouble fromFloat:4.49999999) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3272
     (QDouble fromFloat:4.4) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3273
     (QDouble fromFloat:4.1) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3274
     (QDouble fromFloat:0.1) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3275
     (QDouble fromFloat:0.5) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3276
     (QDouble fromFloat:0.49999) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3277
     (QDouble fromFloat:0.4) roundedAsFloat   
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3278
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3279
     (QDouble fromFloat:-4.0) roundedAsFloat   
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3280
     (QDouble fromFloat:-4.6) roundedAsFloat   
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3281
     (QDouble fromFloat:-4.4) roundedAsFloat       
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3282
     (QDouble fromFloat:-4.499999999) roundedAsFloat   
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3283
     (QDouble fromFloat:-4.5) roundedAsFloat        
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3284
     (QDouble fromFloat:-4.5000000001) roundedAsFloat        
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3285
     (QDouble fromFloat:-4.1) roundedAsFloat       
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3286
     (QDouble fromFloat:-0.1) roundedAsFloat      
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3287
     (QDouble fromFloat:-0.5) roundedAsFloat     
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3288
     (QDouble fromFloat:-0.4) roundedAsFloat    
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3289
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3290
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3291
    "Created: / 13-06-2017 / 01:52:44 / cg"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3292
    "Modified (comment): / 13-06-2017 / 17:33:19 / cg"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3293
!
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3294
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3295
renorm
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3296
    "destructive renormalization"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3297
%{
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3298
    double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3299
    double c0, c1, c2, c3;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3300
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3301
    c0 = a[0];
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3302
    c1 = a[1];
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3303
    c2 = a[2];
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3304
    c3 = a[3];
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3305
    m_renorm4(c0, c1, c2, c3);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3306
    a[0] = c0;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3307
    a[1] = c1;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3308
    a[2] = c2;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3309
    a[3] = c3;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3310
    RETURN( self );
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3311
%}.
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3312
    ^ self error.
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3313
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3314
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3315
     (QDouble fromFloat:1.0) renorm
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3316
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3317
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3318
    "Created: / 13-06-2017 / 18:05:33 / cg"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3319
    "Modified: / 15-06-2017 / 00:12:59 / cg"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3320
! !
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3321
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3322
!QDouble methodsFor:'private accessing'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3323
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3324
d0
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  3325
    "the most significant (and highest valued) 53 bits of precision"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3326
%{
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3327
    RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[0]) );
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3328
%}
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3329
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3330
    "Created: / 12-06-2017 / 20:15:12 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  3331
    "Modified (comment): / 13-06-2017 / 17:59:47 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3332
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3333
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3334
d1
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  3335
    "the next most significant (and next highest valued) 53 bits of precision"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3336
%{
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3337
    RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[1]) );
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3338
%}
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3339
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3340
    "Created: / 12-06-2017 / 20:15:12 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  3341
    "Modified (comment): / 13-06-2017 / 18:00:00 / cg"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3342
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3343
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3344
d2
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3345
%{
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3346
    RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[2]) );
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3347
%}
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3348
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3349
    "Created: / 12-06-2017 / 20:15:29 / cg"
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3350
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3351
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3352
d3
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  3353
    "the least significant (and smallest valued) 53 bits of precision"
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3354
%{
4395
3a01a83b6303 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4393
diff changeset
  3355
    RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[3]) );
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3356
%}
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3357
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3358
    "Created: / 12-06-2017 / 20:15:32 / cg"
4386
0a320155d78a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  3359
    "Modified (comment): / 13-06-2017 / 18:00:18 / cg"
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3360
! !
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3361
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3362
!QDouble methodsFor:'testing'!
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3363
4404
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  3364
isFinite
5195
cfe34e335f2c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5057
diff changeset
  3365
    "return true, if the receiver is a finite float (not NaN and not +/-INF)"
cfe34e335f2c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5057
diff changeset
  3366
4404
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  3367
    ^ self d0 isFinite
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  3368
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  3369
    "Created: / 17-06-2017 / 03:40:30 / cg"
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  3370
!
2708f482fe13 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4395
diff changeset
  3371
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3372
isInfinite
5195
cfe34e335f2c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5057
diff changeset
  3373
    "return true, if the receiver is an infinite float (+Inf or -Inf)."
cfe34e335f2c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5057
diff changeset
  3374
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3375
    ^ self d0 isInfinite
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3376
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3377
    "Created: / 15-06-2017 / 01:57:57 / cg"
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3378
!
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3379
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3380
isNaN
5195
cfe34e335f2c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5057
diff changeset
  3381
     "return true, if the receiver is an invalid float (NaN - not a number)"
cfe34e335f2c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5057
diff changeset
  3382
cfe34e335f2c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5057
diff changeset
  3383
   ^ self d0 isNaN
4393
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3384
4084ca142033 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
  3385
    "Created: / 15-06-2017 / 01:57:35 / cg"
4411
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3386
!
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3387
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3388
isOne
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3389
    ^ self d0 = 1.0
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3390
    and:[ self d1 = 0.0
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3391
    and:[ self d2 = 0.0
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3392
    and:[ self d3 = 0.0 ]]]
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3393
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3394
    "Created: / 18-06-2017 / 23:29:07 / cg"
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3395
!
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3396
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3397
isZero
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3398
    ^ self d0 = 0.0
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3399
8055a8f0b66f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4404
diff changeset
  3400
    "Created: / 18-06-2017 / 23:29:25 / cg"
5270
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3401
!
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3402
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3403
negative
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3404
    ^ self d0 negative
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3405
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3406
    "
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3407
     (QDouble fromFloat:0.0) negative
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3408
     (QDouble fromFloat:1.0) negative
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3409
     (QDouble fromFloat:-1.0) negative
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3410
    "
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3411
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3412
    "Created: / 13-06-2017 / 01:57:39 / cg"
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3413
    "Modified: / 13-06-2017 / 17:58:26 / cg"
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3414
!
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3415
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3416
positive
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3417
    "return true, if the receiver is greater or equal to zero (not negative)"
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3418
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3419
    ^ self d0 positive
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3420
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3421
    "
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3422
     (QDouble fromFloat:1.0) positive
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3423
     (QDouble fromFloat:-1.0) positive
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3424
     (1.0 asQDouble + 1e-100) positive 
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3425
     (0.0 asQDouble + 1e-100) positive 
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3426
     (0.0 asQDouble - 1e-100) positive 
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3427
    "
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3428
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3429
    "Created: / 13-06-2017 / 01:56:53 / cg"
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3430
    "Modified: / 13-06-2017 / 17:58:41 / cg"
af3b659665cf #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5195
diff changeset
  3431
    "Modified (comment): / 28-05-2019 / 05:55:55 / Claus Gittinger"
5306
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3432
!
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3433
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3434
sign
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3435
    "return the sign of the receiver"
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3436
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3437
    ^ self d0 sign
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3438
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3439
    "
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3440
     Float nan isNaN   
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3441
     Float nan sign   
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3442
     Float infinity sign  
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3443
     Float infinity negated sign 
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3444
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3445
     ShortFloat nan isNaN   
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3446
     ShortFloat nan sign   
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3447
     ShortFloat infinity sign  
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3448
     ShortFloat infinity negated sign  
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3449
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3450
     QDouble nan isNaN      
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3451
     QDouble nan sign        
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3452
     QDouble infinity sign  
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3453
     QDouble infinity negated sign  
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3454
     0 asQDouble sign  
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3455
     1 asQDouble sign  
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3456
     -1 asQDouble sign 
819725b85a08 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5304
diff changeset
  3457
    "
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3458
! !
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3459
5273
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3460
!QDouble methodsFor:'truncation & rounding'!
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3461
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3462
ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3463
    "return the smallest integer which is greater or equal to the receiver."
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3464
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3465
    |f|
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3466
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3467
    f := self ceilingAsFloat.
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3468
    ^ f d0 asInteger + f d1 asInteger + f d2 asInteger + f d3 asInteger
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3469
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3470
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3471
     (QDouble fromFloat:4.0) ceiling 
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3472
     (QDouble fromFloat:4.1) ceiling 
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3473
     (QDouble fromFloat:0.1) ceiling 
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3474
     (0.1 + (QDouble fromFloat:1.0)) ceiling 
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3475
     (1e20 + (QDouble fromFloat:1.0)) ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3476
     (1e20 + (QDouble fromFloat:1.1)) ceiling  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3477
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3478
     (QDouble fromFloat:1.5) ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3479
     (QDouble fromFloat:0.5) ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3480
     (QDouble fromFloat:-0.5) ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3481
     (QDouble fromFloat:-1.5) ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3482
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3483
!
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3484
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3485
ceilingAsFloat
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3486
    "return the smallest integer-valued float greater or equal to the receiver.
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3487
     This is much like #ceiling, but avoids a (possibly expensive) conversion
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3488
     of the result to an integer.
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3489
     It may be useful, if the result is to be further used in another float-operation."
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3490
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3491
%{
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3492
    double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3493
    OBJ newQD;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3494
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3495
    double x0, x1, x2, x3;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3496
    x1 = x2 = x3 = 0.0;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3497
    x0 = ceil(a[0]);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3498
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3499
    if (x0 == a[0]) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3500
        x1 = ceil(a[1]);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3501
        if (x1 == a[1]) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3502
            x2 = ceil(a[2]);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3503
            if (x2 == a[2]) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3504
                x3 = ceil(a[3]);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3505
            }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3506
        }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3507
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3508
        m_renorm4(x0, x1, x2, x3);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3509
    }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3510
    __qNew_qdReal(newQD, x0, x1, x2, x3);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3511
    RETURN( newQD );
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3512
%}.
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3513
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3514
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3515
     (QDouble fromFloat:4.0) ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3516
     (QDouble fromFloat:4.1) ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3517
     (QDouble fromFloat:0.1) ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3518
     (0.1 + (QDouble fromFloat:1.0)) ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3519
     (1e20 + (QDouble fromFloat:1.0)) ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3520
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3521
     (QDouble fromFloat:1.5) ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3522
     (QDouble fromFloat:0.5) ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3523
     (QDouble fromFloat:-0.5) ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3524
     (QDouble fromFloat:-1.5) ceiling
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3525
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3526
!
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3527
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3528
floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3529
    "return the receiver truncated towards negative infinity"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3530
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3531
    |f|
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3532
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3533
    f := self floorAsFloat.
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3534
    ^ f d0 asInteger + f d1 asInteger + f d2 asInteger + f d3 asInteger
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3535
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3536
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3537
     (QDouble fromFloat:4.0) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3538
     (QDouble fromFloat:4.1) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3539
     (QDouble fromFloat:0.1) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3540
     (0.1 + (QDouble fromFloat:1.0)) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3541
     (1e20 + (QDouble fromFloat:1.0)) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3542
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3543
     (QDouble fromFloat:1.5) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3544
     (QDouble fromFloat:0.5) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3545
     (QDouble fromFloat:-0.5) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3546
     (QDouble fromFloat:-1.5) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3547
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3548
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3549
    "Created: / 13-06-2017 / 01:52:44 / cg"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3550
    "Modified (comment): / 13-06-2017 / 17:33:19 / cg"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3551
!
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3552
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3553
floorAsFloat
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3554
    "return the receiver truncated towards negative infinity"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3555
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3556
%{
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3557
    double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3558
    OBJ newQD;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3559
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3560
    double x0, x1, x2, x3;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3561
    x1 = x2 = x3 = 0.0;
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3562
    x0 =floor(a[0]);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3563
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3564
    if (x0 == a[0]) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3565
        x1 = floor(a[1]);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3566
        if (x1 == a[1]) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3567
            x2 = floor(a[2]);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3568
            if (x2 == a[2]) {
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3569
                x3 = floor(a[3]);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3570
            }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3571
        }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3572
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3573
        m_renorm4(x0, x1, x2, x3);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3574
    }
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3575
    __qNew_qdReal(newQD, x0, x1, x2, x3);
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3576
    RETURN( newQD );
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3577
%}.
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3578
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3579
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3580
     (QDouble fromFloat:4.0) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3581
     (QDouble fromFloat:4.1) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3582
     (QDouble fromFloat:0.1) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3583
     (0.1 + (QDouble fromFloat:1.0)) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3584
     (1e20 + (QDouble fromFloat:1.0)) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3585
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3586
     (QDouble fromFloat:1.5) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3587
     (QDouble fromFloat:0.5) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3588
     (QDouble fromFloat:-0.5) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3589
     (QDouble fromFloat:-1.5) floor
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3590
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3591
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3592
    "Created: / 13-06-2017 / 01:52:44 / cg"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3593
    "Modified (comment): / 13-06-2017 / 17:33:19 / cg"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3594
!
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3595
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3596
rounded
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3597
    "return the smallest integer which is greater or equal to the receiver."
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3598
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3599
    |f|
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3600
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3601
    f := self roundedAsFloat.
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3602
    "/ ^ (f d0 + f d1 + f d2 + f d3) asInteger
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3603
    ^ f d0 asInteger + f d1 asInteger + f d2 asInteger + f d3 asInteger
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3604
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3605
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3606
     (QDouble fromFloat:4.0) rounded  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3607
     (QDouble fromFloat:4.6) rounded  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3608
     (QDouble fromFloat:4.50000001) rounded  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3609
     (QDouble fromFloat:4.5) rounded        
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3610
     (QDouble fromFloat:4.49999999) rounded  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3611
     (QDouble fromFloat:4.4) rounded  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3612
     (QDouble fromFloat:4.1) rounded  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3613
     (QDouble fromFloat:0.1) rounded  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3614
     (QDouble fromFloat:0.5) rounded  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3615
     (QDouble fromFloat:0.49999) rounded  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3616
     (QDouble fromFloat:0.4) rounded   
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3617
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3618
     (QDouble fromFloat:-4.0) rounded   
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3619
     (QDouble fromFloat:-4.6) rounded   
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3620
     (QDouble fromFloat:-4.4) rounded       
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3621
     (QDouble fromFloat:-4.499999999) rounded   
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3622
     (QDouble fromFloat:-4.5) rounded        
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3623
     (QDouble fromFloat:-4.5000000001) rounded        
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3624
     (QDouble fromFloat:-4.1) rounded       
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3625
     (QDouble fromFloat:-0.1) rounded      
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3626
     (QDouble fromFloat:-0.5) rounded     
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3627
     (QDouble fromFloat:-0.4) rounded    
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3628
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3629
!
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3630
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3631
roundedAsFloat
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3632
    "return the receiver truncated towards negative infinity"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3633
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3634
    self positive ifTrue:[
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3635
        ^ self nintAsFloat
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3636
    ].
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3637
    ^ self negated nintAsFloat negated
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3638
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3639
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3640
     (QDouble fromFloat:4.0) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3641
     (QDouble fromFloat:4.6) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3642
     (QDouble fromFloat:4.50000001) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3643
     (QDouble fromFloat:4.5) roundedAsFloat        
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3644
     (QDouble fromFloat:4.49999999) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3645
     (QDouble fromFloat:4.4) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3646
     (QDouble fromFloat:4.1) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3647
     (QDouble fromFloat:0.1) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3648
     (QDouble fromFloat:0.5) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3649
     (QDouble fromFloat:0.49999) roundedAsFloat  
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3650
     (QDouble fromFloat:0.4) roundedAsFloat   
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3651
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3652
     (QDouble fromFloat:-4.0) roundedAsFloat   
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3653
     (QDouble fromFloat:-4.6) roundedAsFloat   
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3654
     (QDouble fromFloat:-4.4) roundedAsFloat       
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3655
     (QDouble fromFloat:-4.499999999) roundedAsFloat   
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3656
     (QDouble fromFloat:-4.5) roundedAsFloat        
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3657
     (QDouble fromFloat:-4.5000000001) roundedAsFloat        
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3658
     (QDouble fromFloat:-4.1) roundedAsFloat       
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3659
     (QDouble fromFloat:-0.1) roundedAsFloat      
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3660
     (QDouble fromFloat:-0.5) roundedAsFloat     
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3661
     (QDouble fromFloat:-0.4) roundedAsFloat    
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3662
    "
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3663
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3664
    "Created: / 13-06-2017 / 01:52:44 / cg"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3665
    "Modified (comment): / 13-06-2017 / 17:33:19 / cg"
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3666
! !
9533c37f6d69 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5270
diff changeset
  3667
4380
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3668
!QDouble class methodsFor:'documentation'!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3669
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3670
version
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3671
    ^ '$Header$'
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3672
!
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3673
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3674
version_CVS
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3675
    ^ '$Header$'
1f4fe7f1c1d3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3676
! !
5057
cc72e91af490 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4981
diff changeset
  3677