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
52 // Arrange that exp_2 is zero and adjust exp10
53 // so that mantissa is not a multiple of ten.
54 void normalize10( void );
55
56 // Return ( mantissa % 10 )
57 int mod10( void ) const;
58
59 // mantissa /= 10; returns zero if result is zero
60 int div10( void );
61
62 // These are useful for decimal to binary conversions.
63
64 // Set everything to zero.
65 void clear( void );
66
67 // mantissa = 10 * mantissa + digit
68 void mul10( int digit );
69
70 // Arrange that exp_10 is zero and adjust exp_2
71 // so that mantissa is not a multiple of two.
72 void normalize2( void );
73
74 // mantissa = 10 * mantissa + digit
75 double value( void );
76
77 // Shared functionality.
78
79 // Compute 2 ** exponent.
80 static double pow2( unsigned exponent );
81
82 // multiply
83 void multiply( const RTFloat & );
84
85 // We use dword to compute the sum of a column in the multiplication
86 // algorithm. It must be capable of representing, in the worst case,
87 // the sum of the carry from the previous column and mantissa_words
88 // products of operands no larger than word_mask. That sum is bounded
89 // by mantissa_words * word_mask * word_scale.
90 typedef unsigned long dword;
91};
92
93#endif // RTUseFloatingPoint
94
95#endif // __RTFloat_h__