blib/lib/Math/Decimal128.pm

filter: Statementstmt 68.1% 246 / 361 Branchbran 61.5% 139 / 226 Conditioncond 58.3% 49 / 84 MC/DCmcdc 44.4% 20 / 45 Subroutinesub 83.7% 31 / 37 Podpod 0.0% 0 / 20 totaltotal 62.7% 485 / 773 CC 143 SCAR 38.6
CC
143
Cov
65%
_MEtoBINSTR
272.5
decode_dpd_1st
132.0
decode_bidl
32.5
CRAP 47.4
↑ Summary Decimal128.xs »
1 ## This file generated by InlineX::C2XS (version 0.22) using Inline::C (version 0.5501)
2 package Math::Decimal128;
3  
4 31 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 31 require Exporter;
10 31 *import = \&Exporter::import;
11 31 require DynaLoader;
12  
13 31 $Math::Decimal128::VERSION = '0.11';
14  
15 31 ▶use subs qw(DEC128_MAX DEC128_MIN);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 use overload
18 31 ▶ '+' => \&_overload_add,
Subroutine BEGIN: called CC=1 SCAR=0.0
19 '*' => \&_overload_mul,
20 '-' => \&_overload_sub,
21 '/' => \&_overload_div,
22 '+=' => \&_overload_add_eq,
23 '*=' => \&_overload_mul_eq,
24 '-=' => \&_overload_sub_eq,
25 '/=' => \&_overload_div_eq,
26 '""' => \&_overload_string,
27 '==' => \&_overload_equiv,
28 '!=' => \&_overload_not_equiv,
29 '<' => \&_overload_lt,
30 '>' => \&_overload_gt,
31 '<=' => \&_overload_lte,
32 '>=' => \&_overload_gte,
33 '<=>' => \&_overload_spaceship,
34 '=' => \&_overload_copy,
35 '!' => \&_overload_not,
36 'bool' => \&_overload_true,
37 'abs' => \&_overload_abs,
38 '++' => \&_overload_inc,
39 '--' => \&_overload_dec,
40 'int' => \&_overload_int,
41 'neg' => \&_overload_neg,
42 31 ;
43  
44 31 Math::Decimal128->DynaLoader::bootstrap($Math::Decimal128::VERSION);
45  
46 31 @Math::Decimal128::EXPORT = ();
47 31 @Math::Decimal128::EXPORT_OK = qw(
48 NaND128 InfD128 ZeroD128 UnityD128 Exp10l NVtoD128 UVtoD128 IVtoD128 PVtoD128 STRtoD128
49 have_strtod128 D128toNV assignNaNl assignInfl D128toME DPDtoD128
50 D128toD128 D128toD128 is_NaND128 is_InfD128 is_ZeroD128 DEC128_MAX DEC128_MIN
51 assignMEl d128_bytes MEtoD128 hex2binl decode_d128 decode_bidl decode_dpdl d128_fmt
52 get_expl get_signl PVtoMEl MEtoPVl
53 D128toFSTR D128toRSTR
54 assignIVl assignUVl assignNVl assignD128 assignPVl assignDPDl
55 );
56  
57 31 %Math::Decimal128::EXPORT_TAGS = (all => [qw(
58 NaND128 InfD128 ZeroD128 UnityD128 Exp10l NVtoD128 UVtoD128 IVtoD128 PVtoD128 STRtoD128
59 have_strtod128 D128toNV assignNaNl assignInfl D128toME DPDtoD128
60 D128toD128 D128toD128 is_NaND128 is_InfD128 is_ZeroD128 DEC128_MAX DEC128_MIN
61 assignMEl d128_bytes MEtoD128 hex2binl decode_d128 decode_bidl decode_dpdl d128_fmt
62 get_expl get_signl PVtoMEl MEtoPVl
63 D128toFSTR D128toRSTR
64 assignIVl assignUVl assignNVl assignPVl assignDPDl assignD128
65 )]);
66  
67 #######################################################################
68 #######################################################################
69  
70 31 $Math::Decimal128::nan_str = unpack("a*", pack( "B*", '011111' . ('0' x 122)));
71 31 $Math::Decimal128::ninf_str = unpack("a*", pack( "B*", '11111' . ('0' x 123)));
72 31 $Math::Decimal128::pinf_str = unpack("a*", pack( "B*", '01111' . ('0' x 123)));
73 31 $Math::Decimal128::fmt = d128_fmt();
74 31 $Math::Decimal128::NNW = 0; # set to 1 to enable a non-numeric warning whenever
75 # a string containing any non-numeric characters is
76 # treated as a number.
77  
78 #######################################################################
79 #######################################################################
80  
81 31 ▶%Math::Decimal128::dpd_encode = $Math::Decimal128::fmt eq 'DPD' ? (
Branch: 1 branch
BranchTrueFalseTotal
$Math::Decimal128::fmt eq 'DPD' ? : 0 31 31
82 '0000000000' => '000', '0000000001' => '001', '0000000010' => '002', '0000000011' => '003',
83 '0000000100' => '004', '0000000101' => '005', '0000000110' => '006', '0000000111' => '007',
84 '0000001000' => '008', '0000001001' => '009', '0000010000' => '010', '0000010001' => '011',
85 '0000010010' => '012', '0000010011' => '013', '0000010100' => '014', '0000010101' => '015',
86 '0000010110' => '016', '0000010111' => '017', '0000011000' => '018', '0000011001' => '019',
87 '0000100000' => '020', '0000100001' => '021', '0000100010' => '022', '0000100011' => '023',
88 '0000100100' => '024', '0000100101' => '025', '0000100110' => '026', '0000100111' => '027',
89 '0000101000' => '028', '0000101001' => '029', '0000110000' => '030', '0000110001' => '031',
90 '0000110010' => '032', '0000110011' => '033', '0000110100' => '034', '0000110101' => '035',
91 '0000110110' => '036', '0000110111' => '037', '0000111000' => '038', '0000111001' => '039',
92 '0001000000' => '040', '0001000001' => '041', '0001000010' => '042', '0001000011' => '043',
93 '0001000100' => '044', '0001000101' => '045', '0001000110' => '046', '0001000111' => '047',
94 '0001001000' => '048', '0001001001' => '049', '0001010000' => '050', '0001010001' => '051',
95 '0001010010' => '052', '0001010011' => '053', '0001010100' => '054', '0001010101' => '055',
96 '0001010110' => '056', '0001010111' => '057', '0001011000' => '058', '0001011001' => '059',
97 '0001100000' => '060', '0001100001' => '061', '0001100010' => '062', '0001100011' => '063',
98 '0001100100' => '064', '0001100101' => '065', '0001100110' => '066', '0001100111' => '067',
99 '0001101000' => '068', '0001101001' => '069', '0001110000' => '070', '0001110001' => '071',
100 '0001110010' => '072', '0001110011' => '073', '0001110100' => '074', '0001110101' => '075',
101 '0001110110' => '076', '0001110111' => '077', '0001111000' => '078', '0001111001' => '079',
102 '0000001010' => '080', '0000001011' => '081', '0000101010' => '082', '0000101011' => '083',
103 '0001001010' => '084', '0001001011' => '085', '0001101010' => '086', '0001101011' => '087',
104 '0001001110' => '088', '0001001111' => '089', '0000011010' => '090', '0000011011' => '091',
105 '0000111010' => '092', '0000111011' => '093', '0001011010' => '094', '0001011011' => '095',
106 '0001111010' => '096', '0001111011' => '097', '0001011110' => '098', '0001011111' => '099',
107 '0010000000' => '100', '0010000001' => '101', '0010000010' => '102', '0010000011' => '103',
108 '0010000100' => '104', '0010000101' => '105', '0010000110' => '106', '0010000111' => '107',
109 '0010001000' => '108', '0010001001' => '109', '0010010000' => '110', '0010010001' => '111',
110 '0010010010' => '112', '0010010011' => '113', '0010010100' => '114', '0010010101' => '115',
111 '0010010110' => '116', '0010010111' => '117', '0010011000' => '118', '0010011001' => '119',
112 '0010100000' => '120', '0010100001' => '121', '0010100010' => '122', '0010100011' => '123',
113 '0010100100' => '124', '0010100101' => '125', '0010100110' => '126', '0010100111' => '127',
114 '0010101000' => '128', '0010101001' => '129', '0010110000' => '130', '0010110001' => '131',
115 '0010110010' => '132', '0010110011' => '133', '0010110100' => '134', '0010110101' => '135',
116 '0010110110' => '136', '0010110111' => '137', '0010111000' => '138', '0010111001' => '139',
117 '0011000000' => '140', '0011000001' => '141', '0011000010' => '142', '0011000011' => '143',
118 '0011000100' => '144', '0011000101' => '145', '0011000110' => '146', '0011000111' => '147',
119 '0011001000' => '148', '0011001001' => '149', '0011010000' => '150', '0011010001' => '151',
120 '0011010010' => '152', '0011010011' => '153', '0011010100' => '154', '0011010101' => '155',
121 '0011010110' => '156', '0011010111' => '157', '0011011000' => '158', '0011011001' => '159',
122 '0011100000' => '160', '0011100001' => '161', '0011100010' => '162', '0011100011' => '163',
123 '0011100100' => '164', '0011100101' => '165', '0011100110' => '166', '0011100111' => '167',
124 '0011101000' => '168', '0011101001' => '169', '0011110000' => '170', '0011110001' => '171',
125 '0011110010' => '172', '0011110011' => '173', '0011110100' => '174', '0011110101' => '175',
126 '0011110110' => '176', '0011110111' => '177', '0011111000' => '178', '0011111001' => '179',
127 '0010001010' => '180', '0010001011' => '181', '0010101010' => '182', '0010101011' => '183',
128 '0011001010' => '184', '0011001011' => '185', '0011101010' => '186', '0011101011' => '187',
129 '0011001110' => '188', '0011001111' => '189', '0010011010' => '190', '0010011011' => '191',
130 '0010111010' => '192', '0010111011' => '193', '0011011010' => '194', '0011011011' => '195',
131 '0011111010' => '196', '0011111011' => '197', '0011011110' => '198', '0011011111' => '199',
132 '0100000000' => '200', '0100000001' => '201', '0100000010' => '202', '0100000011' => '203',
133 '0100000100' => '204', '0100000101' => '205', '0100000110' => '206', '0100000111' => '207',
134 '0100001000' => '208', '0100001001' => '209', '0100010000' => '210', '0100010001' => '211',
135 '0100010010' => '212', '0100010011' => '213', '0100010100' => '214', '0100010101' => '215',
136 '0100010110' => '216', '0100010111' => '217', '0100011000' => '218', '0100011001' => '219',
137 '0100100000' => '220', '0100100001' => '221', '0100100010' => '222', '0100100011' => '223',
138 '0100100100' => '224', '0100100101' => '225', '0100100110' => '226', '0100100111' => '227',
139 '0100101000' => '228', '0100101001' => '229', '0100110000' => '230', '0100110001' => '231',
140 '0100110010' => '232', '0100110011' => '233', '0100110100' => '234', '0100110101' => '235',
141 '0100110110' => '236', '0100110111' => '237', '0100111000' => '238', '0100111001' => '239',
142 '0101000000' => '240', '0101000001' => '241', '0101000010' => '242', '0101000011' => '243',
143 '0101000100' => '244', '0101000101' => '245', '0101000110' => '246', '0101000111' => '247',
144 '0101001000' => '248', '0101001001' => '249', '0101010000' => '250', '0101010001' => '251',
145 '0101010010' => '252', '0101010011' => '253', '0101010100' => '254', '0101010101' => '255',
146 '0101010110' => '256', '0101010111' => '257', '0101011000' => '258', '0101011001' => '259',
147 '0101100000' => '260', '0101100001' => '261', '0101100010' => '262', '0101100011' => '263',
148 '0101100100' => '264', '0101100101' => '265', '0101100110' => '266', '0101100111' => '267',
149 '0101101000' => '268', '0101101001' => '269', '0101110000' => '270', '0101110001' => '271',
150 '0101110010' => '272', '0101110011' => '273', '0101110100' => '274', '0101110101' => '275',
151 '0101110110' => '276', '0101110111' => '277', '0101111000' => '278', '0101111001' => '279',
152 '0100001010' => '280', '0100001011' => '281', '0100101010' => '282', '0100101011' => '283',
153 '0101001010' => '284', '0101001011' => '285', '0101101010' => '286', '0101101011' => '287',
154 '0101001110' => '288', '0101001111' => '289', '0100011010' => '290', '0100011011' => '291',
155 '0100111010' => '292', '0100111011' => '293', '0101011010' => '294', '0101011011' => '295',
156 '0101111010' => '296', '0101111011' => '297', '0101011110' => '298', '0101011111' => '299',
157 '0110000000' => '300', '0110000001' => '301', '0110000010' => '302', '0110000011' => '303',
158 '0110000100' => '304', '0110000101' => '305', '0110000110' => '306', '0110000111' => '307',
159 '0110001000' => '308', '0110001001' => '309', '0110010000' => '310', '0110010001' => '311',
160 '0110010010' => '312', '0110010011' => '313', '0110010100' => '314', '0110010101' => '315',
161 '0110010110' => '316', '0110010111' => '317', '0110011000' => '318', '0110011001' => '319',
162 '0110100000' => '320', '0110100001' => '321', '0110100010' => '322', '0110100011' => '323',
163 '0110100100' => '324', '0110100101' => '325', '0110100110' => '326', '0110100111' => '327',
164 '0110101000' => '328', '0110101001' => '329', '0110110000' => '330', '0110110001' => '331',
165 '0110110010' => '332', '0110110011' => '333', '0110110100' => '334', '0110110101' => '335',
166 '0110110110' => '336', '0110110111' => '337', '0110111000' => '338', '0110111001' => '339',
167 '0111000000' => '340', '0111000001' => '341', '0111000010' => '342', '0111000011' => '343',
168 '0111000100' => '344', '0111000101' => '345', '0111000110' => '346', '0111000111' => '347',
169 '0111001000' => '348', '0111001001' => '349', '0111010000' => '350', '0111010001' => '351',
170 '0111010010' => '352', '0111010011' => '353', '0111010100' => '354', '0111010101' => '355',
171 '0111010110' => '356', '0111010111' => '357', '0111011000' => '358', '0111011001' => '359',
172 '0111100000' => '360', '0111100001' => '361', '0111100010' => '362', '0111100011' => '363',
173 '0111100100' => '364', '0111100101' => '365', '0111100110' => '366', '0111100111' => '367',
174 '0111101000' => '368', '0111101001' => '369', '0111110000' => '370', '0111110001' => '371',
175 '0111110010' => '372', '0111110011' => '373', '0111110100' => '374', '0111110101' => '375',
176 '0111110110' => '376', '0111110111' => '377', '0111111000' => '378', '0111111001' => '379',
177 '0110001010' => '380', '0110001011' => '381', '0110101010' => '382', '0110101011' => '383',
178 '0111001010' => '384', '0111001011' => '385', '0111101010' => '386', '0111101011' => '387',
179 '0111001110' => '388', '0111001111' => '389', '0110011010' => '390', '0110011011' => '391',
180 '0110111010' => '392', '0110111011' => '393', '0111011010' => '394', '0111011011' => '395',
181 '0111111010' => '396', '0111111011' => '397', '0111011110' => '398', '0111011111' => '399',
182 '1000000000' => '400', '1000000001' => '401', '1000000010' => '402', '1000000011' => '403',
183 '1000000100' => '404', '1000000101' => '405', '1000000110' => '406', '1000000111' => '407',
184 '1000001000' => '408', '1000001001' => '409', '1000010000' => '410', '1000010001' => '411',
185 '1000010010' => '412', '1000010011' => '413', '1000010100' => '414', '1000010101' => '415',
186 '1000010110' => '416', '1000010111' => '417', '1000011000' => '418', '1000011001' => '419',
187 '1000100000' => '420', '1000100001' => '421', '1000100010' => '422', '1000100011' => '423',
188 '1000100100' => '424', '1000100101' => '425', '1000100110' => '426', '1000100111' => '427',
189 '1000101000' => '428', '1000101001' => '429', '1000110000' => '430', '1000110001' => '431',
190 '1000110010' => '432', '1000110011' => '433', '1000110100' => '434', '1000110101' => '435',
191 '1000110110' => '436', '1000110111' => '437', '1000111000' => '438', '1000111001' => '439',
192 '1001000000' => '440', '1001000001' => '441', '1001000010' => '442', '1001000011' => '443',
193 '1001000100' => '444', '1001000101' => '445', '1001000110' => '446', '1001000111' => '447',
194 '1001001000' => '448', '1001001001' => '449', '1001010000' => '450', '1001010001' => '451',
195 '1001010010' => '452', '1001010011' => '453', '1001010100' => '454', '1001010101' => '455',
196 '1001010110' => '456', '1001010111' => '457', '1001011000' => '458', '1001011001' => '459',
197 '1001100000' => '460', '1001100001' => '461', '1001100010' => '462', '1001100011' => '463',
198 '1001100100' => '464', '1001100101' => '465', '1001100110' => '466', '1001100111' => '467',
199 '1001101000' => '468', '1001101001' => '469', '1001110000' => '470', '1001110001' => '471',
200 '1001110010' => '472', '1001110011' => '473', '1001110100' => '474', '1001110101' => '475',
201 '1001110110' => '476', '1001110111' => '477', '1001111000' => '478', '1001111001' => '479',
202 '1000001010' => '480', '1000001011' => '481', '1000101010' => '482', '1000101011' => '483',
203 '1001001010' => '484', '1001001011' => '485', '1001101010' => '486', '1001101011' => '487',
204 '1001001110' => '488', '1001001111' => '489', '1000011010' => '490', '1000011011' => '491',
205 '1000111010' => '492', '1000111011' => '493', '1001011010' => '494', '1001011011' => '495',
206 '1001111010' => '496', '1001111011' => '497', '1001011110' => '498', '1001011111' => '499',
207 '1010000000' => '500', '1010000001' => '501', '1010000010' => '502', '1010000011' => '503',
208 '1010000100' => '504', '1010000101' => '505', '1010000110' => '506', '1010000111' => '507',
209 '1010001000' => '508', '1010001001' => '509', '1010010000' => '510', '1010010001' => '511',
210 '1010010010' => '512', '1010010011' => '513', '1010010100' => '514', '1010010101' => '515',
211 '1010010110' => '516', '1010010111' => '517', '1010011000' => '518', '1010011001' => '519',
212 '1010100000' => '520', '1010100001' => '521', '1010100010' => '522', '1010100011' => '523',
213 '1010100100' => '524', '1010100101' => '525', '1010100110' => '526', '1010100111' => '527',
214 '1010101000' => '528', '1010101001' => '529', '1010110000' => '530', '1010110001' => '531',
215 '1010110010' => '532', '1010110011' => '533', '1010110100' => '534', '1010110101' => '535',
216 '1010110110' => '536', '1010110111' => '537', '1010111000' => '538', '1010111001' => '539',
217 '1011000000' => '540', '1011000001' => '541', '1011000010' => '542', '1011000011' => '543',
218 '1011000100' => '544', '1011000101' => '545', '1011000110' => '546', '1011000111' => '547',
219 '1011001000' => '548', '1011001001' => '549', '1011010000' => '550', '1011010001' => '551',
220 '1011010010' => '552', '1011010011' => '553', '1011010100' => '554', '1011010101' => '555',
221 '1011010110' => '556', '1011010111' => '557', '1011011000' => '558', '1011011001' => '559',
222 '1011100000' => '560', '1011100001' => '561', '1011100010' => '562', '1011100011' => '563',
223 '1011100100' => '564', '1011100101' => '565', '1011100110' => '566', '1011100111' => '567',
224 '1011101000' => '568', '1011101001' => '569', '1011110000' => '570', '1011110001' => '571',
225 '1011110010' => '572', '1011110011' => '573', '1011110100' => '574', '1011110101' => '575',
226 '1011110110' => '576', '1011110111' => '577', '1011111000' => '578', '1011111001' => '579',
227 '1010001010' => '580', '1010001011' => '581', '1010101010' => '582', '1010101011' => '583',
228 '1011001010' => '584', '1011001011' => '585', '1011101010' => '586', '1011101011' => '587',
229 '1011001110' => '588', '1011001111' => '589', '1010011010' => '590', '1010011011' => '591',
230 '1010111010' => '592', '1010111011' => '593', '1011011010' => '594', '1011011011' => '595',
231 '1011111010' => '596', '1011111011' => '597', '1011011110' => '598', '1011011111' => '599',
232 '1100000000' => '600', '1100000001' => '601', '1100000010' => '602', '1100000011' => '603',
233 '1100000100' => '604', '1100000101' => '605', '1100000110' => '606', '1100000111' => '607',
234 '1100001000' => '608', '1100001001' => '609', '1100010000' => '610', '1100010001' => '611',
235 '1100010010' => '612', '1100010011' => '613', '1100010100' => '614', '1100010101' => '615',
236 '1100010110' => '616', '1100010111' => '617', '1100011000' => '618', '1100011001' => '619',
237 '1100100000' => '620', '1100100001' => '621', '1100100010' => '622', '1100100011' => '623',
238 '1100100100' => '624', '1100100101' => '625', '1100100110' => '626', '1100100111' => '627',
239 '1100101000' => '628', '1100101001' => '629', '1100110000' => '630', '1100110001' => '631',
240 '1100110010' => '632', '1100110011' => '633', '1100110100' => '634', '1100110101' => '635',
241 '1100110110' => '636', '1100110111' => '637', '1100111000' => '638', '1100111001' => '639',
242 '1101000000' => '640', '1101000001' => '641', '1101000010' => '642', '1101000011' => '643',
243 '1101000100' => '644', '1101000101' => '645', '1101000110' => '646', '1101000111' => '647',
244 '1101001000' => '648', '1101001001' => '649', '1101010000' => '650', '1101010001' => '651',
245 '1101010010' => '652', '1101010011' => '653', '1101010100' => '654', '1101010101' => '655',
246 '1101010110' => '656', '1101010111' => '657', '1101011000' => '658', '1101011001' => '659',
247 '1101100000' => '660', '1101100001' => '661', '1101100010' => '662', '1101100011' => '663',
248 '1101100100' => '664', '1101100101' => '665', '1101100110' => '666', '1101100111' => '667',
249 '1101101000' => '668', '1101101001' => '669', '1101110000' => '670', '1101110001' => '671',
250 '1101110010' => '672', '1101110011' => '673', '1101110100' => '674', '1101110101' => '675',
251 '1101110110' => '676', '1101110111' => '677', '1101111000' => '678', '1101111001' => '679',
252 '1100001010' => '680', '1100001011' => '681', '1100101010' => '682', '1100101011' => '683',
253 '1101001010' => '684', '1101001011' => '685', '1101101010' => '686', '1101101011' => '687',
254 '1101001110' => '688', '1101001111' => '689', '1100011010' => '690', '1100011011' => '691',
255 '1100111010' => '692', '1100111011' => '693', '1101011010' => '694', '1101011011' => '695',
256 '1101111010' => '696', '1101111011' => '697', '1101011110' => '698', '1101011111' => '699',
257 '1110000000' => '700', '1110000001' => '701', '1110000010' => '702', '1110000011' => '703',
258 '1110000100' => '704', '1110000101' => '705', '1110000110' => '706', '1110000111' => '707',
259 '1110001000' => '708', '1110001001' => '709', '1110010000' => '710', '1110010001' => '711',
260 '1110010010' => '712', '1110010011' => '713', '1110010100' => '714', '1110010101' => '715',
261 '1110010110' => '716', '1110010111' => '717', '1110011000' => '718', '1110011001' => '719',
262 '1110100000' => '720', '1110100001' => '721', '1110100010' => '722', '1110100011' => '723',
263 '1110100100' => '724', '1110100101' => '725', '1110100110' => '726', '1110100111' => '727',
264 '1110101000' => '728', '1110101001' => '729', '1110110000' => '730', '1110110001' => '731',
265 '1110110010' => '732', '1110110011' => '733', '1110110100' => '734', '1110110101' => '735',
266 '1110110110' => '736', '1110110111' => '737', '1110111000' => '738', '1110111001' => '739',
267 '1111000000' => '740', '1111000001' => '741', '1111000010' => '742', '1111000011' => '743',
268 '1111000100' => '744', '1111000101' => '745', '1111000110' => '746', '1111000111' => '747',
269 '1111001000' => '748', '1111001001' => '749', '1111010000' => '750', '1111010001' => '751',
270 '1111010010' => '752', '1111010011' => '753', '1111010100' => '754', '1111010101' => '755',
271 '1111010110' => '756', '1111010111' => '757', '1111011000' => '758', '1111011001' => '759',
272 '1111100000' => '760', '1111100001' => '761', '1111100010' => '762', '1111100011' => '763',
273 '1111100100' => '764', '1111100101' => '765', '1111100110' => '766', '1111100111' => '767',
274 '1111101000' => '768', '1111101001' => '769', '1111110000' => '770', '1111110001' => '771',
275 '1111110010' => '772', '1111110011' => '773', '1111110100' => '774', '1111110101' => '775',
276 '1111110110' => '776', '1111110111' => '777', '1111111000' => '778', '1111111001' => '779',
277 '1110001010' => '780', '1110001011' => '781', '1110101010' => '782', '1110101011' => '783',
278 '1111001010' => '784', '1111001011' => '785', '1111101010' => '786', '1111101011' => '787',
279 '1111001110' => '788', '1111001111' => '789', '1110011010' => '790', '1110011011' => '791',
280 '1110111010' => '792', '1110111011' => '793', '1111011010' => '794', '1111011011' => '795',
281 '1111111010' => '796', '1111111011' => '797', '1111011110' => '798', '1111011111' => '799',
282 '0000001100' => '800', '0000001101' => '801', '0100001100' => '802', '0100001101' => '803',
283 '1000001100' => '804', '1000001101' => '805', '1100001100' => '806', '1100001101' => '807',
284 '0000101110' => '808', '0000101111' => '809', '0000011100' => '810', '0000011101' => '811',
285 '0100011100' => '812', '0100011101' => '813', '1000011100' => '814', '1000011101' => '815',
286 '1100011100' => '816', '1100011101' => '817', '0000111110' => '818', '0000111111' => '819',
287 '0000101100' => '820', '0000101101' => '821', '0100101100' => '822', '0100101101' => '823',
288 '1000101100' => '824', '1000101101' => '825', '1100101100' => '826', '1100101101' => '827',
289 '0100101110' => '828', '0100101111' => '829', '0000111100' => '830', '0000111101' => '831',
290 '0100111100' => '832', '0100111101' => '833', '1000111100' => '834', '1000111101' => '835',
291 '1100111100' => '836', '1100111101' => '837', '0100111110' => '838', '0100111111' => '839',
292 '0001001100' => '840', '0001001101' => '841', '0101001100' => '842', '0101001101' => '843',
293 '1001001100' => '844', '1001001101' => '845', '1101001100' => '846', '1101001101' => '847',
294 '1000101110' => '848', '1000101111' => '849', '0001011100' => '850', '0001011101' => '851',
295 '0101011100' => '852', '0101011101' => '853', '1001011100' => '854', '1001011101' => '855',
296 '1101011100' => '856', '1101011101' => '857', '1000111110' => '858', '1000111111' => '859',
297 '0001101100' => '860', '0001101101' => '861', '0101101100' => '862', '0101101101' => '863',
298 '1001101100' => '864', '1001101101' => '865', '1101101100' => '866', '1101101101' => '867',
299 '1100101110' => '868', '1100101111' => '869', '0001111100' => '870', '0001111101' => '871',
300 '0101111100' => '872', '0101111101' => '873', '1001111100' => '874', '1001111101' => '875',
301 '1101111100' => '876', '1101111101' => '877', '1100111110' => '878', '1100111111' => '879',
302 '0000001110' => '880', '0000001111' => '881', '0100001110' => '882', '0100001111' => '883',
303 '1000001110' => '884', '1000001111' => '885', '1100001110' => '886', '1100001111' => '887',
304 '0001101110' => '888', '0001101111' => '889', '0000011110' => '890', '0000011111' => '891',
305 '0100011110' => '892', '0100011111' => '893', '1000011110' => '894', '1000011111' => '895',
306 '1100011110' => '896', '1100011111' => '897', '0001111110' => '898', '0001111111' => '899',
307 '0010001100' => '900', '0010001101' => '901', '0110001100' => '902', '0110001101' => '903',
308 '1010001100' => '904', '1010001101' => '905', '1110001100' => '906', '1110001101' => '907',
309 '0010101110' => '908', '0010101111' => '909', '0010011100' => '910', '0010011101' => '911',
310 '0110011100' => '912', '0110011101' => '913', '1010011100' => '914', '1010011101' => '915',
311 '1110011100' => '916', '1110011101' => '917', '0010111110' => '918', '0010111111' => '919',
312 '0010101100' => '920', '0010101101' => '921', '0110101100' => '922', '0110101101' => '923',
313 '1010101100' => '924', '1010101101' => '925', '1110101100' => '926', '1110101101' => '927',
314 '0110101110' => '928', '0110101111' => '929', '0010111100' => '930', '0010111101' => '931',
315 '0110111100' => '932', '0110111101' => '933', '1010111100' => '934', '1010111101' => '935',
316 '1110111100' => '936', '1110111101' => '937', '0110111110' => '938', '0110111111' => '939',
317 '0011001100' => '940', '0011001101' => '941', '0111001100' => '942', '0111001101' => '943',
318 '1011001100' => '944', '1011001101' => '945', '1111001100' => '946', '1111001101' => '947',
319 '1010101110' => '948', '1010101111' => '949', '0011011100' => '950', '0011011101' => '951',
320 '0111011100' => '952', '0111011101' => '953', '1011011100' => '954', '1011011101' => '955',
321 '1111011100' => '956', '1111011101' => '957', '1010111110' => '958', '1010111111' => '959',
322 '0011101100' => '960', '0011101101' => '961', '0111101100' => '962', '0111101101' => '963',
323 '1011101100' => '964', '1011101101' => '965', '1111101100' => '966', '1111101101' => '967',
324 '1110101110' => '968', '1110101111' => '969', '0011111100' => '970', '0011111101' => '971',
325 '0111111100' => '972', '0111111101' => '973', '1011111100' => '974', '1011111101' => '975',
326 '1111111100' => '976', '1111111101' => '977', '1110111110' => '978', '1110111111' => '979',
327 '0010001110' => '980', '0010001111' => '981', '0110001110' => '982', '0110001111' => '983',
328 '1010001110' => '984', '1010001111' => '985', '1110001110' => '986', '1110001111' => '987',
329 '0011101110' => '988', '0011101111' => '989', '0010011110' => '990', '0010011111' => '991',
330 '0110011110' => '992', '0110011111' => '993', '1010011110' => '994', '1010011111' => '995',
331 '1110011110' => '996', '1110011111' => '997', '0011111110' => '998', '0011111111' => '999',
332 ) : ();
333  
334 #######################################################################
335 #######################################################################
336  
337 # %Math::Decimal128::dpd_decode is simply %Math::Decimal128::dpd_encode
338 # with the keys and values interchanged.
339  
340 31 for my $key(keys(%Math::Decimal128::dpd_encode)) {
341 0 $Math::Decimal128::dpd_decode{$Math::Decimal128::dpd_encode{$key}} = $key;
342 }
343  
344 #######################################################################
345 #######################################################################
346  
347 31 ▶%Math::Decimal128::bid_decode = $Math::Decimal128::fmt eq 'BID' ? (
Branch: 1 branch
BranchTrueFalseTotal
$Math::Decimal128::fmt eq 'BID' ? : 31 0 31
348 0 => MEtoD128('1' . ('0' x 33), 0), 1 => MEtoD128('1' . ('0' x 32), 0),
349 2 => MEtoD128('1' . ('0' x 31), 0), 3 => MEtoD128('1' . ('0' x 30), 0),
350 4 => MEtoD128('1' . ('0' x 29), 0), 5 => MEtoD128('1' . ('0' x 28), 0),
351 6 => MEtoD128('1' . ('0' x 27), 0), 7 => MEtoD128('1' . ('0' x 26), 0),
352 8 => MEtoD128('1' . ('0' x 25), 0), 9 => MEtoD128('1' . ('0' x 24), 0),
353 10 => MEtoD128('1' . ('0' x 23), 0), 11 => MEtoD128('1' . ('0' x 22), 0),
354 12 => MEtoD128('1' . ('0' x 21), 0), 13 => MEtoD128('1' . ('0' x 20), 0),
355 14 => MEtoD128('1' . ('0' x 19), 0), 15 => MEtoD128('1' . ('0' x 18), 0),
356 16 => MEtoD128('1' . ('0' x 17), 0), 17 => MEtoD128('1' . ('0' x 16), 0),
357 18 => MEtoD128('1' . ('0' x 15), 0), 19 => MEtoD128('1' . ('0' x 14), 0),
358 20 => MEtoD128('1' . ('0' x 13), 0), 21 => MEtoD128('1' . ('0' x 12), 0),
359 22 => MEtoD128('1' . ('0' x 11), 0), 23 => MEtoD128('1' . ('0' x 10), 0),
360 24 => MEtoD128('1' . ('0' x 9), 0), 25 => MEtoD128('1' . ('0' x 8), 0),
361 26 => MEtoD128('1' . ('0' x 7), 0), 27 => MEtoD128('1' . ('0' x 6), 0),
362 28 => MEtoD128('1' . ('0' x 5), 0), 29 => MEtoD128('1' . ('0' x 4), 0),
363 30 => MEtoD128('1' . ('0' x 3), 0), 31 => MEtoD128('1' . ('0' x 2), 0),
364 32 => MEtoD128('1' . ('0' x 1), 0), 33 => MEtoD128('1', 0)
365 ) : ();
366  
367 #######################################################################
368 #######################################################################
369 # Used only wrt BID encoding
370  
371 189587 ▶sub _decode_mant {
Subroutine _decode_mant: called CC=4 SCAR=13.9
372 189587 my $val = shift;
373 189587 my $ret = '';
374 189587 for my $i(0 .. 33) {
375 6445958 my $count = 0;
376 6445958 ▶ if($val > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val > 0) 4180017 2265941 6445958
377 4180017 ▶ while($val >= $Math::Decimal128::bid_decode{$i}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val >= $Math::Decimal128::bid_decode{$i}) 7370336 4180017 11550353
378 7370336 $val -= $Math::Decimal128::bid_decode{$i};
379 7370336 $count++;
380 }
381 }
382 6445958 $ret .= $count;
383 }
384 189587 return $ret;
385 }
386  
387 #######################################################################
388 #######################################################################
389  
390 31 ▶sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaking
Subroutine dl_load_flags: called CC=1 SCAR=0.0
Pod undocumented
391  
392 #######################################################################
393 #######################################################################
394  
395 60 ▶sub _overload_string {
Subroutine _overload_string: called CC=3 SCAR=11.0
396 60 my @ret = D128toME($_[0]);
397 60 ▶ if(is_InfD128($_[0]) || !$_[0]) {return $ret[0]}
Branch: 1 branch
BranchTrueFalseTotal
if (is_InfD128($_[0]) or not $_[0]) 12 48 60
Condition66%2/3
is_InfD128($_[0]) or not $_[0]
l!l&&r!l&&!r
01248
MC/DC50%1/2
is_InfD128($_[0]) or not $_[0]
is_InfD128($_[0]) not $_[0]
Truth table66%2/3
A or not(B)
A= is_InfD128($_[0])B= not $_[0]
ABresult
1X1
011
000
398 48 return $ret[0] . 'e' . $ret[1];
399 }
400  
401 #######################################################################
402 #######################################################################
403  
404 47732 ▶sub _overload_int {
Subroutine _overload_int: called CC=8 SCAR=20.8
405 47732 ▶ if(is_NaND128($_[0]) || is_InfD128($_[0]) || is_ZeroD128($_[0])) {return $_[0]}
Branch: 1 branch
BranchTrueFalseTotal
if (is_NaND128($_[0]) or is_InfD128($_[0]) or is_ZeroD128($_[0])) 326 47406 47732
Condition100%6/6
is_NaND128($_[0]) or is_InfD128($_[0]) or is_ZeroD128($_[0])
l!l&&r!l&&!r
432247406
is_NaND128($_[0]) or is_InfD128($_[0])
l!l&&r!l&&!r
2247728
MC/DC100%3/3
is_NaND128($_[0]) or is_InfD128($_[0]) or is_ZeroD128($_[0])
is_NaND128($_[0]) is_InfD128($_[0]) is_ZeroD128($_[0])
Truth table100%4/4
A or B or C
A= is_NaND128($_[0])B= is_InfD128($_[0])C= is_ZeroD128($_[0])
ABCresult
1XX1
01X1
0011
0000
406 47406 my($man, $exp) = D128toME($_[0]);
407 47406 ▶ if($exp >= 0) {return $_[0]}
Branch: 1 branch
BranchTrueFalseTotal
if ($exp >= 0) 23510 23896 47406
408 23896 my $man_length = length($man);
409 23896 ▶ $man_length-- if $man =~ /^\-/;
Branch: 1 branch
BranchTrueFalseTotal
if $man =~ /^\-/ 23888 8 23896
410 23896 ▶ if(-$exp >= $man_length) { # -1 <= $_[0] <= 1
Branch: 1 branch
BranchTrueFalseTotal
if (-$exp >= $man_length) 23881 15 23896
411 23881 my $z = ZeroD128(1);
412 23881 ▶ if($_[0] < $z) {return ZeroD128(-1)} # return -0
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] < $z) 23880 1 23881
413 1 return $z; # return 0
414 }
415  
416 15 substr($man, $exp, -$exp, '');
417 15 return MEtoD128($man, 0);
418 }
419  
420 #######################################################################
421 #######################################################################
422  
423 309407 ▶sub new {
Subroutine new: called CC=14 SCAR=26.4
Pod undocumented
424  
425 # This function caters for 2 possibilities:
426 # 1) that 'new' has been called OOP style - in which
427 # case there will be a maximum of 2 args
428 # 2) that 'new' has been called as a function - in
429 # which case there will be a maximum of 1 arg.
430 # If there are no args, then we just want to return a
431 # Math::Decimal128 object that's a NaN.
432  
433 309407 ▶ if(!@_) {return NaND128()}
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 1 309406 309407
434  
435 309406 ▶ if(@_ > 3) {die "More than 3 arguments supplied to new()"}
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 3) 2 309404 309406
436  
437 # If 'new' has been called OOP style, the first arg is the string
438 # "Math::Decimal128" which we don't need - so let's remove it. However,
439 # if the first arg is a Math::Decimal128 object (which is a possibility),
440 # then we'll get a fatal error when we check it for equivalence to
441 # the string "Math::Decimal128". So we first need to check that it's not
442 # an object - which we'll do by using the ref() function:
443 309404 ▶ if(!ref($_[0]) && $_[0] eq "Math::Decimal128") {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_[0] and $_[0] eq "Math::Decimal128") 309393 11 309404
Condition100%3/3
not ref $_[0] and $_[0] eq "Math::Decimal128"
!ll&&!rl&&r
29309393
MC/DC100%2/2
not ref $_[0] and $_[0] eq "Math::Decimal128"
not ref $_[0] $_[0] eq "Math::Decimal128"
Truth table100%3/3
not(A) and B
A= not ref $_[0]B= $_[0] eq "Math::Decimal128"
ABresult
0X0
100
111
444 309393 shift;
445 309393 ▶ if(!@_) {return NaND128()}
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 11 309382 309393
446 }
447  
448 # @_ can now contain max of 2 vals - the mantissa and exponent.
449 # If @_ == 1 then it contains the value.
450 309393 ▶ if(@_ > 2) {die "Too many arguments supplied to new() - expected no more than 2"}
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2) 1 309392 309393
451  
452 309392 ▶ if(@_ == 2) {return MEtoD128(shift, shift)}
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) 309258 134 309392
453  
454 134 my $arg = shift;
455 134 my $type = _itsa($arg);
456  
457 134 ▶ if($type == 1) { # UV
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 1) 13 121 134
458 13 return UVtoD128($arg);
459 }
460  
461 121 ▶ if($type == 2) { # IV
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 2) 16 105 121
462 16 return IVtoD128($arg);
463 }
464  
465 105 ▶ if($type == 3) { # NV
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 3) 3 102 105
466 3 die "new() cannot be used to assign an NV - use NVtoD128() instead";
467 }
468  
469 102 ▶ if($type == 4) { # PV
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 4) 74 28 102
470 74 ▶ return STRtoD128($arg) if have_strtod128();
Branch: 1 branch
BranchTrueFalseTotal
if have_strtod128() 0 74 74
471 74 return PVtoD128($arg);
472 }
473  
474 28 ▶ if($type == 34) { # Math::Decimal128 object
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 34) 25 3 28
475 25 return D128toD128($arg);
476 }
477  
478 3 die "Bad argument given to new";
479 }
480  
481 #######################################################################
482 #######################################################################
483  
484 179930 ▶sub D128toME {
Subroutine D128toME: called CC=3 SCAR=11.0
Pod undocumented
485 179930 my($ret1, $ret2) = split /e/i, decode_d128($_[0]);
486 179930 ▶ $ret2 = 0 unless defined $ret2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ret2 35 179895 179930
487 179930 ▶ $ret2 = 0 if is_ZeroD128($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if is_ZeroD128($_[0]) 944 178986 179930
488 179930 return ($ret1, $ret2);
489 }
490  
491 #######################################################################
492 #######################################################################
493  
494 373675 ▶sub MEtoD128 {
Subroutine MEtoD128: called CC=11 SCAR=24.0
Pod undocumented
495 # Check that 2 args are supplied
496 373675 ▶ die "MEtoD128 takes 2 args" if @_ != 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 373675 373675
497  
498 373675 my ($arg1, $arg2) = (shift, shift);
499  
500 373675 ▶ die "Invalid 1st arg ($arg1) to MEtoD128" if $arg1 =~ /[^0-9\-\+]/;
Branch: 1 branch
BranchTrueFalseTotal
if $arg1 =~ /[^0-9\-\+]/ 1 373674 373675
501 373674 ▶ die "Invalid 2nd arg ($arg2) to MEtoD128" if $arg2 =~ /[^0-9\-\+]/;
Branch: 1 branch
BranchTrueFalseTotal
if $arg2 =~ /[^0-9\-\+]/ 0 373674 373674
502  
503 373674 $arg1 =~ s/^\+//;
504 373674 $arg2 =~ s/^\+//;
505 373674 ▶ my $sign = $arg1 =~ s/^\-// ? '-' : '';
Branch: 1 branch
BranchTrueFalseTotal
$arg1 =~ s/^\-// ? : 198212 175462 373674
506  
507 373674 my $len_1 = length($arg1);
508  
509 373674 ▶ if($len_1 > 34 || $arg2 < -6176) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len_1 > 34 or $arg2 < -6176) 11279 362395 373674
Condition100%3/3
$len_1 > 34 or $arg2 < -6176
l!l&&r!l&&!r
111278362395
MC/DC100%2/2
$len_1 > 34 or $arg2 < -6176
$len_1 > 34 $arg2 < -6176
Truth table100%3/3
A or B
A= $len_1 > 34B= $arg2 < -6176
ABresult
1X1
011
000
510 11279 ▶ die "$arg1 exceeds _Decimal128 precision. It needs to be shortened to no more than 34 decimal digits"
Branch: 1 branch
BranchTrueFalseTotal
if $len_1 > 34 1 11278 11279
511 if $len_1 > 34;
512 11278 ($arg1, $arg2) = _round_as_needed($arg1, $arg2);
513 }
514  
515 # split $arg1 into segments that don't exceed 16 digits.
516  
517 373673 my($msd, $nsd, $lsd);
518  
519 {
520 31 ▶ no warnings 'substr';
Subroutine BEGIN: called CC=1 SCAR=0.0
521 373673 ▶ $msd = substr($arg1, -34, 10) || '0';
Condition100%2/2
substr($arg1, -34, 10) || '0'
l!l
13453360220
MC/DC100%1/1
substr($arg1, -34, 10) || '0'
substr($arg1, -34, 10)
Truth table100%2/2
A
A= substr($arg1, -34, 10)
Aresult
11
00
522 373673 ▶ $nsd = substr($arg1, -24, 12) || '0';
Condition100%2/2
substr($arg1, -24, 12) || '0'
l!l
107498266175
MC/DC100%1/1
substr($arg1, -24, 12) || '0'
substr($arg1, -24, 12)
Truth table100%2/2
A
A= substr($arg1, -24, 12)
Aresult
11
00
523 373673 ▶ $lsd = substr($arg1, -12, 12) || '0';
Condition100%2/2
substr($arg1, -12, 12) || '0'
l!l
3712822391
MC/DC100%1/1
substr($arg1, -12, 12) || '0'
substr($arg1, -12, 12)
Truth table100%2/2
A
A= substr($arg1, -12, 12)
Aresult
11
00
524 }
525  
526 373673 return _MEtoD128($sign . $msd, $sign . $nsd, $sign . $lsd, $arg2);
527  
528 }
529  
530 #######################################################################
531 #######################################################################
532  
533 # Values such as (d, -6178), (dd, -6179), (ddd, -6180), etc evaluate to zero.
534 # But values such as (dddd, -6178), (ddd, -6179), (dddddddd, -6180), etc may be non-zero.
535 # In such cases we'll remove the ignored (trailing) digits, rounding the leading
536 # digits to nearest - tied to even for midway cases.
537  
538 11278 ▶sub _round_as_needed {
Subroutine _round_as_needed: called CC=9 SCAR=22.0
539 11278 my($sign, $man, $exp) = ('', shift, shift);
540  
541 11278 ▶ if($man =~ /^\-/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($man =~ /^\-/) 0 11278 11278
542 0 $man =~ s/^\-//;
543 0 $sign = '-';
544 }
545  
546 11278 my $length = length $man;
547 11278 my $maxlen = -6176 - $exp;
548  
549 11278 ▶ if($length >= $maxlen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length >= $maxlen) 4286 6992 11278
550 4286 my $rounder = substr($man, $length - $maxlen); # The trailing (ignored) digits
551 4286 ▶ $man = $length > $maxlen ? substr($man, 0, $length - $maxlen)
Branch: 1 branch
BranchTrueFalseTotal
$length > $maxlen ? : 4025 261 4286
552 : '0';
553 4286 my $roundup = 0;
554 4286 ▶ $roundup = 1 if substr($rounder, 0, 1) > 5;
Branch: 1 branch
BranchTrueFalseTotal
if substr($rounder, 0, 1) > 5 1737 2549 4286
555 4286 ▶ $roundup = 1 if ((substr($rounder, 0, 1) == 5) &&
Branch: 1 branch
BranchTrueFalseTotal
if substr($rounder, 0, 1) == 5 and substr($rounder, 1) =~ /[1-9]/ || substr($man, -1, 1) % 2 == 1 386 3900 4286
Condition100%6/6
substr($rounder, 0, 1) == 5 and substr($rounder, 1) =~ /[1-9]/ || substr($man, -1, 1) % 2 == 1
!ll&&!rl&&r
388020386
substr($rounder, 1) =~ /[1-9]/ or substr($man, -1, 1) % 2 == 1
l!l&&r!l&&!r
3691720
MC/DC100%3/3
substr($rounder, 0, 1) == 5 and substr($rounder, 1) =~ /[1-9]/ || substr($man, -1, 1) % 2 == 1
substr($rounder, 0, 1) == 5 substr($rounder, 1) =~ /[1-9]/ substr($man, -1, 1) % 2 == 1
Truth table100%4/4
A and B or C
A= substr($rounder, 0, 1) == 5B= substr($rounder, 1) =~ /[1-9]/C= substr($man, -1, 1) % 2 == 1
ABCresult
0XX0
1000
11X1
1011
556 ((substr($rounder, 1) =~ /[1-9]/) || (substr($man, -1, 1) %2 == 1)));
557  
558 4286 ▶ $man++ if $roundup;
Branch: 1 branch
BranchTrueFalseTotal
if $roundup 2123 2163 4286
559 4286 $exp += $maxlen; # Removal of trailing digits moved the implied
560 # decimal point $maxlen places to the left
561 }
562  
563 11278 return ($sign . $man, $exp);
564 }
565  
566 #######################################################################
567 #######################################################################
568  
569 13 ▶sub assignMEl {
Subroutine assignMEl: called CC=13 SCAR=26.7
Pod undocumented
570 # Check that 3 args are supplied
571 13 ▶ die "assignMEl takes 3 args" if @_ != 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 3 0 13 13
572  
573 13 my $arg1 = shift;
574 13 my $arg2 = shift;
575 13 my $arg3 = shift;
576  
577 13 ▶ die "Invalid 1st arg ($arg1) to assignMEl" if _itsa($arg1) != 34;
Branch: 1 branch
BranchTrueFalseTotal
if _itsa($arg1) != 34 2 11 13
578 11 ▶ die "Invalid 2nd arg ($arg2) to assignMEl" if $arg2 =~ /[^0-9\-]/;
Branch: 1 branch
BranchTrueFalseTotal
if $arg2 =~ /[^0-9\-]/ 0 11 11
579 11 ▶ die "Invalid 3rd arg ($arg3) to assignMEl" if $arg3 =~ /[^0-9\-]/;
Branch: 1 branch
BranchTrueFalseTotal
if $arg3 =~ /[^0-9\-]/ 0 11 11
580  
581 11 my $len_2 = length($arg2);
582 11 ▶ my $sign = $arg2 =~ /^\-/ ? '-' : '';
Branch: 1 branch
BranchTrueFalseTotal
$arg2 =~ /^\-/ ? : 4 7 11
583 11 ▶ if($sign) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sign) 4 7 11
584 4 $len_2--;
585 4 $arg2 =~ s/^\-//;
586 }
587  
588 11 ▶ if($len_2 > 34 || $arg3 < -6176) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len_2 > 34 or $arg3 < -6176) 0 11 11
Condition33%1/3
$len_2 > 34 or $arg3 < -6176
l!l&&r!l&&!r
0011
MC/DC0%0/2
$len_2 > 34 or $arg3 < -6176
$len_2 > 34 $arg3 < -6176
Truth table33%1/3
A or B
A= $len_2 > 34B= $arg3 < -6176
ABresult
1X1
011
000
589 0 ▶ die "$arg2 exceeds _Decimal128 precision. It needs to be shortened to no more than 34 decimal digits"
Branch: 1 branch
BranchTrueFalseTotal
if $len_2 > 34 0 0 0
590 if $len_2 > 34;
591 0 ($arg2, $arg3) = _round_as_needed($arg2, $arg3);
592 }
593  
594 11 my($msd, $nsd, $lsd);
595  
596 {
597 31 ▶ no warnings 'substr';
Subroutine BEGIN: called CC=1 SCAR=0.0
598 11 ▶ $msd = substr($arg2, -34, 10) || '0';
Condition100%2/2
substr($arg2, -34, 10) || '0'
l!l
29
MC/DC100%1/1
substr($arg2, -34, 10) || '0'
substr($arg2, -34, 10)
Truth table100%2/2
A
A= substr($arg2, -34, 10)
Aresult
11
00
599 11 ▶ $nsd = substr($arg2, -24, 12) || '0';
Condition100%2/2
substr($arg2, -24, 12) || '0'
l!l
29
MC/DC100%1/1
substr($arg2, -24, 12) || '0'
substr($arg2, -24, 12)
Truth table100%2/2
A
A= substr($arg2, -24, 12)
Aresult
11
00
600 11 ▶ $lsd = substr($arg2, -12, 12) || '0';
Condition100%2/2
substr($arg2, -12, 12) || '0'
l!l
101
MC/DC100%1/1
substr($arg2, -12, 12) || '0'
substr($arg2, -12, 12)
Truth table100%2/2
A
A= substr($arg2, -12, 12)
Aresult
11
00
601 }
602  
603 11 return _assignME($arg1, $sign . $msd, $sign . $nsd, $sign . $lsd, $arg3);
604  
605 }
606  
607 #######################################################################
608 #######################################################################
609  
610 0 ▶sub _sci2me {
Subroutine _sci2me: not called CC=3 SCAR=24.8
611 0 my @ret = split /e/i, $_[0];
612 0 ▶ chop $ret[0] while $ret[0] =~ /0\b/;
Branch: 1 branch
BranchTrueFalseTotal
$ret[0] =~ /0\b/ and do { chop $ret[0] } 0 0 0
613 0 my @adj = split /\./, $ret[0];
614 0 ▶ my $adj = defined $adj[1] ? length($adj[1])
Branch: 1 branch
BranchTrueFalseTotal
defined $adj[1] ? : 0 0 0
615 : 0;
616 0 $ret[0] =~ s/\.//;
617 0 $ret[1] += $_[1] - $adj;
618  
619 0 return @ret;
620 }
621  
622 #######################################################################
623 #######################################################################
624  
625 8 ▶sub DEC128_MAX () {return _DEC128_MAX()}
Subroutine DEC128_MAX: called CC=1 SCAR=0.0
626 9 ▶sub DEC128_MIN () {return _DEC128_MIN()}
Subroutine DEC128_MIN: called CC=1 SCAR=0.0
627  
628 #######################################################################
629 #######################################################################
630  
631 199425 ▶sub d128_bytes {
Subroutine d128_bytes: called CC=1 SCAR=0.0
Pod undocumented
632 199425 my @ret = _d128_bytes($_[0]);
633 199425 return join '', @ret;
634 }
635  
636 #######################################################################
637 #######################################################################
638  
639 194487 ▶sub hex2binl {
Subroutine hex2binl: called CC=2 SCAR=7.0
Pod undocumented
640 194487 my $ret = unpack("B*", (pack "H*", $_[0]));
641 194487 my $len = length $ret;
642 194487 ▶ die "hex2binl() yielded $len bits" if $len != 128;
Branch: 1 branch
BranchTrueFalseTotal
if $len != 128 0 194487 194487
643 194487 return $ret;
644 }
645  
646 #######################################################################
647 #######################################################################
648  
649 38 ▶sub d128_fmt {
Subroutine d128_fmt: called CC=3 SCAR=12.5
Pod undocumented
650 38 my $d128 = MEtoD128('1234567890123456789012345678901234', 0);
651 # DPD: 2608134B9C1E28E56F3C127177823534
652 # BID: 30403CDE6FFF9732DE825CD07E96AFF2
653 38 ▶ return 'DPD' if d128_bytes($d128) =~ /534$/i;
Branch: 1 branch
BranchTrueFalseTotal
if d128_bytes($d128) =~ /534$/i 0 38 38
654 38 ▶ return 'BID' if d128_bytes($d128) =~ /FF2$/i;
Branch: 1 branch
BranchTrueFalseTotal
if d128_bytes($d128) =~ /FF2$/i 38 0 38
655 0 return 'Unknown';
656 }
657  
658 #######################################################################
659 #######################################################################
660  
661 0 ▶sub decode_dpdl {
Subroutine decode_dpdl: not called CC=5 SCAR=34.0
Pod undocumented
662 # Takes the Math::Decimal128 object as its arg.
663 # Decodes Densely Packed Decimal formatting of the Decimal128 value.
664 0 my $binstring = hex2binl(d128_bytes($_[0]));
665 0 my @first = decode_dpd_1st($binstring);
666 0 ▶ return ($first[0] . $first[1]) if ($first[1] =~ /inf/i || $first[1] =~ /nan/i);
Branch: 1 branch
BranchTrueFalseTotal
if $first[1] =~ /inf/i or $first[1] =~ /nan/i 0 0 0
Condition0%0/3
$first[1] =~ /inf/i or $first[1] =~ /nan/i
l!l&&r!l&&!r
000
MC/DC0%0/2
$first[1] =~ /inf/i or $first[1] =~ /nan/i
$first[1] =~ /inf/i $first[1] =~ /nan/i
Truth table0%0/3
A or B
A= $first[1] =~ /inf/iB= $first[1] =~ /nan/i
ABresult
1X1
011
000
667 0 my $mantissa = $first[1] . decode_dpd_2nd($binstring);
668  
669 # Remove leading zeroes from the mantissa
670 0 $mantissa =~ s/^0+//;
671 0 ▶ if($mantissa eq '') {$mantissa = '0'}
Branch: 1 branch
BranchTrueFalseTotal
if ($mantissa eq '') { } 0 0 0
672 else {
673 # Remove trailing zeroes
674 0 ▶ while($mantissa =~ /0$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mantissa =~ /0$/) 0 0 0
675 0 $mantissa =~ s/0$//;
676 0 $first[2]++;
677 }
678 }
679  
680 0 my $ret = $first[0] . $mantissa . 'e' . $first[2];
681  
682 }
683  
684 #######################################################################
685 #######################################################################
686  
687 0 ▶sub decode_dpd_1st{
Subroutine decode_dpd_1st: not called CC=11 SCAR=48.8
Pod undocumented
688 # Takes the entire binary string as its arg.
689 0 ▶ die "Argument to decode_dpd_1st is wrong size (", length($_[0]), ")"
Branch: 1 branch
BranchTrueFalseTotal
if length $_[0] != 128 0 0 0
690 if length($_[0]) != 128;
691 0 my $leading_bits = 18;
692 0 my $trailing_bits = 110;
693 0 my $msd; # significand's most siginificant digit
694 my $exp; # exponent
695 0 my $keep = substr($_[0], 0, $leading_bits);
696 0 ▶ my $sign = substr($keep, 0, 1) ? '-' : '';
Branch: 1 branch
BranchTrueFalseTotal
substr($keep, 0, 1) ? : 0 0 0
697 0 ▶ return ('','nan') if substr($keep, 1, 5) eq '11111';
Branch: 1 branch
BranchTrueFalseTotal
if substr($keep, 1, 5) eq 11111 0 0 0
698 0 ▶ if(substr($keep, 1 ,5) eq '11110') {return ($sign, 'inf')}
Branch: 1 branch
BranchTrueFalseTotal
if (substr($keep, 1, 5) eq 11110) 0 0 0
699 0 my $pre = substr($keep, 1, 2);
700 0 ▶ if($pre eq '00' || $pre eq '01' || $pre eq '10') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre eq "00" or $pre eq "01" or $pre eq 10) 0 0 0
Condition0%0/6
$pre eq "00" or $pre eq "01" or $pre eq 10
l!l&&r!l&&!r
000
$pre eq "00" or $pre eq "01"
l!l&&r!l&&!r
000
MC/DC0%0/3
$pre eq "00" or $pre eq "01" or $pre eq 10
$pre eq "00" $pre eq "01" $pre eq 10
Truth table0%0/4
A or B or C
A= $pre eq "00"B= $pre eq "01"C= $pre eq 10
ABCresult
1XX1
01X1
0011
0000
701 0 $msd = oct('0b0' . substr($keep, 3, 3));
702 0 $exp = oct('0b' . $pre . substr($keep, 6, 12)) - 6176;
703 0 return ($sign, $msd, $exp);
704 }
705 0 $pre = substr($keep, 1, 4);
706 0 ▶ if($pre eq '1100' || $pre eq '1101' || $pre eq '1110') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre eq 1100 or $pre eq 1101 or $pre eq 1110) 0 0 0
Condition0%0/6
$pre eq 1100 or $pre eq 1101 or $pre eq 1110
l!l&&r!l&&!r
000
$pre eq 1100 or $pre eq 1101
l!l&&r!l&&!r
000
MC/DC0%0/3
$pre eq 1100 or $pre eq 1101 or $pre eq 1110
$pre eq 1100 $pre eq 1101 $pre eq 1110
Truth table0%0/4
A or B or C
A= $pre eq 1100B= $pre eq 1101C= $pre eq 1110
ABCresult
1XX1
01X1
0011
0000
707 0 $exp = oct('0b' . substr($pre, 2, 2) . substr($keep, 6, 12)) - 6176;
708 0 $msd = oct('0b' . '100' . substr($keep, 5, 1));
709 0 return ($sign, $msd, $exp);
710 }
711 0 die "decode_dpd_1st function failed to parse its argument ($_[0])";
712 }
713  
714 #######################################################################
715 #######################################################################
716  
717 0 ▶sub decode_dpd_2nd {
Subroutine decode_dpd_2nd: not called CC=3 SCAR=24.8
Pod undocumented
718 # Takes the entire binary string as its arg.
719 0 ▶ die "Argument to decode_dpd_2nd is wrong size (", length($_[0]), ")"
Branch: 1 branch
BranchTrueFalseTotal
if length $_[0] != 128 0 0 0
720 if length($_[0]) != 128;
721 0 my $leading_bits = 18;
722 0 my $trailing_bits = 110;
723 0 my $keep = substr($_[0], $leading_bits, $trailing_bits);
724 0 my $ret = '';
725 0 for my $i(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100) {
726 0 my $key = substr($keep, $i, 10);
727 0 $ret .= $Math::Decimal128::dpd_encode{$key};
728 }
729 0 return $ret;
730 }
731  
732 #######################################################################
733 #######################################################################
734  
735 184763 ▶sub decode_bidl {
Subroutine decode_bidl: called CC=15 SCAR=34.8
Pod undocumented
736 # Takes a Math::Decimal128 object as its arg.
737 # Decodes Binary Integer Decimal formatting of the _Decimal128 value.
738  
739 184763 my $keep = hex2binl(d128_bytes($_[0]));
740 184763 ▶ die "Base 2 representation is wrong size (", length($keep), ")"
Branch: 1 branch
BranchTrueFalseTotal
if length $keep != 128 0 184763 184763
741 if length($keep) != 128;
742 184763 my $leading_bits = 17;
743 184763 my $trailing_bits = 111;
744 184763 my @mantissa;
745 my $exp; # exponent
746 184763 ▶ my $sign = substr($keep, 0, 1) ? '-' : '';
Branch: 1 branch
BranchTrueFalseTotal
substr($keep, 0, 1) ? : 104311 80452 184763
747 184763 ▶ return 'nan' if substr($keep, 1, 5) eq '11111';
Branch: 1 branch
BranchTrueFalseTotal
if substr($keep, 1, 5) eq 11111 13 184750 184763
748 184750 ▶ if(substr($keep, 1 ,5) eq '11110') {return $sign . 'inf'}
Branch: 1 branch
BranchTrueFalseTotal
if (substr($keep, 1, 5) eq 11110) 25 184725 184750
749 184725 my $pre = substr($keep, 1, 2);
750 184725 ▶ if($pre eq '00' || $pre eq '01' || $pre eq '10') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre eq "00" or $pre eq "01" or $pre eq 10) 184725 0 184725
Condition83%5/6
$pre eq "00" or $pre eq "01" or $pre eq 10
l!l&&r!l&&!r
1843503750
$pre eq "00" or $pre eq "01"
l!l&&r!l&&!r
378183972375
MC/DC0%0/3
$pre eq "00" or $pre eq "01" or $pre eq 10
$pre eq "00" $pre eq "01" $pre eq 10
Truth table75%3/4
A or B or C
A= $pre eq "00"B= $pre eq "01"C= $pre eq 10
ABCresult
1XX1
01X1
0011
0000
751 184725 $exp = oct('0b' . substr($keep, 1, 14)) - 6176;
752 184725 @mantissa = reverse(split(//, '0' . substr($keep, 15, 113)));
753 184725 my $m = _bid_mant(\@mantissa); # $m is a Math::Decimal128 object
754 184725 my $mantissa = _decode_mant($m);
755 184725 $mantissa =~ s/^0+//;
756 184725 ▶ if($mantissa !~ /[1-9]/) { $mantissa = '0'}
Branch: 1 branch
BranchTrueFalseTotal
if (not $mantissa =~ /[1-9]/) { } 968 183757 184725
757 else {
758 183757 ▶ while($mantissa =~ /0$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mantissa =~ /0$/) 2197140 183757 2380897
759 2197140 $mantissa =~ s/0$//;
760 2197140 $exp++;
761 }
762 }
763 184725 return $sign . $mantissa . 'e' . $exp;
764 }
765 0 $pre = substr($keep, 1, 4);
766 0 ▶ if($pre eq '1100' || $pre eq '1101' || $pre eq '1110') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre eq 1100 or $pre eq 1101 or $pre eq 1110) 0 0 0
Condition0%0/6
$pre eq 1100 or $pre eq 1101 or $pre eq 1110
l!l&&r!l&&!r
000
$pre eq 1100 or $pre eq 1101
l!l&&r!l&&!r
000
MC/DC0%0/3
$pre eq 1100 or $pre eq 1101 or $pre eq 1110
$pre eq 1100 $pre eq 1101 $pre eq 1110
Truth table0%0/4
A or B or C
A= $pre eq 1100B= $pre eq 1101C= $pre eq 1110
ABCresult
1XX1
01X1
0011
0000
767 0 $exp = oct('0b' . substr($keep, 3, 14)) - 6176;
768 0 @mantissa = reverse(split(//,'100' . substr($keep, 17, 111)));
769 0 my $m = _bid_mant(\@mantissa); # $m is a Math::Decimal128 object
770 0 my $mantissa = _decode_mant($m);
771 0 $mantissa =~ s/^0+//;
772 0 ▶ if($mantissa !~ /[1-9]/) { $mantissa = '0'}
Branch: 1 branch
BranchTrueFalseTotal
if (not $mantissa =~ /[1-9]/) { } 0 0 0
773 else {
774 0 ▶ while($mantissa =~ /0$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mantissa =~ /0$/) 0 0 0
775 0 $mantissa =~ s/0$//;
776 0 $exp++;
777 }
778 }
779 0 return $sign . $mantissa . 'e' . $exp;
780 }
781 0 die "decode_bid function failed to parse its argument ($_[0])";
782 }
783  
784 #######################################################################
785 #######################################################################
786 # Now using XSub of same name
787 # sub PVtoD128 {
788 #
789 # my($arg1, $arg2) = PVtoMEl($_[0]);
790 #
791 # if($arg1 =~ /inf|nan/i) {
792 # $arg1 =~ /nan/i ? return NaND128()
793 # : $arg1 =~ /^\-/ ? return InfD128(-1)
794 # : return InfD128(1);
795 # }
796 #
797 # return MEtoD128($arg1, $arg2);
798 #}
799  
800 #######################################################################
801 #######################################################################
802 # Now using XSub of same name
803 # sub assignPVl {
804 #
805 # my($arg1, $arg2) = PVtoMEl($_[1]);
806 # if($arg1 =~ /inf|nan/i) {
807 # $arg1 =~ /nan/i ? assignNaNl($_[0])
808 # : $arg1 =~ /^\-/ ? assignInfl($_[0], -1)
809 # : assignInfl($_[0], 1);
810 # }
811 # else {
812 # assignMEl($_[0], $arg1, $arg2);
813 # }
814 #}
815  
816 #######################################################################
817 #######################################################################
818  
819 0 ▶sub PVtoMEl {
Subroutine PVtoMEl: not called CC=2 SCAR=17.9
Pod undocumented
820  
821 0 my($arg1, $arg2) = split /e/i, $_[0];
822  
823 0 ▶ if($arg1 =~ /^(\-|\+)?inf|^(\-|\+)?nan/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg1 =~ /^(\-|\+)?inf|^(\-|\+)?nan/i) 0 0 0
824 0 return ($arg1, 0);
825 }
826  
827 0 _sanitise_args($arg1, $arg2);
828 0 return ($arg1, $arg2);
829 }
830  
831 #######################################################################
832 #######################################################################
833  
834 16 ▶sub MEtoPVl {
Subroutine MEtoPVl: called CC=2 SCAR=6.9
Pod undocumented
835 16 my $arg1 = shift;
836 16 ▶ if($arg1 =~ /^(\-|\+)?inf|^(\-|\+)?nan/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg1 =~ /^(\-|\+)?inf|^(\-|\+)?nan/i) 8 8 16
837 8 $arg1 =~ s/\+//;
838 8 return $arg1;
839 }
840  
841 8 my $arg2 = shift;
842 8 return $arg1 . 'e' . $arg2;
843 }
844  
845 #######################################################################
846 #######################################################################
847  
848 0 ▶sub _sanitise_args {
Subroutine _sanitise_args: not called CC=3 SCAR=24.8
849 0 ▶ $_[1] = 0 unless defined $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 0 0
850 0 $_[0] =~ s/\.0+$//;
851 0 my @split = split /\./, $_[0];
852 0 ▶ $split[1] = '' unless defined $split[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $split[1] 0 0 0
853 0 $_[1] -= length($split[1]);
854 0 $_[0] =~ s/\.//;
855 0 $_[0] =~ s/^0+//;
856 }
857  
858 #######################################################################
859 #######################################################################
860  
861 9724 ▶sub get_expl {
Subroutine get_expl: called CC=8 SCAR=29.4
Pod undocumented
862 9724 my $keep = hex2binl(d128_bytes($_[0]));
863 9724 my $pre = substr($keep, 1, 2);
864 9724 ▶ if($Math::Decimal128::fmt eq 'DPD') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Math::Decimal128::fmt eq 'DPD') { } 0 9724 9724
865 0 ▶ if($pre eq '00' || $pre eq '01' || $pre eq '10') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre eq '00' or $pre eq '01' or $pre eq '10') { } 0 0 0
Condition0%0/6
$pre eq "00" or $pre eq "01" or $pre eq 10
l!l&&r!l&&!r
000
$pre eq "00" or $pre eq "01"
l!l&&r!l&&!r
000
MC/DC0%0/3
$pre eq "00" or $pre eq "01" or $pre eq 10
$pre eq "00" $pre eq "01" $pre eq 10
Truth table0%0/4
A or B or C
A= $pre eq "00"B= $pre eq "01"C= $pre eq 10
ABCresult
1XX1
01X1
0011
0000
866 0 return oct('0b' . $pre . substr($keep, 6, 12)) - 6176;
867 }
868 else {
869 0 return oct('0b' . substr($pre, 2, 2) . substr($keep, 6, 12)) - 6176;
870 }
871 }
872 else {
873 9724 ▶ if($pre eq '00' || $pre eq '01' || $pre eq '10') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre eq '00' or $pre eq '01' or $pre eq '10') { } 9724 0 9724
Condition83%5/6
$pre eq "00" or $pre eq "01" or $pre eq 10
l!l&&r!l&&!r
93214030
$pre eq "00" or $pre eq "01"
l!l&&r!l&&!r
3748947403
MC/DC0%0/3
$pre eq "00" or $pre eq "01" or $pre eq 10
$pre eq "00" $pre eq "01" $pre eq 10
Truth table75%3/4
A or B or C
A= $pre eq "00"B= $pre eq "01"C= $pre eq 10
ABCresult
1XX1
01X1
0011
0000
874 9724 return oct('0b' . substr($keep, 1, 14)) - 6176;
875 }
876 else {
877 0 return oct('0b' . substr($keep, 3, 14)) - 6176;
878 }
879 }
880 }
881  
882 #######################################################################
883 #######################################################################
884  
885 4862 ▶sub get_signl {
Subroutine get_signl: called CC=2 SCAR=6.9
Pod undocumented
886 4862 ▶ return '-' if hex(substr(d128_bytes($_[0]), 0, 1)) >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if hex substr(d128_bytes($_[0]), 0, 1) >= 8 2414 2448 4862
887 2448 return '+';
888 }
889  
890 #######################################################################
891 #######################################################################
892  
893 6 ▶sub DPDtoD128 {
Subroutine DPDtoD128: called CC=1 SCAR=0.0
Pod undocumented
894 # Usable only where DPD format is in use.
895 # Converts the 128-bit string returned by _MEtoBINSTR into
896 # a Math::Decimal128 object set to the value encoded by the
897 # the 128-bit string. This is all done without having to calculate
898 # the actual value - and is typically ~25 times quicker than
899 # MEtoD128.
900 6 my($man, $exp) = (shift, shift);
901 6 my $arg = _MEtoBINSTR($man, $exp);
902 6 return _DPDtoD128(unpack("a*", pack( "B*", $arg)));
903 }
904  
905 #######################################################################
906 #######################################################################
907  
908 6 ▶sub assignDPDl {
Subroutine assignDPDl: called CC=1 SCAR=0.0
Pod undocumented
909 6 _assignDPD($_[0], unpack("a*", pack("B*", _MEtoBINSTR($_[1], $_[2]))));
910 }
911  
912 #######################################################################
913 #######################################################################
914  
915 12 ▶sub _MEtoBINSTR {
Subroutine _MEtoBINSTR: called CC=19 SCAR=56.1
916 # Converts (mantissa, exponent) strings to DPD encoded 128-bit string - without
917 # the need to actually calculate the value.
918 12 my $man = shift;
919  
920 12 ▶ if($man =~ /^(\-|\+)?inf|^(\-|\+)?nan/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($man =~ /^(\-|\+)?inf|^(\-|\+)?nan/i) 12 0 12
921 12 ▶ $man =~ /\-inf/i ? return '11111' . ('0' x 123)
Branch: 2 branches
BranchTrueFalseTotal
$man =~ /\-inf/i ? : 2 10 12
$man =~ /^(\-|\+)?nan/i ? : 6 4 10
922 : $man =~ /^(\-|\+)?nan/i ? return '011111' . ('0' x 122)
923 : return '01111' . ('0' x 123);
924 }
925  
926 0 my $exp = shift;
927  
928 # Determine the sign, and remove it.
929 0 ▶ my $sign = $man =~ /^\-/ ? '1' : '0';
Branch: 1 branch
BranchTrueFalseTotal
$man =~ /^\-/ ? : 0 0 0
930 0 $man =~ s/[\+\-]//;
931 0 ▶ die "_MEtoBINSTR has been passed (probably from DPDtoBINSTR) an illegal mantissa"
Branch: 1 branch
BranchTrueFalseTotal
if $man =~ /[^0-9]/ 0 0 0
932 if $man =~ /[^0-9]/;
933  
934 # Remove leading zeroes, and return zero (of appropriate sign)
935 # if we're left with the empty string.
936 0 $man =~ s/^0+//;
937 0 ▶ return $sign . '01000011111111111' . ('0' x 110) unless $man;
Branch: 1 branch
BranchTrueFalseTotal
unless $man 0 0 0
938  
939 # Fill the mantissa with 34 digits - by zero padding the end.
940 0 my $add_zeroes = 34 - length($man);
941 0 $man .= '0' x $add_zeroes;
942 0 $exp -= $add_zeroes;
943  
944 0 ▶ if(length($man) > 34 || $exp < -6176) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $man > 34 or $exp < -6176) 0 0 0
Condition0%0/3
length $man > 34 or $exp < -6176
l!l&&r!l&&!r
000
MC/DC0%0/2
length $man > 34 or $exp < -6176
length $man > 34 $exp < -6176
Truth table0%0/3
A or B
A= length $man > 34B= $exp < -6176
ABresult
1X1
011
000
945 0 ▶ die "$man exceeds _Decimal128 precision. It needs to be shortened to no more than 34 decimal digits"
Branch: 1 branch
BranchTrueFalseTotal
if length $man > 34 0 0 0
946 if length($man) > 34;
947 0 ($man, $exp) = _round_as_needed($man, $exp);
948 }
949  
950 # Return 0 if $exp is still less that -6176.
951 0 ▶ return $sign . '01000011111111111' . ('0' x 110) if $exp < -6176;
Branch: 1 branch
BranchTrueFalseTotal
if $exp < -6176 0 0 0
952  
953 # Return -inf/inf if value is infinite
954 0 ▶ if($exp > 6111) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exp > 6111) 0 0 0
955 0 ▶ return $sign . '1111' . ('0' x 123) if (length($man) + $exp) > 6145;
Branch: 1 branch
BranchTrueFalseTotal
if length($man) + $exp > 6145 0 0 0
956 }
957  
958 0 ▶ $man = '0' . $man while length($man) < 34;
Branch: 1 branch
BranchTrueFalseTotal
length $man < 34 and do { $man = '0' . $man } 0 0 0
959  
960 # The last 110 bits encode the last 33 digits.
961 0 my $last_33_dig = substr($man, 1, 33);
962 0 my $last_110_bits;
963 0 ▶ for(my $i = 0; $i < 31; $i += 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 31) 0 0 0
964 0 $last_110_bits .= $Math::Decimal128::dpd_decode{substr($last_33_dig, $i, 3)}
965 }
966  
967 0 my $len = length($last_110_bits);
968 0 ▶ die "Wrong bitsize ($len != 110) in MEtoBINSTR()" if $len != 110;
Branch: 1 branch
BranchTrueFalseTotal
if $len != 110 0 0 0
969  
970 0 my $leading_digit = substr($man, 0, 1); # ie the msd (most siginificant digit).
971 0 my $exp_base_2 = sprintf "%014b", $exp + 6176;
972  
973 # The encoding of the exponent and msd depends upon the value of the msd.
974 # If it's 0..7, it's done one way; if it's 8 or 9 it's done th'other way.
975 0 ▶ if($leading_digit < 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($leading_digit < 8) { } 0 0 0
976 0 my $leading_digit_bits = sprintf "%03b", $leading_digit;
977 0 substr($exp_base_2, 2, 0, $leading_digit_bits);
978 }
979 else {
980 0 ▶ my $leading_digit_bit = $leading_digit == 8 ? '0' : '1';
Branch: 1 branch
BranchTrueFalseTotal
$leading_digit == 8 ? : 0 0 0
981 0 $exp_base_2 = '11' . substr($exp_base_2, 0, 2) . $leading_digit_bit . substr($exp_base_2, 2, 12);
982 }
983  
984 0 $len = length($exp_base_2);
985 0 ▶ die "Exponent component length is wrong ($len != 17) in MEtoBINSTR()" if $len != 17;
Branch: 1 branch
BranchTrueFalseTotal
if $len != 17 0 0 0
986  
987 0 return $sign . $exp_base_2 . $last_110_bits;
988 }
989  
990 #######################################################################
991 #######################################################################
992  
993 1741 ▶sub D128toFSTR {
Subroutine D128toFSTR: called CC=8 SCAR=20.8
Pod undocumented
994 # Converts the argument (M::D128 object) to a string in floating point
995 # format - as distinct from scientific notation.
996 1741 my($m, $e) = D128toME($_[0]);
997 1741 ▶ return 'nan' if is_NaND128($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if is_NaND128($_[0]) 11 1730 1741
998 1730 ▶ if(is_InfD128($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_InfD128($_[0])) 22 1708 1730
999 22 ▶ return 'inf' if is_InfD128($_[0])> 0;
Branch: 1 branch
BranchTrueFalseTotal
if is_InfD128($_[0]) > 0 11 11 22
1000 11 return '-inf';
1001 }
1002 1708 ▶ return $m . '0' x $e if $e >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $e >= 0 641 1067 1708
1003 1067 my($len, $sign) = (length $m, '');
1004 1067 $m =~ s/^\-//;
1005 1067 ▶ if($len != length $m) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len != length $m) 534 533 1067
1006 534 $len--;
1007 534 $sign = '-';
1008 }
1009 1067 ▶ if($len + $e > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len + $e > 0) 273 794 1067
1010 273 substr($m, $e, 0, '.');
1011 273 return $sign . $m;
1012 }
1013 794 ▶ if($len + $e < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len + $e < 0) 754 40 794
1014 754 return $sign . '0.' . '0' x -($len + $e) . $m;
1015 }
1016 40 return $sign . '0.' . $m;
1017 }
1018  
1019 #######################################################################
1020 #######################################################################
1021  
1022 123 ▶sub D128toRSTR {
Subroutine D128toRSTR: called CC=12 SCAR=24.8
Pod undocumented
1023 # As for D128toFSTR, but rounds the string to the no. of
1024 # decimal places specified by the second arg.
1025  
1026 123 ▶ die "2nd arg to D128toRSTR() must be greater than zero"
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] >= 0 1 122 123
1027 unless $_[1] >= 0;
1028  
1029 122 ▶ my $dp = $_[1] ? '.' : '';
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 98 24 122
1030  
1031 122 my $str = D128toFSTR($_[0]);
1032  
1033 122 ▶ return $str if $str =~ /n/i; # inf/nan
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /n/i 30 92 122
1034  
1035 92 ▶ return $str . "$dp" . '0' x $_[1] unless $str =~ /\./;
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ /\./ 8 84 92
1036  
1037 84 my($leading, $trailing) = split /\./, $str;
1038 84 my $len_trail = length $trailing ;
1039  
1040 84 ▶ return $str if ($_[1] == $len_trail);
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] == $len_trail 18 66 84
1041  
1042 66 ▶ if(length($trailing) <= $_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $trailing <= $_[1]) 14 52 66
1043 14 $trailing .= '0' x ($_[1] - length($trailing));
1044 14 return $leading . "$dp" . $trailing;
1045 }
1046  
1047 # $len_trail > specified number of decimal places ($_[1]).
1048 # We need to round (to nearest, ties to even) from here on.
1049  
1050 52 ▶ return $leading . "$dp" . substr($trailing, 0, $_[1])
Branch: 1 branch
BranchTrueFalseTotal
if substr($trailing, $_[1], 1) <= 4 or substr($trailing, $_[1]) =~ /^5(0+)?$/ and substr($trailing, $_[1] - 1, 1) % 2 == 0 18 34 52
Condition100%6/6
substr($trailing, $_[1], 1) <= 4 or substr($trailing, $_[1]) =~ /^5(0+)?$/ and substr($trailing, $_[1] - 1, 1) % 2 == 0
l!l&&r!l&&!r
14434
substr($trailing, $_[1]) =~ /^5(0+)?$/ and substr($trailing, $_[1] - 1, 1) % 2 == 0
!ll&&!rl&&r
24104
MC/DC100%3/3
substr($trailing, $_[1], 1) <= 4 or substr($trailing, $_[1]) =~ /^5(0+)?$/ and substr($trailing, $_[1] - 1, 1) % 2 == 0
substr($trailing, $_[1], 1) <= 4 substr($trailing, $_[1]) =~ /^5(0+)?$/ substr($trailing, $_[1] - 1, 1) % 2 == 0
Truth table100%4/4
A or B and C
A= substr($trailing, $_[1], 1) <= 4B= substr($trailing, $_[1]) =~ /^5(0+)?$/C= substr($trailing, $_[1] - 1, 1) % 2 == 0
ABCresult
1XX1
0111
00X0
0100
1051 if (substr($trailing, $_[1], 1) <= 4) ||
1052 (substr($trailing, $_[1]) =~ /^5(0+)?$/ && substr($trailing, $_[1] - 1, 1) % 2 == 0);
1053  
1054 34 my $to_inc = substr($trailing, 0, $_[1]);
1055  
1056 34 my $carry = _increment($to_inc); # $carry will either be mt string or '1'. If '1', then we
1057 # also need to increment $leading.
1058  
1059 34 ▶ return $leading . "$dp" . $to_inc
Branch: 1 branch
BranchTrueFalseTotal
if $carry eq "" 10 24 34
1060 if $carry eq '';
1061  
1062 24 my($sign, $len_lead) = ('', length($leading));
1063  
1064 24 $leading =~ s/^\-//;
1065  
1066 24 ▶ if($len_lead != length($leading)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len_lead != length $leading) 12 12 24
1067 12 $sign = '-';
1068 12 $len_lead--;
1069 }
1070  
1071 24 $carry = _increment($leading);
1072  
1073 24 return $sign . $carry . $leading . "$dp" . $to_inc;
1074 }
1075  
1076 #######################################################################
1077 #######################################################################
1078  
1079 58 ▶sub _increment {
Subroutine _increment: called CC=3 SCAR=11.0
1080 58 my $carry = 1;
1081 58 my $len = length($_[0]) * -1;
1082  
1083 58 ▶ for(my $offset = -1; $offset >= $len; $offset--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset >= $len) 52 28 80
1084 52 substr($_[0], $offset, 1) = (substr($_[0], $offset, 1) + 1) % 10;
1085 52 ▶ if(substr($_[0], $offset, 1) ne '0') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($_[0], $offset, 1) ne 0) 30 22 52
1086 30 $carry = '';
1087 30 last;
1088 }
1089 }
1090  
1091 58 return $carry;
1092 }
1093  
1094 #######################################################################
1095 #######################################################################
1096  
1097 31 ▶*decode_d128 = $Math::Decimal128::fmt eq 'DPD' ? \&decode_dpdl : \&decode_bidl;
Branch: 1 branch
BranchTrueFalseTotal
$Math::Decimal128::fmt eq 'DPD' ? : 0 31 31
1098  
1099 #######################################################################
1100 #######################################################################
1101  
1102 31 1;
1103  
1104 __END__
↑ Summary Decimal128.xs »