| File: | pr/Linux6.7_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests/../../../pr/tests/dtoa.c | 
| Warning: | line 185, column 5 Value stored to 'num1' is never read  | 
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 
| 2 | /* This Source Code Form is subject to the terms of the Mozilla Public | 
| 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this | 
| 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 
| 5 | |
| 6 | /****************************************************************************** | 
| 7 | * | 
| 8 | * This file contains a test program for the function conversion functions | 
| 9 | * for double precision code: | 
| 10 | * PR_strtod | 
| 11 | * PR_dtoa | 
| 12 | * PR_cnvtf | 
| 13 | * | 
| 14 | * This file was ns/nspr/tests/dtoa.c, created by rrj on 1996/06/22. | 
| 15 | * | 
| 16 | *****************************************************************************/ | 
| 17 | #include <stdio.h> | 
| 18 | #include <stdlib.h> | 
| 19 | #include <sys/types.h> | 
| 20 | #include <string.h> | 
| 21 | #include <locale.h> | 
| 22 | #include "prprf.h" | 
| 23 | #include "prdtoa.h" | 
| 24 | |
| 25 | static int failed_already = 0; | 
| 26 | |
| 27 | int main(int argc, char **argv) | 
| 28 | { | 
| 29 | double num; | 
| 30 | double num1; | 
| 31 | double zero = 0.0; | 
| 32 | char cnvt[50]; | 
| 33 | char *thousands; | 
| 34 | |
| 35 | num = 1e24; | 
| 36 | num1 = PR_strtod("1e24",NULL((void*)0)); | 
| 37 | if(num1 != num) { | 
| 38 | fprintf(stderrstderr,"Failed to convert numeric value %s\n","1e24"); | 
| 39 | failed_already = 1; | 
| 40 | } | 
| 41 | |
| 42 | PR_cnvtf(cnvt,sizeof(cnvt),20,num); | 
| 43 | if(strcmp("1e+24",cnvt) != 0) { | 
| 44 | fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt); | 
| 45 | failed_already = 1; | 
| 46 | } | 
| 47 | |
| 48 | num = 0.001e7; | 
| 49 | num1 = PR_strtod("0.001e7",NULL((void*)0)); | 
| 50 | if(num1 != num) { | 
| 51 | fprintf(stderrstderr,"Failed to convert numeric value %s\n","0.001e7"); | 
| 52 | failed_already = 1; | 
| 53 | } | 
| 54 | PR_cnvtf(cnvt,sizeof(cnvt),20,num); | 
| 55 | if(strcmp("10000",cnvt) != 0) { | 
| 56 | fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt); | 
| 57 | failed_already = 1; | 
| 58 | } | 
| 59 | |
| 60 | num = 0.0000000000000753; | 
| 61 | num1 = PR_strtod("0.0000000000000753",NULL((void*)0)); | 
| 62 | if(num1 != num) { | 
| 63 | fprintf(stderrstderr,"Failed to convert numeric value %s\n", | 
| 64 | "0.0000000000000753"); | 
| 65 | failed_already = 1; | 
| 66 | } | 
| 67 | PR_cnvtf(cnvt,sizeof(cnvt),20,num); | 
| 68 | if(strcmp("7.53e-14",cnvt) != 0) { | 
| 69 | fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt); | 
| 70 | failed_already = 1; | 
| 71 | } | 
| 72 | |
| 73 | num = 1.867e73; | 
| 74 | num1 = PR_strtod("1.867e73",NULL((void*)0)); | 
| 75 | if(num1 != num) { | 
| 76 | fprintf(stderrstderr,"Failed to convert numeric value %s\n","1.867e73"); | 
| 77 | failed_already = 1; | 
| 78 | } | 
| 79 | PR_cnvtf(cnvt,sizeof(cnvt),20,num); | 
| 80 | if(strcmp("1.867e+73",cnvt) != 0) { | 
| 81 | fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt); | 
| 82 | failed_already = 1; | 
| 83 | } | 
| 84 | |
| 85 | |
| 86 | num = -1.867e73; | 
| 87 | num1 = PR_strtod("-1.867e73",NULL((void*)0)); | 
| 88 | if(num1 != num) { | 
| 89 | fprintf(stderrstderr,"Failed to convert numeric value %s\n","-1.867e73"); | 
| 90 | failed_already = 1; | 
| 91 | } | 
| 92 | PR_cnvtf(cnvt,sizeof(cnvt),20,num); | 
| 93 | if(strcmp("-1.867e+73",cnvt) != 0) { | 
| 94 | fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt); | 
| 95 | failed_already = 1; | 
| 96 | } | 
| 97 | |
| 98 | num = -1.867e-73; | 
| 99 | num1 = PR_strtod("-1.867e-73",NULL((void*)0)); | 
| 100 | if(num1 != num) { | 
| 101 | fprintf(stderrstderr,"Failed to convert numeric value %s\n","-1.867e-73"); | 
| 102 | failed_already = 1; | 
| 103 | } | 
| 104 | |
| 105 | PR_cnvtf(cnvt,sizeof(cnvt),20,num); | 
| 106 | if(strcmp("-1.867e-73",cnvt) != 0) { | 
| 107 | fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt); | 
| 108 | failed_already = 1; | 
| 109 | } | 
| 110 | |
| 111 | /* Testing for infinity */ | 
| 112 | num = 1.0 / zero; | 
| 113 | num1 = PR_strtod("1.867e765",NULL((void*)0)); | 
| 114 | if(num1 != num) { | 
| 115 | fprintf(stderrstderr,"Failed to convert numeric value %s\n","1.867e765"); | 
| 116 | failed_already = 1; | 
| 117 | } | 
| 118 | |
| 119 | PR_cnvtf(cnvt,sizeof(cnvt),20,num); | 
| 120 | if(strcmp("Infinity",cnvt) != 0) { | 
| 121 | fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt); | 
| 122 | failed_already = 1; | 
| 123 | } | 
| 124 | |
| 125 | num = -1.0 / zero; | 
| 126 | num1 = PR_strtod("-1.867e765",NULL((void*)0)); | 
| 127 | if(num1 != num) { | 
| 128 | fprintf(stderrstderr,"Failed to convert numeric value %s\n","-1.867e765"); | 
| 129 | failed_already = 1; | 
| 130 | } | 
| 131 | |
| 132 | PR_cnvtf(cnvt,sizeof(cnvt),20,num); | 
| 133 | if(strcmp("-Infinity",cnvt) != 0) { | 
| 134 | fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt); | 
| 135 | failed_already = 1; | 
| 136 | } | 
| 137 | |
| 138 | /* Testing for NaN. PR_strtod can't parse "NaN" and "Infinity" */ | 
| 139 | num = zero / zero; | 
| 140 | |
| 141 | PR_cnvtf(cnvt,sizeof(cnvt),20,num); | 
| 142 | if(strcmp("NaN",cnvt) != 0) { | 
| 143 | fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt); | 
| 144 | failed_already = 1; | 
| 145 | } | 
| 146 | |
| 147 | num = - zero / zero; | 
| 148 | PR_cnvtf(cnvt,sizeof(cnvt),20,num); | 
| 149 | if(strcmp("NaN",cnvt) != 0) { | 
| 150 | fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt); | 
| 151 | failed_already = 1; | 
| 152 | } | 
| 153 | |
| 154 | num = 1.0000000001e21; | 
| 155 | num1 = PR_strtod("1.0000000001e21",NULL((void*)0)); | 
| 156 | if(num1 != num) { | 
| 157 | fprintf(stderrstderr,"Failed to convert numeric value %s\n", | 
| 158 | "1.0000000001e21"); | 
| 159 | failed_already = 1; | 
| 160 | } | 
| 161 | |
| 162 | PR_cnvtf(cnvt,sizeof(cnvt),20,num); | 
| 163 | if(strcmp("1.0000000001e+21",cnvt) != 0) { | 
| 164 | fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt); | 
| 165 | failed_already = 1; | 
| 166 | } | 
| 167 | |
| 168 | num = -1.0000000001e-21; | 
| 169 | num1 = PR_strtod("-1.0000000001e-21",NULL((void*)0)); | 
| 170 | if(num1 != num) { | 
| 171 | fprintf(stderrstderr,"Failed to convert numeric value %s\n", | 
| 172 | "-1.0000000001e-21"); | 
| 173 | failed_already = 1; | 
| 174 | } | 
| 175 | PR_cnvtf(cnvt,sizeof(cnvt),20,num); | 
| 176 | if(strcmp("-1.0000000001e-21",cnvt) != 0) { | 
| 177 | fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt); | 
| 178 | failed_already = 1; | 
| 179 | } | 
| 180 | |
| 181 | /* | 
| 182 | * Bug 414772: should not exit with "Zero passed to d2b" in debug | 
| 183 | * build. | 
| 184 | */ | 
| 185 | num1 = PR_strtod("4e-356",NULL((void*)0)); | 
Value stored to 'num1' is never read  | |
| 186 | |
| 187 | /* | 
| 188 | * A very long input with ~384K digits. | 
| 189 | * Bug 516396: Should not crash. | 
| 190 | * Bug 521306: Should return 0 without converting the input. | 
| 191 | */ | 
| 192 | #define LENGTH(384 * 1024) (384 * 1024) | 
| 193 | thousands = (char *)malloc(LENGTH(384 * 1024)); | 
| 194 | thousands[0] = '0'; | 
| 195 | thousands[1] = '.'; | 
| 196 | memset(&thousands[2], '1', LENGTH(384 * 1024) - 3); | 
| 197 | thousands[LENGTH(384 * 1024) - 1] = '\0'; | 
| 198 | num = 0; | 
| 199 | num1 = PR_strtod(thousands,NULL((void*)0)); | 
| 200 | free(thousands); | 
| 201 | if(num1 != num) { | 
| 202 | fprintf(stderrstderr,"Failed to convert numeric value %s\n", | 
| 203 | "0.1111111111111111..."); | 
| 204 | failed_already = 1; | 
| 205 | } | 
| 206 | |
| 207 | if (failed_already) { | 
| 208 | printf("FAILED\n"); | 
| 209 | } else { | 
| 210 | printf("PASSED\n"); | 
| 211 | } | 
| 212 | return failed_already; | 
| 213 | } |