VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/tests/dtoa.c@ 1

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/******************************************************************************
39 *
40 * This file contains a test program for the function conversion functions
41 * for double precision code:
42 * PR_strtod
43 * PR_dtoa
44 * PR_cnvtf
45 *
46 * This file was ns/nspr/tests/dtoa.c, created by rrj on 1996/06/22.
47 *
48 *****************************************************************************/
49#include <stdio.h>
50#include <sys/types.h>
51#include <string.h>
52#include <locale.h>
53#include "prprf.h"
54#include "prdtoa.h"
55
56static int failed_already = 0;
57
58int main( int argc, char* argv[] )
59{
60 double num;
61 double num1;
62 double zero = 0.0;
63 char cnvt[50];
64
65 num = 1e24;
66 num1 = PR_strtod("1e24",NULL);
67 if(num1 != num){
68 fprintf(stderr,"Failed to convert numeric value %s\n","1e24");
69 failed_already = 1;
70 }
71
72 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
73 if(strcmp("1e+24",cnvt) != 0){
74 fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
75 failed_already = 1;
76 }
77
78 num = 0.001e7;
79 num1 = PR_strtod("0.001e7",NULL);
80 if(num1 != num){
81 fprintf(stderr,"Failed to convert numeric value %s\n","0.001e7");
82 failed_already = 1;
83 }
84 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
85 if(strcmp("10000",cnvt) != 0){
86 fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
87 failed_already = 1;
88 }
89
90 num = 0.0000000000000753;
91 num1 = PR_strtod("0.0000000000000753",NULL);
92 if(num1 != num){
93 fprintf(stderr,"Failed to convert numeric value %s\n",
94 "0.0000000000000753");
95 failed_already = 1;
96 }
97 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
98 if(strcmp("7.53e-14",cnvt) != 0){
99 fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
100 failed_already = 1;
101 }
102
103 num = 1.867e73;
104 num1 = PR_strtod("1.867e73",NULL);
105 if(num1 != num){
106 fprintf(stderr,"Failed to convert numeric value %s\n","1.867e73");
107 failed_already = 1;
108 }
109 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
110 if(strcmp("1.867e+73",cnvt) != 0){
111 fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
112 failed_already = 1;
113 }
114
115
116 num = -1.867e73;
117 num1 = PR_strtod("-1.867e73",NULL);
118 if(num1 != num){
119 fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e73");
120 failed_already = 1;
121 }
122 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
123 if(strcmp("-1.867e+73",cnvt) != 0){
124 fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
125 failed_already = 1;
126 }
127
128 num = -1.867e-73;
129 num1 = PR_strtod("-1.867e-73",NULL);
130 if(num1 != num){
131 fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e-73");
132 failed_already = 1;
133 }
134
135 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
136 if(strcmp("-1.867e-73",cnvt) != 0){
137 fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
138 failed_already = 1;
139 }
140
141 /* Testing for infinity */
142 num = 1.0 / zero;
143 num1 = PR_strtod("1.867e765",NULL);
144 if(num1 != num){
145 fprintf(stderr,"Failed to convert numeric value %s\n","1.867e765");
146 failed_already = 1;
147 }
148
149 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
150 if(strcmp("Infinity",cnvt) != 0){
151 fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
152 failed_already = 1;
153 }
154
155 num = -1.0 / zero;
156 num1 = PR_strtod("-1.867e765",NULL);
157 if(num1 != num){
158 fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e765");
159 failed_already = 1;
160 }
161
162 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
163 if(strcmp("-Infinity",cnvt) != 0){
164 fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
165 failed_already = 1;
166 }
167
168 /* Testing for NaN. PR_strtod can't parse "NaN" and "Infinity" */
169 num = zero / zero;
170
171 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
172 if(strcmp("NaN",cnvt) != 0){
173 fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
174 failed_already = 1;
175 }
176
177 num = - zero / zero;
178 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
179 if(strcmp("NaN",cnvt) != 0){
180 fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
181 failed_already = 1;
182 }
183
184 num = 1.0000000001e21;
185 num1 = PR_strtod("1.0000000001e21",NULL);
186 if(num1 != num){
187 fprintf(stderr,"Failed to convert numeric value %s\n",
188 "1.0000000001e21");
189 failed_already = 1;
190 }
191
192 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
193 if(strcmp("1.0000000001e+21",cnvt) != 0){
194 fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
195 failed_already = 1;
196 }
197
198
199 num = -1.0000000001e-21;
200 num1 = PR_strtod("-1.0000000001e-21",NULL);
201 if(num1 != num){
202 fprintf(stderr,"Failed to convert numeric value %s\n",
203 "-1.0000000001e-21");
204 failed_already = 1;
205 }
206 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
207 if(strcmp("-1.0000000001e-21",cnvt) != 0){
208 fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
209 failed_already = 1;
210 }
211 if (failed_already) {
212 printf("FAILED\n");
213 } else {
214 printf("PASSED\n");
215 }
216 return failed_already;
217}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette