blob: f4afd64702d3efaae2a4f33549c024be7061c18b [file] [log] [blame]
Lev Walkin4eceeba2007-07-23 06:48:26 +00001#include <stdio.h>
2#include <assert.h>
3#include <math.h>
Lev Walkin8ca13c82016-01-24 22:40:00 -08004#include <float.h>
Lev Walkin4eceeba2007-07-23 06:48:26 +00005
Lev Walkin681f0592016-03-14 04:21:26 -07006/* C11 specifies DBL_TRUE_MIN, might not be immediately available. */
7#ifndef DBL_TRUE_MIN
8#define DBL_TRUE_MIN 4.9406564584124654E-324
9#endif
10
Lev Walkin4eceeba2007-07-23 06:48:26 +000011#include <REAL.h>
Lev Walkin41ba1f22004-09-14 12:46:35 +000012
Lev Walkined465432004-09-27 20:52:36 +000013static char reconstructed[2][512];
14static int reconstr_lens[2];
15
16static int
17callback(const void *buffer, size_t size, void *app_key) {
18 char *buf = reconstructed[app_key ? 1 : 0];
19 int *len = &reconstr_lens[app_key ? 1 : 0];
20
21 if(*len + size >= sizeof(reconstructed[0]))
22 return -1;
23
24 memcpy(buf + *len, buffer, size);
25 *len += size;
26
27 return 0;
28}
29
Lev Walkin833d2752012-01-07 15:29:25 -080030static char *
Lev Walkin97363482016-01-24 19:23:02 -080031d2s(double d, int canonical) {
Lev Walkin833d2752012-01-07 15:29:25 -080032 ssize_t s;
33
34 reconstr_lens[canonical] = 0;
35 s = REAL__dump(d, canonical, callback, (void *)(ptrdiff_t)canonical);
Lev Walkin97363482016-01-24 19:23:02 -080036 assert(s > 0 && (size_t)s < sizeof(reconstructed[canonical]));
Lev Walkin833d2752012-01-07 15:29:25 -080037 assert(s == reconstr_lens[canonical]);
38 reconstructed[canonical][s] = '\0'; // ASCIIZ
39 return reconstructed[canonical];
40}
41
42/*
43 * Verify that a string representation of a given floating point value
44 * is as given in the (sample) and (canonical_sample) arguments.
45 */
Lev Walkin41ba1f22004-09-14 12:46:35 +000046static void
Lev Walkin5fda7d52012-01-09 03:20:19 -080047check_str_representation(double d, const char *sample, const char *canonical_sample, int lineno) {
Lev Walkin833d2752012-01-07 15:29:25 -080048 char *s0, *s1;
Lev Walkined465432004-09-27 20:52:36 +000049
Lev Walkin97363482016-01-24 19:23:02 -080050 s0 = d2s(d, 0);
51 s1 = d2s(d, 1);
Lev Walkined465432004-09-27 20:52:36 +000052
53 if(sample) {
Lev Walkin8ca13c82016-01-24 22:40:00 -080054 printf("%03d: Checking %g->[\"%s\"] against [\"%s\"]%s\n",
Lev Walkin5fda7d52012-01-09 03:20:19 -080055 lineno, d, s0, sample,
Lev Walkinf0b808d2005-04-25 21:08:25 +000056 canonical_sample ? " (canonical follows...)" : ""
57 );
Lev Walkin833d2752012-01-07 15:29:25 -080058 assert(!strcmp(s0, sample));
Lev Walkined465432004-09-27 20:52:36 +000059 }
60 if(canonical_sample) {
Lev Walkin8ca13c82016-01-24 22:40:00 -080061 printf("%03d: Checking %g->[\"%s\"] against [\"%s\"] (canonical)\n",
Lev Walkin5fda7d52012-01-09 03:20:19 -080062 lineno, d, s1, canonical_sample);
Lev Walkin833d2752012-01-07 15:29:25 -080063 assert(!strcmp(s1, canonical_sample));
Lev Walkined465432004-09-27 20:52:36 +000064 }
65}
66
Lev Walkin5fe72e92012-01-07 17:00:29 -080067#define check(rn, d, str1, str2) \
68 check_impl(rn, d, str1, str2, __LINE__)
69
Lev Walkined465432004-09-27 20:52:36 +000070static void
Lev Walkin5fda7d52012-01-09 03:20:19 -080071check_impl(REAL_t *rn, double orig_dbl, const char *sample, const char *canonical_sample, int lineno) {
Lev Walkin41ba1f22004-09-14 12:46:35 +000072 double val;
73 uint8_t *p, *end;
74 int ret;
75
Lev Walkin5fda7d52012-01-09 03:20:19 -080076 printf("Line %d: double value %.12f [", lineno, orig_dbl);
Lev Walkin41ba1f22004-09-14 12:46:35 +000077 for(p = (uint8_t *)&orig_dbl, end = p + sizeof(double); p < end ; p++)
78 printf("%02x", *p);
79 printf("] (ilogb %d)\n", ilogb(orig_dbl));
80
81 val = frexp(orig_dbl, &ret);
82 printf("frexp(%f, %d): [", val, ret);
83 for(p = (uint8_t *)&val, end = p + sizeof(double); p < end ; p++)
84 printf("%02x", *p);
85 printf("]\n");
86
Lev Walkin5e033762004-09-29 13:26:15 +000087 ret = asn_double2REAL(rn, orig_dbl);
Lev Walkin41ba1f22004-09-14 12:46:35 +000088 assert(ret == 0);
89
90 printf("converted into [");
91 for(p = rn->buf, end = p + rn->size; p < end; p++)
92 printf("%02x", *p);
Lev Walkin494fb702017-08-07 20:07:00 -070093 printf("]: %zu\n", rn->size);
Lev Walkin41ba1f22004-09-14 12:46:35 +000094
Lev Walkin5e033762004-09-29 13:26:15 +000095 ret = asn_REAL2double(rn, &val);
Lev Walkin41ba1f22004-09-14 12:46:35 +000096 assert(ret == 0);
97
98 printf("and back to double: [");
99 for(p = (uint8_t *)&val, end = p + sizeof(double); p < end ; p++)
100 printf("%02x", *p);
101 printf("] (ilogb %d)\n", ilogb(val));
102
Lev Walkin1aea6982004-10-26 09:35:25 +0000103 printf("%.12f vs %.12f\n", val, orig_dbl);
104 assert((isnan(orig_dbl) && isnan(val)) || val == orig_dbl);
Lev Walkin41ba1f22004-09-14 12:46:35 +0000105 printf("OK\n");
Lev Walkined465432004-09-27 20:52:36 +0000106
Lev Walkin5fda7d52012-01-09 03:20:19 -0800107 check_str_representation(val, sample, canonical_sample, lineno);
Lev Walkin41ba1f22004-09-14 12:46:35 +0000108}
Lev Walkin5f560912004-10-21 13:37:57 +0000109static void
110check_xer(int fuzzy, double orig_value) {
111 asn_enc_rval_t er;
112 asn_dec_rval_t rc;
113 REAL_t st;
114 REAL_t *newst0 = 0;
115 REAL_t *newst1 = 0;
Lev Walkinb1919382006-07-27 11:46:25 +0000116 REAL_t **newst0p = &newst0;
117 REAL_t **newst1p = &newst1;
Lev Walkin5f560912004-10-21 13:37:57 +0000118 double value0, value1;
119 int ret;
120
121 memset(&st, 0, sizeof(st));
122 ret = asn_double2REAL(&st, orig_value);
123 assert(ret == 0);
124
125 reconstr_lens[0] = 0;
126 reconstr_lens[1] = 0;
Lev Walkin229ad002017-09-18 20:13:49 -0700127 er = xer_encode(&asn_DEF_REAL, &st, XER_F_BASIC, callback, 0);
Lev Walkin5f560912004-10-21 13:37:57 +0000128 assert(er.encoded == reconstr_lens[0]);
Lev Walkin229ad002017-09-18 20:13:49 -0700129 er = xer_encode(&asn_DEF_REAL, &st, XER_F_CANONICAL, callback, (void *)1);
Lev Walkin5f560912004-10-21 13:37:57 +0000130 assert(er.encoded == reconstr_lens[1]);
131 reconstructed[0][reconstr_lens[0]] = 0;
132 reconstructed[1][reconstr_lens[1]] = 0;
133
134 printf("%f vs (%d)[%s] & (%d)%s",
135 orig_value,
136 reconstr_lens[1], reconstructed[1],
137 reconstr_lens[0], reconstructed[0]
138 );
139
Lev Walkinb1919382006-07-27 11:46:25 +0000140 rc = xer_decode(0, &asn_DEF_REAL, (void **)newst0p,
Lev Walkin5f560912004-10-21 13:37:57 +0000141 reconstructed[0], reconstr_lens[0]);
142 assert(rc.code == RC_OK);
Lev Walkin97363482016-01-24 19:23:02 -0800143 assert(reconstr_lens[0] > 0 && rc.consumed < (size_t)reconstr_lens[0]);
Lev Walkin5f560912004-10-21 13:37:57 +0000144
Lev Walkinb1919382006-07-27 11:46:25 +0000145 rc = xer_decode(0, &asn_DEF_REAL, (void **)newst1p,
Lev Walkin5f560912004-10-21 13:37:57 +0000146 reconstructed[1], reconstr_lens[1]);
147 assert(rc.code == RC_OK);
Lev Walkin97363482016-01-24 19:23:02 -0800148 assert(rc.consumed == (size_t)reconstr_lens[1]);
Lev Walkin5f560912004-10-21 13:37:57 +0000149
150 ret = asn_REAL2double(newst0, &value0);
151 assert(ret == 0);
152 ret = asn_REAL2double(newst1, &value1);
153 assert(ret == 0);
154
Lev Walkin1aea6982004-10-26 09:35:25 +0000155 assert((isnan(value0) && isnan(orig_value))
156 || value0 == orig_value
Lev Walkin5f560912004-10-21 13:37:57 +0000157 || fuzzy);
Lev Walkin1aea6982004-10-26 09:35:25 +0000158 assert((isnan(value1) && isnan(orig_value))
159 || value1 == orig_value);
Lev Walkin5f560912004-10-21 13:37:57 +0000160
161 assert(newst0->size == st.size || fuzzy);
162 assert(newst1->size == st.size);
163 assert(fuzzy || memcmp(newst0->buf, st.buf, st.size) == 0);
164 assert(memcmp(newst1->buf, st.buf, st.size) == 0);
Lev Walkin229ad002017-09-18 20:13:49 -0700165 ASN_STRUCT_RESET(asn_DEF_REAL, &st);
166 ASN_STRUCT_FREE(asn_DEF_REAL, newst0);
167 ASN_STRUCT_FREE(asn_DEF_REAL, newst1);
Lev Walkin5f560912004-10-21 13:37:57 +0000168}
169
Lev Walkin5fe72e92012-01-07 17:00:29 -0800170static void
Lev Walkin53e5ae62017-08-23 10:56:19 -0700171check_ber_buffer_twoway(double d, const char *sample, const char *canonical_sample, const uint8_t *inbuf, size_t insize, uint8_t *outbuf, size_t outsize, int lineno) {
Lev Walkin5fe72e92012-01-07 17:00:29 -0800172 REAL_t rn;
173 double val;
174 int ret;
175
176 /*
177 * Decode our expected buffer and check that it matches the given (d).
178 */
Lev Walkin53e5ae62017-08-23 10:56:19 -0700179 rn.buf = calloc(1, insize + 1); /* By convention, buffers have extra \0 */
180 assert(rn.buf);
181 memcpy(rn.buf, inbuf, insize);
Lev Walkin5fe72e92012-01-07 17:00:29 -0800182 rn.size = insize;
183 asn_REAL2double(&rn, &val);
184 if(isnan(val)) assert(isnan(d));
185 if(isnan(d)) assert(isnan(val));
186 if(!isnan(val) && !isnan(d)) {
Lev Walkin5fda7d52012-01-09 03:20:19 -0800187 assert(copysign(1.0, d) == copysign(1.0, val));
188 assert(d == val);
189 }
Lev Walkin5fe72e92012-01-07 17:00:29 -0800190
191 /*
192 * Encode value and check that it matches our expected buffer.
193 */
Lev Walkin53e5ae62017-08-23 10:56:19 -0700194 free(rn.buf);
Lev Walkin5fe72e92012-01-07 17:00:29 -0800195 memset(&rn, 0, sizeof(rn));
196 ret = asn_double2REAL(&rn, d);
197 assert(ret == 0);
Lev Walkin97363482016-01-24 19:23:02 -0800198 if((size_t)rn.size != outsize) {
Lev Walkin5fe72e92012-01-07 17:00:29 -0800199 printf("Encoded %f into %d expected %ld\n",
200 d, (int)rn.size, outsize);
Lev Walkin97363482016-01-24 19:23:02 -0800201 assert((size_t)rn.size == outsize);
Lev Walkin5fe72e92012-01-07 17:00:29 -0800202 }
203 assert(memcmp(rn.buf, outbuf, rn.size) == 0);
Lev Walkin229ad002017-09-18 20:13:49 -0700204 ASN_STRUCT_RESET(asn_DEF_REAL, &rn);
Lev Walkin5fe72e92012-01-07 17:00:29 -0800205
Lev Walkin5fda7d52012-01-09 03:20:19 -0800206 check_str_representation(d, sample, canonical_sample, lineno);
Lev Walkin5fe72e92012-01-07 17:00:29 -0800207}
208
209static void
Lev Walkin5fda7d52012-01-09 03:20:19 -0800210check_ber_buffer_oneway(double d, const char *sample, const char *canonical_sample, uint8_t *buf, size_t bufsize, int lineno) {
Lev Walkin229ad002017-09-18 20:13:49 -0700211 REAL_t rn0;
212 REAL_t rn1;
213 double val0;
214 double val1;
Lev Walkin5fe72e92012-01-07 17:00:29 -0800215 uint8_t *p, *end;
216 int ret;
217
Lev Walkin229ad002017-09-18 20:13:49 -0700218 memset(&rn0, 0, sizeof(rn0));
219 memset(&rn1, 0, sizeof(rn1));
Lev Walkin5fe72e92012-01-07 17:00:29 -0800220
221 printf("verify double value %.12f [", d);
222 for(p = (uint8_t *)&d, end = p + sizeof(double); p < end ; p++)
223 printf("%02x", *p);
224 printf("] (ilogb %d)\n", ilogb(d));
225
Lev Walkin229ad002017-09-18 20:13:49 -0700226 ret = asn_double2REAL(&rn0, d);
Lev Walkin5fe72e92012-01-07 17:00:29 -0800227 assert(ret == 0);
228
229 printf("canonical DER: [");
Lev Walkin229ad002017-09-18 20:13:49 -0700230 for(p = rn0.buf, end = p + rn0.size; p < end; p++)
Lev Walkin5fe72e92012-01-07 17:00:29 -0800231 printf("%02x", *p);
Lev Walkin229ad002017-09-18 20:13:49 -0700232 ret = asn_REAL2double(&rn0, &val0);
233 assert(ret == 0);
234 printf("] => %f\n", val0);
Lev Walkin5fe72e92012-01-07 17:00:29 -0800235
Lev Walkin229ad002017-09-18 20:13:49 -0700236 rn1.buf = buf;
237 rn1.size = bufsize;
Lev Walkin5fe72e92012-01-07 17:00:29 -0800238
239 printf("received as: [");
Lev Walkin229ad002017-09-18 20:13:49 -0700240 for(p = rn1.buf, end = p + rn1.size; p < end; p++)
Lev Walkin5fe72e92012-01-07 17:00:29 -0800241 printf("%02x", *p);
Lev Walkin229ad002017-09-18 20:13:49 -0700242 ret = asn_REAL2double(&rn1, &val1);
Lev Walkin5fe72e92012-01-07 17:00:29 -0800243 assert(ret == 0);
Lev Walkin229ad002017-09-18 20:13:49 -0700244 printf("] => %f\n", val1);
Lev Walkin5fe72e92012-01-07 17:00:29 -0800245
Lev Walkin229ad002017-09-18 20:13:49 -0700246 printf("%.12f vs %.12f vs %.12f\n", d, val0, val1);
Lev Walkin5fe72e92012-01-07 17:00:29 -0800247
Lev Walkin229ad002017-09-18 20:13:49 -0700248 assert(val0 == d);
249 assert(val1 == d);
Lev Walkin5fe72e92012-01-07 17:00:29 -0800250
Lev Walkin229ad002017-09-18 20:13:49 -0700251 ASN_STRUCT_RESET(asn_DEF_REAL, &rn0);
252
253 check_str_representation(val1, sample, canonical_sample, lineno);
Lev Walkin5fe72e92012-01-07 17:00:29 -0800254}
255
Lev Walkine8727ec2012-01-09 05:46:16 -0800256/*
257 * 8.5.7 Verify binary encoding, two-way.
258 */
259static void
260check_ber_857_encoding(int base, int sign, int scaling_factor, int exponent, int mantissa) {
261 uint8_t buf[100];
262 uint8_t *b = buf;
263 int explen, mantlen;
264 REAL_t rn;
265 static REAL_t rn_check;
266 double d;
267 double verify;
268 int baseF = 0;
269 int ret;
270
271#define BIT(b) (1<<(b - 1))
272
273 switch(base) {
274 case 0: baseF = 1; break;
275 case 1: baseF = 3; break;
276 case 2: baseF = 4; break;
277 default: assert(base >= 0 && base <= 2);
278 }
279
280 if(exponent >= -128 && exponent <= 127) {
281 explen = 1;
282 } else {
283 assert(exponent > -60000 && exponent < 60000);
284 explen = 2;
285 }
286
287 if(mantissa == 0) {
288 mantlen = 0;
289 } else if(mantissa >= 0 && mantissa <= 255) {
290 mantlen = 1;
291 } else if(mantissa >= 0 && mantissa <= 65535) {
292 mantlen = 2;
293 } else {
294 assert(mantissa >= 0 && mantissa <= 256 * 65536);
295 mantlen = 3;
296 }
297
298 *b = BIT(8) | (sign ? BIT(7) : 0);
299 *b |= (base & 0x03) << 4; /* 8.5.7.2 */
300 *b |= (scaling_factor & 0x03) << 2; /* 8.5.7.3 */
301 *b |= ((explen - 1) & 0x03); /* 8.5.7.4 */
302 b++;
303 switch(explen) {
304 case 2: *b++ = (int8_t)(exponent >> 8);
305 case 1: *b++ = (int8_t)exponent;
306 }
307 switch(mantlen) {
308 case 3: *b++ = (mantissa >> 16) & 0xff;
309 case 2: *b++ = (mantissa >> 8) & 0xff;
310 case 1: *b++ = (mantissa & 0xff);
311 }
312
313 verify = (sign ? -1.0 : 1.0) * ldexp(mantissa, exponent * baseF + scaling_factor);
314
315 /* Verify than encoding of this double value round-trips */
316 if(!isinf(verify)) {
317 d = verify;
318 verify = 0.0;
319 ret = asn_double2REAL(&rn_check, d);
320 assert(ret == 0);
321 ret = asn_REAL2double(&rn_check, &verify);
322 assert(ret == 0);
323 assert(d == verify);
324
325 /* Verify with a slight non-friendly offset. Not too easy. */
326 d = verify - 0.13;
327 verify = 0.0;
328 ret = asn_double2REAL(&rn_check, d);
329 assert(ret == 0);
330 ret = asn_REAL2double(&rn_check, &verify);
331 assert(ret == 0);
332 assert(ret == 0);
333 assert(d == verify);
334 }
335
336 verify = (sign ? -1.0 : 1.0) * ldexp(mantissa, exponent * baseF + scaling_factor);
337
338 rn.buf = buf;
339 rn.size = b - buf;
340 ret = asn_REAL2double(&rn, &d);
341 if(!isinf(verify) && (ret != 0 || d != verify)) {
342 printf("Converting B=%d, S=%d, F=%d, E=%d/%d, M=%d/%d\n", (1 << baseF), sign, scaling_factor, exponent, explen, mantissa, mantlen);
343 printf("Verify: %e\n", verify);
344 uint8_t *p;
345 printf("received as: [");
346 for(p = buf; p < b; p++) printf("%02x", *p);
347 printf("]\n");
348 assert(ret == 0);
349 printf("Converted: %e\n", d);
350 assert(d == verify);
351 }
352}
Lev Walkin5fe72e92012-01-07 17:00:29 -0800353
354static void
355check_ber_encoding() {
Lev Walkin5fda7d52012-01-09 03:20:19 -0800356#define CHECK_BER_STRICT(v, nocan, can, inbuf, outbuf) \
357 check_ber_buffer_twoway(v, nocan, can, inbuf, sizeof(inbuf), \
358 outbuf, sizeof(outbuf), __LINE__)
Lev Walkin5fe72e92012-01-07 17:00:29 -0800359
360#define CHECK_BER_NONSTRICT(v, nocan, can, buf) \
Lev Walkin5fda7d52012-01-09 03:20:19 -0800361 check_ber_buffer_oneway(v, nocan, can, buf, sizeof(buf), __LINE__)
Lev Walkin5fe72e92012-01-07 17:00:29 -0800362
363 /*
364 * X.690 8.4 Encoding of an enumerated value.
365 */
366
367 /* 8.5.2 If the real value is the value plus zero,
368 * there shall be no contents octet in the encoding */
369 { uint8_t b_0[] = {};
Lev Walkin5fda7d52012-01-09 03:20:19 -0800370 CHECK_BER_STRICT(0.0, "0", "0", b_0, b_0); }
Lev Walkin5fe72e92012-01-07 17:00:29 -0800371
372 /* 8.5.3 When -0 is to be encoded, there shall be only one contents octet */
373 { uint8_t b_m0[] = { 0x43 };
Lev Walkin5fda7d52012-01-09 03:20:19 -0800374 CHECK_BER_STRICT(-0.0, "-0", "-0", b_m0, b_m0); }
Lev Walkin5fe72e92012-01-07 17:00:29 -0800375
376 /* Old way of encoding -0.0: 8.5.6 a) */
377 { uint8_t b_m0[] = { 0x43 };
378 uint8_t b_m0_856a[] = { 0xC0, 0x00 }; /* #8.5.6 a) */
379 uint8_t b_m0_856a_1[] = { 0xC0, 0x00, 0x00 };
380 uint8_t b_m0_856a_2[] = { 0xC0, 0x00, 0x00, 0x00 };
381 uint8_t b_m0_856a_3[] = { 0xC0, 0x00, 0x00, 0x00, 0x00 };
382 CHECK_BER_STRICT(-0.0, "-0", "-0", b_m0_856a, b_m0);
383 CHECK_BER_STRICT(-0.0, "-0", "-0", b_m0_856a_1, b_m0);
384 CHECK_BER_STRICT(-0.0, "-0", "-0", b_m0_856a_2, b_m0);
Lev Walkin5fda7d52012-01-09 03:20:19 -0800385 CHECK_BER_STRICT(-0.0, "-0", "-0", b_m0_856a_3, b_m0); }
Lev Walkin5fe72e92012-01-07 17:00:29 -0800386
387 /* 8.5.6 c) => 8.5.9 SpecialRealValue */
388 { uint8_t b_pinf[] = { 0x40 };
389 uint8_t b_minf[] = { 0x41 };
390 uint8_t b_nan[] = { 0x42 };
Lev Walkin9c57f332017-09-17 22:30:49 -0700391 CHECK_BER_STRICT(INFINITY, "<PLUS-INFINITY/>", "<PLUS-INFINITY/>", b_pinf, b_pinf);
392 CHECK_BER_STRICT(-INFINITY, "<MINUS-INFINITY/>", "<MINUS-INFINITY/>", b_minf, b_minf);
393 CHECK_BER_STRICT(NAN, "<NOT-A-NUMBER/>", "<NOT-A-NUMBER/>", b_nan, b_nan); }
Lev Walkin5fda7d52012-01-09 03:20:19 -0800394
395 /* 8.5.6 b) => 8.5.8 Decimal encoding is used; NR1 form */
396 { uint8_t b_0_nr1[] = { 0x01, '0' };
397 uint8_t b_0[] = { };
398 CHECK_BER_STRICT(0.0, "0", "0", b_0_nr1, b_0); }
399 { uint8_t b_0_nr1[] = { 0x01, '0', '0' };
400 uint8_t b_0[] = { };
401 CHECK_BER_STRICT(0.0, "0", "0", b_0_nr1, b_0); }
402 { uint8_t b_0_nr1[] = { 0x01, ' ', '0' };
403 uint8_t b_0[] = { };
404 CHECK_BER_STRICT(0.0, "0", "0", b_0_nr1, b_0); }
405 { uint8_t b_p0_nr1[] = { 0x01, '+', '0' };
406 uint8_t b_0[] = { };
407 CHECK_BER_STRICT(0.0, "0", "0", b_p0_nr1, b_0); }
408 { uint8_t b_p0_nr1[] = { 0x01, ' ', '+', '0' };
409 uint8_t b_0[] = { };
410 CHECK_BER_STRICT(0.0, "0", "0", b_p0_nr1, b_0); }
411 { uint8_t b_m0_nr1[] = { 0x01, '-', '0' };
412 uint8_t b_m0[] = { 0x43 };
413 CHECK_BER_STRICT(-0.0, "-0", "-0", b_m0_nr1, b_m0); }
414 { uint8_t b_m0_nr1[] = { 0x01, ' ', '-', '0' };
415 uint8_t b_m0[] = { 0x43 };
416 CHECK_BER_STRICT(-0.0, "-0", "-0", b_m0_nr1, b_m0); }
417
418 { uint8_t b_1_nr1[] = { 0x01, '1' };
419 uint8_t b_1[] = { 0x80, 0x00, 0x01 };
420 CHECK_BER_STRICT(1.0, "1.0", "1.0E0", b_1_nr1, b_1); }
421 { uint8_t b_1_nr1[] = { 0x01, '0', '1' };
422 uint8_t b_1[] = { 0x80, 0x00, 0x01 };
423 CHECK_BER_STRICT(1.0, "1.0", "1.0E0", b_1_nr1, b_1); }
424 { uint8_t b_1_nr1[] = { 0x01, ' ', '1' };
425 uint8_t b_1[] = { 0x80, 0x00, 0x01 };
426 CHECK_BER_STRICT(1.0, "1.0", "1.0E0", b_1_nr1, b_1); }
427 { uint8_t b_p1_nr1[] = { 0x01, '+', '1' };
428 uint8_t b_1[] = { 0x80, 0x00, 0x01 };
429 CHECK_BER_STRICT(1.0, "1.0", "1.0E0", b_p1_nr1, b_1); }
430 { uint8_t b_p1_nr1[] = { 0x01, ' ', '+', '1' };
431 uint8_t b_1[] = { 0x80, 0x00, 0x01 };
432 CHECK_BER_STRICT(1.0, "1.0", "1.0E0", b_p1_nr1, b_1); }
433 { uint8_t b_m1_nr1[] = { 0x01, '-', '1' };
434 uint8_t b_m1[] = { 0xC0, 0x00, 0x01 };
435 CHECK_BER_STRICT(-1.0, "-1.0", "-1.0E0", b_m1_nr1, b_m1); }
436 { uint8_t b_m1_nr1[] = { 0x01, ' ', '-', '1' };
437 uint8_t b_m1[] = { 0xC0, 0x00, 0x01 };
438 CHECK_BER_STRICT(-1.0, "-1.0", "-1.0E0", b_m1_nr1, b_m1); }
439
440 {
441 uint8_t comma_symbol[] = { '.', ',' };
442 int csi;
443 for(csi = 0; csi < 2; csi++) {
444 uint8_t CS = comma_symbol[csi];
445
446 /* 8.5.6 b) => 8.5.8 Decimal encoding is used; NR2 form */
447 { uint8_t b_0_nr2[] = { 0x02, '0', CS, '0' };
448 uint8_t b_0[] = { };
449 CHECK_BER_STRICT(0.0, "0", "0", b_0_nr2, b_0); }
450 { uint8_t b_0_nr2[] = { 0x02, '0', '0', CS, '0' };
451 uint8_t b_0[] = { };
452 CHECK_BER_STRICT(0.0, "0", "0", b_0_nr2, b_0); }
453 { uint8_t b_0_nr2[] = { 0x02, ' ', '0', CS, '0' };
454 uint8_t b_0[] = { };
455 CHECK_BER_STRICT(0.0, "0", "0", b_0_nr2, b_0); }
456 { uint8_t b_p0_nr2[] = { 0x02, '+', '0', CS, '0' };
457 uint8_t b_0[] = { };
458 CHECK_BER_STRICT(0.0, "0", "0", b_p0_nr2, b_0); }
459 { uint8_t b_p0_nr2[] = { 0x02, ' ', '+', '0', CS, '0' };
460 uint8_t b_0[] = { };
461 CHECK_BER_STRICT(0.0, "0", "0", b_p0_nr2, b_0); }
462 { uint8_t b_m0_nr2[] = { 0x02, '-', '0', CS, '0' };
463 uint8_t b_m0[] = { 0x43 };
464 CHECK_BER_STRICT(-0.0, "-0", "-0", b_m0_nr2, b_m0); }
465 { uint8_t b_m0_nr2[] = { 0x02, ' ', '-', '0', CS, '0' };
466 uint8_t b_m0[] = { 0x43 };
467 CHECK_BER_STRICT(-0.0, "-0", "-0", b_m0_nr2, b_m0); }
468
469 /* 8.5.6 b) => 8.5.8 NR2 "1." */
470 { uint8_t b_1_nr2[] = { 0x02, '1', CS };
471 uint8_t b_1[] = { 0x80, 0x00, 0x01 };
472 CHECK_BER_STRICT(1.0, "1.0", "1.0E0", b_1_nr2, b_1); }
473 { uint8_t b_1_nr2[] = { 0x02, '0', '1', CS };
474 uint8_t b_1[] = { 0x80, 0x00, 0x01 };
475 CHECK_BER_STRICT(1.0, "1.0", "1.0E0", b_1_nr2, b_1); }
476 { uint8_t b_1_nr2[] = { 0x02, ' ', '1', CS };
477 uint8_t b_1[] = { 0x80, 0x00, 0x01 };
478 CHECK_BER_STRICT(1.0, "1.0", "1.0E0", b_1_nr2, b_1); }
479 { uint8_t b_p1_nr2[] = { 0x02, '+', '1', CS };
480 uint8_t b_1[] = { 0x80, 0x00, 0x01 };
481 CHECK_BER_STRICT(1.0, "1.0", "1.0E0", b_p1_nr2, b_1); }
482 { uint8_t b_p1_nr2[] = { 0x02, ' ', '+', '1', CS };
483 uint8_t b_1[] = { 0x80, 0x00, 0x01 };
484 CHECK_BER_STRICT(1.0, "1.0", "1.0E0", b_p1_nr2, b_1); }
485 { uint8_t b_m1_nr2[] = { 0x02, '-', '1', CS };
486 uint8_t b_m1[] = { 0xC0, 0x00, 0x01 };
487 CHECK_BER_STRICT(-1.0, "-1.0", "-1.0E0", b_m1_nr2, b_m1); }
488 { uint8_t b_m1_nr2[] = { 0x02, ' ', '-', '1', CS };
489 uint8_t b_m1[] = { 0xC0, 0x00, 0x01 };
490 CHECK_BER_STRICT(-1.0, "-1.0", "-1.0E0", b_m1_nr2, b_m1); }
491
492 /* 8.5.6 b) => 8.5.8 NR2 ".5" */
493 { uint8_t b_05_nr2[] = { 0x02, CS, '5' };
494 uint8_t b_05[] = { 0x80, 0xff, 0x01 };
495 CHECK_BER_STRICT(0.5, "0.5", "5.0E-1", b_05_nr2, b_05); }
496 { uint8_t b_05_nr2[] = { 0x02, '0', CS, '5' };
497 uint8_t b_05[] = { 0x80, 0xff, 0x01 };
498 CHECK_BER_STRICT(0.5, "0.5", "5.0E-1", b_05_nr2, b_05); }
499 { uint8_t b_05_nr2[] = { 0x02, ' ', CS, '5' };
500 uint8_t b_05[] = { 0x80, 0xff, 0x01 };
501 CHECK_BER_STRICT(0.5, "0.5", "5.0E-1", b_05_nr2, b_05); }
502 { uint8_t b_p1_nr2[] = { 0x02, '+', CS, '5' };
503 uint8_t b_05[] = { 0x80, 0xff, 0x01 };
504 CHECK_BER_STRICT(0.5, "0.5", "5.0E-1", b_p1_nr2, b_05); }
505 { uint8_t b_p1_nr2[] = { 0x02, ' ', '+', CS, '5' };
506 uint8_t b_05[] = { 0x80, 0xff, 0x01 };
507 CHECK_BER_STRICT(0.5, "0.5", "5.0E-1", b_p1_nr2, b_05); }
508 { uint8_t b_m05_nr2[] = { 0x02, '-', CS, '5' };
509 uint8_t b_m05[] = { 0xC0, 0xff, 0x01 };
510 CHECK_BER_STRICT(-0.5, "-0.5", "-5.0E-1", b_m05_nr2, b_m05); }
511 { uint8_t b_m05_nr2[] = { 0x02, ' ', '-', CS, '5' };
512 uint8_t b_m05[] = { 0xC0, 0xff, 0x01 };
513 CHECK_BER_STRICT(-0.5, "-0.5", "-5.0E-1", b_m05_nr2, b_m05); }
514
515 /* 8.5.6 b) => 8.5.8 Decimal encoding is used; NR3 form */
516 { uint8_t b_0_nr3[] = { 0x03, '0', CS, '0', 'e', '0' };
517 uint8_t b_0[] = { };
518 CHECK_BER_STRICT(0.0, "0", "0", b_0_nr3, b_0); }
519 { uint8_t b_0_nr3[] = { 0x03, '0', '0', CS, '0', 'E', '0' };
520 uint8_t b_0[] = { };
521 CHECK_BER_STRICT(0.0, "0", "0", b_0_nr3, b_0); }
522 { uint8_t b_0_nr3[] = { 0x03, ' ', '0', CS, '0', 'e', '0' };
523 uint8_t b_0[] = { };
524 CHECK_BER_STRICT(0.0, "0", "0", b_0_nr3, b_0); }
525 { uint8_t b_p0_nr3[] = { 0x03, '+', '0', CS, '0', 'E', '+', '0' };
526 uint8_t b_0[] = { };
527 CHECK_BER_STRICT(0.0, "0", "0", b_p0_nr3, b_0); }
528 { uint8_t b_p0_nr3[] = { 0x03, ' ', '+', '0', CS, '0', 'e', '+', '0' };
529 uint8_t b_0[] = { };
530 CHECK_BER_STRICT(0.0, "0", "0", b_p0_nr3, b_0); }
531 { uint8_t b_m0_nr3[] = { 0x03, '-', '0', CS, '0', 'E', '-', '0' };
532 uint8_t b_m0[] = { 0x43 };
533 CHECK_BER_STRICT(-0.0, "-0", "-0", b_m0_nr3, b_m0); }
534 { uint8_t b_m0_nr3[] = { 0x03, ' ', '-', '0', CS, '0', 'e', '-', '0' };
535 uint8_t b_m0[] = { 0x43 };
536 CHECK_BER_STRICT(-0.0, "-0", "-0", b_m0_nr3, b_m0); }
537
538 /* 8.5.6 b) => 8.5.8 NR3 "5.e-1" */
539 { uint8_t b_5_nr3[] = { 0x03, '5', CS, 'e', '-', '1' };
540 uint8_t b_5[] = { 0x80, 0xff, 0x01 };
541 CHECK_BER_STRICT(0.5, "0.5", "5.0E-1", b_5_nr3, b_5); }
542 { uint8_t b_5_nr3[] = { 0x03, '0', '5', CS, 'E', '-', '1' };
543 uint8_t b_5[] = { 0x80, 0xff, 0x01 };
544 CHECK_BER_STRICT(0.5, "0.5", "5.0E-1", b_5_nr3, b_5); }
545 { uint8_t b_5_nr3[] = { 0x03, ' ', '5', CS, 'e', '-', '1' };
546 uint8_t b_5[] = { 0x80, 0xff, 0x01 };
547 CHECK_BER_STRICT(0.5, "0.5", "5.0E-1", b_5_nr3, b_5); }
548 { uint8_t b_p5_nr3[] = { 0x03, '+', '5', CS, 'E', '-', '1' };
549 uint8_t b_5[] = { 0x80, 0xff, 0x01 };
550 CHECK_BER_STRICT(0.5, "0.5", "5.0E-1", b_p5_nr3, b_5); }
551 { uint8_t b_p5_nr3[] = { 0x03, ' ', '+', '5', CS, 'e', '-', '1' };
552 uint8_t b_5[] = { 0x80, 0xff, 0x01 };
553 CHECK_BER_STRICT(0.5, "0.5", "5.0E-1", b_p5_nr3, b_5); }
554 { uint8_t b_m5_nr3[] = { 0x03, '-', '5', CS, 'E', '-', '1' };
555 uint8_t b_m5[] = { 0xC0, 0xff, 0x01 };
556 CHECK_BER_STRICT(-0.5, "-0.5", "-5.0E-1", b_m5_nr3, b_m5); }
557 { uint8_t b_m5_nr3[] = { 0x03, ' ', '-', '5', CS, 'e', '-', '1' };
558 uint8_t b_m5[] = { 0xC0, 0xff, 0x01 };
559 CHECK_BER_STRICT(-0.5, "-0.5", "-5.0E-1", b_m5_nr3, b_m5); }
560
561 /* 8.5.6 b) => 8.5.8 NR3 ".5e1" */
562 { uint8_t b_05_nr3[] = { 0x03, CS, '5', 'e', '+', '1' };
563 uint8_t b_05[] = { 0x80, 0x00, 0x05 };
564 CHECK_BER_STRICT(5.0, "5.0", "5.0E0", b_05_nr3, b_05); }
565 { uint8_t b_05_nr3[] = { 0x03, '0', CS, '5', 'E', '+', '1'};
566 uint8_t b_05[] = { 0x80, 0x00, 0x05 };
567 CHECK_BER_STRICT(5.0, "5.0", "5.0E0", b_05_nr3, b_05); }
568 { uint8_t b_05_nr3[] = { 0x03, ' ', CS, '5', 'e', '1'};
569 uint8_t b_05[] = { 0x80, 0x00, 0x05 };
570 CHECK_BER_STRICT(5.0, "5.0", "5.0E0", b_05_nr3, b_05); }
571 { uint8_t b_p1_nr3[] = { 0x03, '+', CS, '5', 'E', '1' };
572 uint8_t b_05[] = { 0x80, 0x00, 0x05 };
573 CHECK_BER_STRICT(5.0, "5.0", "5.0E0", b_p1_nr3, b_05); }
574 { uint8_t b_p1_nr3[] = { 0x03, ' ', '+', CS, '5', 'e', '+', '1' };
575 uint8_t b_05[] = { 0x80, 0x00, 0x05 };
576 CHECK_BER_STRICT(5.0, "5.0", "5.0E0", b_p1_nr3, b_05); }
577 { uint8_t b_m05_nr3[] = { 0x03, '-', CS, '5', 'E', '+', '1' };
578 uint8_t b_m05[] = { 0xC0, 0x00, 0x05 };
579 CHECK_BER_STRICT(-5.0, "-5.0", "-5.0E0", b_m05_nr3, b_m05); }
580 { uint8_t b_m05_nr3[] = { 0x03, ' ', '-', CS, '5', 'e', '1' };
581 uint8_t b_m05[] = { 0xC0, 0x00, 0x05 };
582 CHECK_BER_STRICT(-5.0, "-5.0", "-5.0E0", b_m05_nr3, b_m05); }
583 } /* for(comma symbol) */
584 }
Lev Walkin5fe72e92012-01-07 17:00:29 -0800585
Lev Walkine8727ec2012-01-09 05:46:16 -0800586 /* Scan through the range of bits, construct the valid base-2 numbers, and
587 * try two-way conversion with them */
588 {
589 int base, sign, scaling_factor, exponent, mantissa;
590 for(base = 0; base <= 2; base++) {
591 for(sign = 0; sign <= 1; sign++) {
592 for(scaling_factor = 0; scaling_factor <= 3; scaling_factor++) {
593 for(exponent = -1000; exponent < 1000; exponent += (exponent > -990 && exponent < 990) ? 100 : 1) {
594 for(mantissa = 0; mantissa < 66000; mantissa += (mantissa > 300 && mantissa < 65400) ? 100 : 1) {
595 check_ber_857_encoding(base, sign, scaling_factor, exponent, mantissa);
596 }
597 }
598 }
599 }
600 }
601 }
602
Lev Walkin5fe72e92012-01-07 17:00:29 -0800603 {
604 uint8_t b_1_0[] =
605 { 0x80, 0xcc, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
606 uint8_t b_1_1[] =
607 { 0x80, 0xcc, 0x11, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a };
608 uint8_t b_3_14[] =
609 { 0x80, 0xcd, 0x19, 0x1e, 0xb8, 0x51, 0xeb, 0x85, 0x1f };
610 uint8_t b_3_14_mo1[] =
611 { 0xC0, 0xc5, 0x19, 0x1e, 0xb8, 0x51, 0xeb, 0x85, 0x1f,3};
612 uint8_t b_3_14_mo2[] =
613 { 0x80, 0xbd, 0x19, 0x1e, 0xb8, 0x51, 0xeb, 0x85, 0x1f,3,2};
614
615 CHECK_BER_NONSTRICT(1.0, "1.0", "1.0E0", b_1_0);
616 CHECK_BER_NONSTRICT(1.1, "1.1", "1.1E0", b_1_1);
617 CHECK_BER_NONSTRICT(3.14, "3.14", "3.14E0", b_3_14);
618 /* These two are very interesting! They check mantissa overflow! */
619 CHECK_BER_NONSTRICT(-3.14, "-3.14", "-3.14E0", b_3_14_mo1);
620 CHECK_BER_NONSTRICT(3.14, "3.14", "3.14E0", b_3_14_mo2);
621 }
622}
Lev Walkinf0b808d2005-04-25 21:08:25 +0000623
Lev Walkin41ba1f22004-09-14 12:46:35 +0000624int
625main() {
626 REAL_t rn;
Lev Walkin41ba1f22004-09-14 12:46:35 +0000627 memset(&rn, 0, sizeof(rn));
628
Lev Walkin5fe72e92012-01-07 17:00:29 -0800629 check_ber_encoding();
630
Lev Walkined465432004-09-27 20:52:36 +0000631 check(&rn, 0.0, "0", "0");
632 check(&rn, -0.0, "-0", "-0"); /* minus-zero */
Lev Walkin9c57f332017-09-17 22:30:49 -0700633 check(&rn, NAN, "<NOT-A-NUMBER/>", "<NOT-A-NUMBER/>");
634 check(&rn, INFINITY, "<PLUS-INFINITY/>", "<PLUS-INFINITY/>");
635 check(&rn, -INFINITY, "<MINUS-INFINITY/>", "<MINUS-INFINITY/>");
Lev Walkined465432004-09-27 20:52:36 +0000636 check(&rn, 1.0, "1.0", "1.0E0");
637 check(&rn, -1.0, "-1.0", "-1.0E0");
Lev Walkined465432004-09-27 20:52:36 +0000638 check(&rn, 0.1, "0.1", "1.0E-1");
Lev Walkinf0b808d2005-04-25 21:08:25 +0000639 check(&rn, 0.01, "0.01", "1.0E-2");
640 check(&rn, 0.02, "0.02", "2.0E-2");
641 check(&rn, 0.09, "0.09", "9.0E-2");
642 check(&rn, 1.5, "1.5", "1.5E0");
Lev Walkined465432004-09-27 20:52:36 +0000643 check(&rn, 0.33333, "0.33333", "3.3333E-1");
644 check(&rn, 2, "2.0", "2.0E0");
645 check(&rn, 2.1, "2.1", "2.1E0");
646 check(&rn, 3, "3.0", "3.0E0");
647 check(&rn, 3.1, "3.1", "3.1E0");
648 check(&rn, 3.14, "3.14", "3.14E0");
649 check(&rn, 3.1415, "3.1415", "3.1415E0");
650 check(&rn, 3.141592, "3.141592", "3.141592E0");
651 check(&rn, 3.14159265, "3.14159265", "3.14159265E0");
652 check(&rn, -3.14159265, "-3.14159265", "-3.14159265E0");
653 check(&rn, 14159265.0, "14159265.0", "1.4159265E7");
654 check(&rn, -123456789123456789.0, "-123456789123456784.0", "-1.234567891234568E17");
Lev Walkinf0b808d2005-04-25 21:08:25 +0000655 check(&rn, 0.00000000001, "0.00000000001", "9.999999999999999E-12");
656 check(&rn, 0.00000000002, "0.00000000002", "2.0E-11");
657 check(&rn, 0.00000000009, "0.00000000009", "9.0E-11");
658 check(&rn, 0.000000000002, "0.000000000002", "2.0E-12");
659 check(&rn, 0.0000000000002, "0.0000000000002", "2.0E-13");
660 check(&rn, 0.00000000000002, "0.00000000000002", "2.0E-14");
661 check(&rn, 0.000000000000002, "0.000000000000002", "2.0E-15");
662 check(&rn, 0.0000000000000002, "0.0", "2.0E-16");
Lev Walkined465432004-09-27 20:52:36 +0000663 check(&rn, 0.0000000000000000000001, "0.0", "1.0E-22");
664 check(&rn, 0.000000000000000000000000000001, "0.0", "1.0E-30"); /* proved 2B a problem */
665 check(&rn,-0.000000000000000000000000000001, "-0.0", "-1.0E-30"); /* proved 2B a problem */
666 check(&rn, 0.0000000000010000000001000000000001, 0, 0);
667 check(&rn, 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001, 0, 0);
668 check(&rn, 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001, 0, 0);
669 check(&rn,-0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001, 0, 0);
670 check(&rn,-3.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333, 0, 0);
671 check(&rn, 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000033333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333, 0, 0);
Lev Walkin8ca13c82016-01-24 22:40:00 -0800672 check(&rn, 0.25, "0.25", "2.5E-1");
673 check(&rn, -0.25, "-0.25", "-2.5E-1");
674 check(&rn, 0.03, "0.03", "3.0E-2");
675 check(&rn, -0.03, "-0.03", "-3.0E-2");
676
677 check(&rn, 4.01E-50, "0.0", "4.01E-50");
678 check(&rn, -4.01E-50, "-0.0", "-4.01E-50");
679 check(&rn, -4.9406564584124654E-324, "-0.0", "-4.940656458412465E-324"); /* MIN */
680 check(&rn, DBL_MIN, "0.0", "2.225073858507201E-308"); /* MIN */
681 check(&rn, -DBL_MIN, "-0.0", "-2.225073858507201E-308"); /* -MIN */
682 check(&rn, DBL_MAX, "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0", "1.797693134862316E308"); /* MAX */
683 check(&rn, -DBL_MAX, "-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0", "-1.797693134862316E308"); /* MAX */
684 check(&rn, -DBL_TRUE_MIN, "-0.0", "-4.940656458412465E-324"); /* subnorm */
685 check(&rn, DBL_TRUE_MIN, "0.0", "4.940656458412465E-324"); /* subnorm */
Lev Walkin41ba1f22004-09-14 12:46:35 +0000686
Lev Walkin5f560912004-10-21 13:37:57 +0000687
Lev Walkin1aea6982004-10-26 09:35:25 +0000688#ifdef NAN
689 check_xer(0, NAN); /* "<NOT-A-NUMBER/>" */
690#else
Lev Walkin5f560912004-10-21 13:37:57 +0000691 check_xer(0, zero/zero); /* "<NOT-A-NUMBER/>" */
Lev Walkin1aea6982004-10-26 09:35:25 +0000692#endif
693#ifdef INFINITY
694 check_xer(0, INFINITY); /* "<PLUS-INFINITY/>" */
695 check_xer(0, -INFINITY); /* "<MINUS-INFINITY/>" */
696#else
Lev Walkin5f560912004-10-21 13:37:57 +0000697 check_xer(0, 1.0/zero); /* "<PLUS-INFINITY/>" */
698 check_xer(0, -1.0/zero); /* "<MINUS-INFINITY/>" */
Lev Walkin1aea6982004-10-26 09:35:25 +0000699#endif
Lev Walkin5f560912004-10-21 13:37:57 +0000700 check_xer(0, 1.0);
701 check_xer(0, -1.0);
702 check_xer(0, 1.5);
703 check_xer(0, 123);
704 check_xer(1, 0.0000000000000000000001);
705 check_xer(1, -0.0000000000000000000001);
706
Lev Walkin229ad002017-09-18 20:13:49 -0700707 ASN_STRUCT_RESET(asn_DEF_REAL, &rn);
Lev Walkin41ba1f22004-09-14 12:46:35 +0000708 return 0;
709}