C++ TargetRTS
Loading...
Searching...
No Matches
RTFloat.h
1/*
2 * Licensed Materials - Property of HCL and/or IBM
3 * Copyright HCL Technologies Ltd. 2016, 2021. All Rights Reserved.
4 * Copyright IBM Corporation 1999, 2016. All Rights Reserved.
5 *
6 * U.S. Government Users Restricted Rights - Use, duplication or
7 * disclosure restricted by GSA ADP Schedule.
8 */
9
10#ifndef __RTFloat_h__
11#define __RTFloat_h__ included
12
13#ifdef PRAGMA
14#pragma interface
15#endif
16
17#ifndef __RTConfig_h__
18#include <RTConfig.h>
19#endif
20
21#if RTUseFloatingPoint
22
23struct RTFloat
24{
25 enum
26 {
27 mantissa_words = 12
28 , bits_per_word = 8
29 , word_scale = 1 << bits_per_word
30 , word_mask = word_scale - 1
31
32 , mantissa_bits = mantissa_words * bits_per_word
33 , mantissa_digits = ( 10 * mantissa_bits + 32 ) / 33
34 };
35
36 // We use word to store the digits of mantissas in a base(word_scale)
37 // representation. Those digits lie in the range [ 0, word_mask ].
38 typedef unsigned char word;
39
40 // value is represented by:
41 // mantissa * ( 10 ** exp10 ) * ( 2 ** exp_2 )
42 // mantissa[ 0 ] is the most significant word.
43 word mantissa[ mantissa_words ];
44 int exp10;
45 int exp_2;
46
47 // These are useful for binary to decimal conversions.
48
49 // Assigned value must be positive.
50 void assign( double );
51 void assign( long double );
52
53 // Arrange that exp_2 is zero and adjust exp10
54 // so that mantissa is not a multiple of ten.
55 void normalize10( void );
56
57 // Return ( mantissa % 10 )
58 int mod10( void ) const;
59
60 // mantissa /= 10; returns zero if result is zero
61 int div10( void );
62
63 // These are useful for decimal to binary conversions.
64
65 // Set everything to zero.
66 void clear( void );
67
68 // mantissa = 10 * mantissa + digit
69 void mul10( int digit );
70
71 // Arrange that exp_10 is zero and adjust exp_2
72 // so that mantissa is not a multiple of two.
73 void normalize2( void );
74
75 // mantissa = 10 * mantissa + digit
76 double value( void );
77
78 // Shared functionality.
79
80 // Compute 2 ** exponent.
81 static double pow2( unsigned exponent );
82
83 // multiply
84 void multiply( const RTFloat & );
85
86 // We use dword to compute the sum of a column in the multiplication
87 // algorithm. It must be capable of representing, in the worst case,
88 // the sum of the carry from the previous column and mantissa_words
89 // products of operands no larger than word_mask. That sum is bounded
90 // by mantissa_words * word_mask * word_scale.
91 typedef unsigned long dword;
92};
93
94#endif // RTUseFloatingPoint
95
96#endif // __RTFloat_h__