2 * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
5 #define _ISOC99_SOURCE /* For ilogb() and quiet NAN */
7 #define _BSD_SOURCE /* To reintroduce finite(3) */
9 #include <asn_internal.h>
11 #include <sys/resource.h> /* For INFINITY */
13 #include <stdlib.h> /* for strtod(3) */
18 #include <OCTET_STRING.h>
21 #define INT_MAX ((int)(((unsigned int)-1) >> 1))
23 #if !(defined(NAN) || defined(INFINITY))
24 static volatile double real_zero CC_NOTUSED = 0.0;
30 #define INFINITY (1.0/0.0)
33 #if defined(__clang__)
35 * isnan() is defined using generic selections and won't compile in
36 * strict C89 mode because of too fancy system's standard library.
37 * However, prior to C11 the math had a perfectly working isnan()
38 * in the math library.
39 * Disable generic selection warning so we can test C89 mode with newer libc.
41 #pragma clang diagnostic push
42 #pragma clang diagnostic ignored "-Wc11-extensions"
43 static int asn_isnan(double d) {
46 static int asn_isfinite(double d) {
48 return isfinite(d); /* ISO C99 */
50 return finite(d); /* Deprecated on Mac OS X 10.9 */
53 #pragma clang diagnostic pop
55 #define asn_isnan(v) isnan(v)
57 #define asn_isfinite(d) isfinite(d) /* ISO C99 */
59 #define asn_isfinite(d) finite(d) /* Deprecated on Mac OS X 10.9 */
64 * REAL basic type description.
66 static const ber_tlv_tag_t asn_DEF_REAL_tags[] = {
67 (ASN_TAG_CLASS_UNIVERSAL | (9 << 2))
69 asn_TYPE_operation_t asn_OP_REAL = {
70 ASN__PRIMITIVE_TYPE_free,
77 #ifdef ASN_DISABLE_OER_SUPPORT
83 #endif /* ASN_DISABLE_OER_SUPPORT */
84 #ifdef ASN_DISABLE_PER_SUPPORT
94 #endif /* ASN_DISABLE_PER_SUPPORT */
96 0 /* Use generic outmost tag fetcher */
98 asn_TYPE_descriptor_t asn_DEF_REAL = {
103 sizeof(asn_DEF_REAL_tags) / sizeof(asn_DEF_REAL_tags[0]),
104 asn_DEF_REAL_tags, /* Same as above */
105 sizeof(asn_DEF_REAL_tags) / sizeof(asn_DEF_REAL_tags[0]),
106 { 0, 0, asn_generic_no_constraint },
112 typedef enum specialRealValue {
116 } specialRealValue_e;
117 static struct specialRealValue_s {
121 } specialRealValue[] = {
122 #define SRV_SET(foo, val) { foo, sizeof(foo) - 1, val }
123 SRV_SET("<NOT-A-NUMBER/>", 0),
124 SRV_SET("<MINUS-INFINITY/>", -1),
125 SRV_SET("<PLUS-INFINITY/>", 1),
130 REAL__dump(double d, int canonical, asn_app_consume_bytes_f *cb, void *app_key) {
132 char *buf = local_buf;
133 ssize_t buflen = sizeof(local_buf);
134 const char *fmt = canonical ? "%.17E" /* Precise */ : "%.15f" /* Pleasant*/;
138 * Check whether it is a special value.
140 /* fpclassify(3) is not portable yet */
142 buf = specialRealValue[SRV__NOT_A_NUMBER].string;
143 buflen = specialRealValue[SRV__NOT_A_NUMBER].length;
144 return (cb(buf, buflen, app_key) < 0) ? -1 : buflen;
145 } else if(!asn_isfinite(d)) {
146 if(copysign(1.0, d) < 0.0) {
147 buf = specialRealValue[SRV__MINUS_INFINITY].string;
148 buflen = specialRealValue[SRV__MINUS_INFINITY].length;
150 buf = specialRealValue[SRV__PLUS_INFINITY].string;
151 buflen = specialRealValue[SRV__PLUS_INFINITY].length;
153 return (cb(buf, buflen, app_key) < 0) ? -1 : buflen;
154 } else if(ilogb(d) <= -INT_MAX) {
155 if(copysign(1.0, d) < 0.0) {
162 return (cb(buf, buflen, app_key) < 0) ? -1 : buflen;
166 * Use the libc's double printing, hopefully they got it right.
169 ret = snprintf(buf, buflen, fmt, d);
171 /* There are some old broken APIs. */
174 /* Should be plenty. */
175 if(buf != local_buf) FREEMEM(buf);
178 } else if(ret >= buflen) {
184 if(buf != local_buf) FREEMEM(buf);
185 buf = (char *)MALLOC(buflen);
191 * Transform the "[-]d.dddE+-dd" output into "[-]d.dddE[-]d"
192 * Check that snprintf() constructed the output correctly.
195 char *end = buf + buflen;
197 char *first_zero_in_run;
203 } lz_state = LZSTATE_NOTHING;
205 dot = (buf[0] == 0x2d /* '-' */) ? (buf + 2) : (buf + 1);
207 if(buf != local_buf) FREEMEM(buf);
209 return -1; /* Not a dot, really */
211 *dot = 0x2e; /* Replace possible comma */
213 for(first_zero_in_run = last_zero = s = dot + 2; s < end; s++) {
216 if(lz_state == LZSTATE_ZEROES) last_zero = first_zero_in_run;
219 if(lz_state == LZSTATE_NOTHING) first_zero_in_run = s;
220 lz_state = LZSTATE_ZEROES;
223 lz_state = LZSTATE_NOTHING;
230 if(buf != local_buf) FREEMEM(buf);
232 return -1; /* No promised E */
242 if(*expptr == 0x2b /* '+' */) {
252 if(buf != local_buf) FREEMEM(buf);
256 if(*expptr == 0x30) {
260 if(lz_state == LZSTATE_ZEROES) {
261 *last_zero = 0x45; /* E */
262 buflen -= s - (last_zero + 1);
265 *s++ = 0x2d /* '-' */;
269 for(; expptr <= end; s++, expptr++)
274 * Remove trailing zeros.
276 char *end = buf + buflen;
277 char *last_zero = end;
280 for(z = end - 1; z > buf; z--) {
286 case 0x31: case 0x32: case 0x33: case 0x34:
287 case 0x35: case 0x36: case 0x37: case 0x38: case 0x39:
290 default: /* Catch dot and other separators */
292 * Replace possible comma (which may even
293 * be not a comma at all: locale-defined).
296 if(last_zero == z + 1) { /* leave x.0 */
299 buflen = last_zero - buf;
307 ret = cb(buf, buflen, app_key);
308 if(buf != local_buf) FREEMEM(buf);
309 return (ret < 0) ? -1 : buflen;
313 REAL_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
314 asn_app_consume_bytes_f *cb, void *app_key) {
315 const REAL_t *st = (const REAL_t *)sptr;
319 (void)td; /* Unused argument */
320 (void)ilevel; /* Unused argument */
323 ret = cb("<absent>", 8, app_key);
324 else if(asn_REAL2double(st, &d))
325 ret = cb("<error>", 7, app_key);
327 ret = REAL__dump(d, 0, cb, app_key);
329 return (ret < 0) ? -1 : 0;
333 REAL_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
335 const REAL_t *a = aptr;
336 const REAL_t *b = bptr;
343 ra = asn_REAL2double(a, &adbl);
344 rb = asn_REAL2double(b, &bdbl);
345 if(ra == 0 && rb == 0) {
346 if(asn_isnan(adbl)) {
347 if(asn_isnan(bdbl)) {
352 } else if(asn_isnan(bdbl)) {
355 /* Value comparison. */
358 } else if(adbl > bdbl) {
376 REAL_encode_xer(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
377 enum xer_encoder_flags_e flags, asn_app_consume_bytes_f *cb,
379 const REAL_t *st = (const REAL_t *)sptr;
380 asn_enc_rval_t er = {0,0,0};
385 if(!st || !st->buf || asn_REAL2double(st, &d))
388 er.encoded = REAL__dump(d, flags & XER_F_CANONICAL, cb, app_key);
389 if(er.encoded < 0) ASN__ENCODE_FAILED;
396 * Decode the chunk of XML text encoding REAL.
398 static enum xer_pbd_rval
399 REAL__xer_body_decode(const asn_TYPE_descriptor_t *td, void *sptr,
400 const void *chunk_buf, size_t chunk_size) {
401 REAL_t *st = (REAL_t *)sptr;
403 const char *xerdata = (const char *)chunk_buf;
409 if(!chunk_size) return XPBD_BROKEN_ENCODING;
412 * Decode an XMLSpecialRealValue: <MINUS-INFINITY>, etc.
414 if(xerdata[0] == 0x3c /* '<' */) {
416 for(i = 0; i < sizeof(specialRealValue)
417 / sizeof(specialRealValue[0]); i++) {
418 struct specialRealValue_s *srv = &specialRealValue[i];
421 if(srv->length != chunk_size
422 || memcmp(srv->string, chunk_buf, chunk_size))
426 * It could've been done using
427 * (double)srv->dv / real_zero,
428 * but it summons fp exception on some platforms.
431 case -1: dv = - INFINITY; break;
432 case 0: dv = NAN; break;
433 case 1: dv = INFINITY; break;
434 default: return XPBD_SYSTEM_FAILURE;
437 if(asn_double2REAL(st, dv))
438 return XPBD_SYSTEM_FAILURE;
440 return XPBD_BODY_CONSUMED;
442 ASN_DEBUG("Unknown XMLSpecialRealValue");
443 return XPBD_BROKEN_ENCODING;
447 * Copy chunk into the nul-terminated string, and run strtod.
449 b = (char *)MALLOC(chunk_size + 1);
450 if(!b) return XPBD_SYSTEM_FAILURE;
451 memcpy(b, chunk_buf, chunk_size);
452 b[chunk_size] = 0; /* nul-terminate */
454 value = strtod(b, &endptr);
456 if(endptr == b) return XPBD_BROKEN_ENCODING;
458 if(asn_double2REAL(st, value))
459 return XPBD_SYSTEM_FAILURE;
461 return XPBD_BODY_CONSUMED;
465 REAL_decode_xer(const asn_codec_ctx_t *opt_codec_ctx,
466 const asn_TYPE_descriptor_t *td, void **sptr,
467 const char *opt_mname, const void *buf_ptr, size_t size) {
468 return xer_decode_primitive(opt_codec_ctx, td,
469 sptr, sizeof(REAL_t), opt_mname,
470 buf_ptr, size, REAL__xer_body_decode);
474 asn_REAL2double(const REAL_t *st, double *dbl_value) {
477 if(!st || !st->buf) {
487 octv = st->buf[0]; /* unsigned byte */
489 switch(octv & 0xC0) {
490 case 0x40: /* X.690: 8.5.6 a) => 8.5.9 */
491 /* "SpecialRealValue" */
493 /* Be liberal in what you accept...
494 * http://en.wikipedia.org/wiki/Robustness_principle
495 if(st->size != 1) ...
499 case 0x40: /* 01000000: PLUS-INFINITY */
500 *dbl_value = INFINITY;
502 case 0x41: /* 01000001: MINUS-INFINITY */
503 *dbl_value = - INFINITY;
505 case 0x42: /* 01000010: NOT-A-NUMBER */
508 case 0x43: /* 01000011: minus zero */
515 case 0x00: { /* X.690: 8.5.7 */
517 * Decimal. NR{1,2,3} format from ISO 6093.
518 * NR1: [ ]*[+-]?[0-9]+
519 * NR2: [ ]*[+-]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)
520 * NR3: [ ]*[+-]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)[Ee][+-]?[0-9]+
527 if(octv == 0 || (octv & 0x3C)) {
528 /* Remaining values of bits 6 to 1 are Reserved. */
533 /* 1. By contract, an input buffer should be '\0'-terminated.
534 * OCTET STRING decoder ensures that, as is asn_double2REAL().
535 * 2. ISO 6093 specifies COMMA as a possible decimal separator.
536 * However, strtod() can't always deal with COMMA.
537 * So her we fix both by reallocating, copying and fixing.
539 if(st->buf[st->size] != '\0' || memchr(st->buf, ',', st->size)) {
540 const uint8_t *p, *end;
543 b = source = (char *)MALLOC(st->size + 1);
544 if(!source) return -1;
547 /* Copy without the first byte and with 0-termination */
548 for(p = st->buf + 1, end = st->buf + st->size;
550 *b = (*p == ',') ? '.' : *p;
553 source = (char *)&st->buf[1];
557 d = strtod(source, &endptr);
558 if(*endptr != '\0') {
559 /* Format is not consistent with ISO 6093 */
560 if(used_malloc) FREEMEM(source);
564 if(used_malloc) FREEMEM(source);
565 if(asn_isfinite(d)) {
576 * Binary representation.
580 int32_t expval; /* exponent value */
581 unsigned int elen; /* exponent value length, in octets */
588 switch((octv & 0x30) >> 4) {
589 case 0x00: baseF = 1; break; /* base 2 */
590 case 0x01: baseF = 3; break; /* base 8 */
591 case 0x02: baseF = 4; break; /* base 16 */
593 /* Reserved field, can't parse now. */
598 sign = (octv & 0x40); /* bit 7 */
599 scaleF = (octv & 0x0C) >> 2; /* bits 4 to 3 */
601 if(st->size <= 1 + (octv & 0x03)) {
606 elen = (octv & 0x03); /* bits 2 to 1; 8.5.6.4 */
607 if(elen == 0x03) { /* bits 2 to 1 = 11; 8.5.6.4, case d) */
608 elen = st->buf[1]; /* unsigned binary number */
609 if(elen == 0 || st->size <= (2 + elen)) {
613 /* FIXME: verify constraints of case d) */
619 /* Fetch the multibyte exponent */
620 expval = (int)(*(int8_t *)ptr);
621 if(elen >= sizeof(expval)-1) {
625 end = ptr + elen + 1;
626 for(ptr++; ptr < end; ptr++)
627 expval = (expval * 256) + *ptr;
629 m = 0.0; /* Initial mantissa value */
631 /* Okay, the exponent is here. Now, what about mantissa? */
632 end = st->buf + st->size;
633 for(; ptr < end; ptr++)
634 m = ldexp(m, 8) + *ptr;
637 ASN_DEBUG("m=%.10f, scF=%d, bF=%d, expval=%d, ldexp()=%f, ldexp()=%f\n",
638 m, scaleF, baseF, expval,
639 ldexp(m, expval * baseF + scaleF),
640 ldexp(m, scaleF) * pow(pow(2, baseF), expval)
644 * (S * N * 2^F) * B^E
646 m = ldexp(m, scaleF) * pow(pow(2, baseF), expval);
648 m = ldexp(m, expval * baseF + scaleF);
649 if(asn_isfinite(m)) {
650 *dbl_value = sign ? -m : m;
656 } /* if(binary_format) */
662 * Assume IEEE 754 floating point: standard 64 bit double.
663 * [1 bit sign] [11 bits exponent] [52 bits mantissa]
666 asn_double2REAL(REAL_t *st, double dbl_value) {
668 int float_big_endian = *(const char *)&test != 0;
669 uint8_t buf[16]; /* More than enough for 8-byte dbl_value */
670 uint8_t dscr[sizeof(dbl_value)]; /* double value scratch pad */
671 /* Assertion guards: won't even compile, if unexpected double size */
672 char assertion_buffer1[9 - sizeof(dbl_value)] CC_NOTUSED;
673 char assertion_buffer2[sizeof(dbl_value) - 7] CC_NOTUSED;
675 uint8_t *mstop; /* Last byte of mantissa */
676 unsigned int mval; /* Value of the last byte of mantissa */
677 unsigned int bmsign; /* binary mask with sign */
688 * ilogb(+-0) returns -INT_MAX or INT_MIN (platform-dependent)
689 * ilogb(+-inf) returns INT_MAX, logb(+-inf) returns +inf
690 * ilogb(NaN) returns INT_MIN or INT_MAX (platform-dependent)
692 expval = ilogb(dbl_value);
693 if(expval <= -INT_MAX /* Also catches +-0 and maybe isnan() */
694 || expval == INT_MAX /* catches isfin() and maybe isnan() */
696 if(!st->buf || st->size < 2) {
697 ptr = (uint8_t *)MALLOC(2);
699 if(st->buf) FREEMEM(st->buf);
702 /* fpclassify(3) is not portable yet */
703 if(asn_isnan(dbl_value)) {
704 st->buf[0] = 0x42; /* NaN */
707 } else if(!asn_isfinite(dbl_value)) {
708 if(copysign(1.0, dbl_value) < 0.0) {
709 st->buf[0] = 0x41; /* MINUS-INFINITY */
711 st->buf[0] = 0x40; /* PLUS-INFINITY */
716 if(copysign(1.0, dbl_value) >= 0.0) {
717 /* no content octets: positive zero */
718 st->buf[0] = 0; /* JIC */
721 /* Negative zero. #8.5.3, 8.5.9 */
730 if(float_big_endian) {
731 uint8_t *s = ((uint8_t *)&dbl_value) + 1;
732 uint8_t *end = ((uint8_t *)&dbl_value) + sizeof(double);
735 bmsign = 0x80 | ((s[-1] >> 1) & 0x40); /* binary mask & - */
736 for(mstop = d = dscr; s < end; d++, s++) {
741 uint8_t *s = ((uint8_t *)&dbl_value) + sizeof(dbl_value) - 2;
742 uint8_t *start = ((uint8_t *)&dbl_value);
745 bmsign = 0x80 | ((s[1] >> 1) & 0x40); /* binary mask & - */
746 for(mstop = d = dscr; s >= start; d++, s--) {
752 /* Remove parts of the exponent, leave mantissa and explicit 1. */
753 dscr[0] = 0x10 | (dscr[0] & 0x0f);
755 /* Adjust exponent in a very unobvious way */
756 expval -= 8 * ((mstop - dscr) + 1) - 4;
758 /* This loop ensures DER conformance by forcing mantissa odd: 11.3.1 */
760 if(mval && !(mval & 1)) {
766 * Figure out what needs to be done to make mantissa odd.
768 if(!(mval & 0x0f)) /* Speed-up a little */
770 while(((mval >> shift_count) & 1) == 0)
773 ishift = 8 - shift_count;
776 /* Go over the buffer, shifting it shift_count bits right. */
777 for(mptr = dscr; mptr <= mstop; mptr++) {
779 *mptr = accum | (mval >> shift_count);
780 accum = mval << ishift;
783 /* Adjust exponent appropriately. */
784 expval += shift_count;
788 if((expval >> 7) == -1) {
789 *ptr++ = bmsign | 0x00;
791 } else if((expval >> 15) == -1) {
792 *ptr++ = bmsign | 0x01;
793 *ptr++ = expval >> 8;
796 *ptr++ = bmsign | 0x02;
797 *ptr++ = expval >> 16;
798 *ptr++ = expval >> 8;
801 } else if(expval <= 0x7f) {
802 *ptr++ = bmsign | 0x00;
804 } else if(expval <= 0x7fff) {
805 *ptr++ = bmsign | 0x01;
806 *ptr++ = expval >> 8;
809 assert(expval <= 0x7fffff);
810 *ptr++ = bmsign | 0x02;
811 *ptr++ = expval >> 16;
812 *ptr++ = expval >> 8;
816 buflen = (mstop - dscr) + 1;
817 memcpy(ptr, dscr, buflen);
821 ptr = (uint8_t *)MALLOC(buflen + 1);
824 memcpy(ptr, buf, buflen);
825 buf[buflen] = 0; /* JIC */
827 if(st->buf) FREEMEM(st->buf);
834 int CC_ATTR_NO_SANITIZE("float-cast-overflow")
835 asn_double2float(double d, float *outcome) {
840 if(asn_isfinite(d) == asn_isfinite(f)) {
847 #ifndef ASN_DISABLE_OER_SUPPORT
850 * Encode as Canonical OER
853 REAL_encode_oer(const asn_TYPE_descriptor_t *td,
854 const asn_oer_constraints_t *constraints, const void *sptr,
855 asn_app_consume_bytes_f *cb, void *app_key) {
856 const REAL_t *st = sptr;
857 asn_enc_rval_t er = {0,0,0};
860 if(!st || !st->buf || !td)
863 if(!constraints) constraints = td->encoding_constraints.oer_constraints;
864 if(constraints && constraints->value.width != 0) {
865 /* If we're constrained to a narrow float/double representation, we
866 * shouldn't have ended up using REAL. Expecting NativeReal. */
870 /* Encode a fake REAL */
871 len_len = oer_serialize_length(st->size, cb, app_key);
872 if(len_len < 0 || cb(st->buf, st->size, app_key) < 0) {
875 er.encoded = len_len + st->size;
881 REAL_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
882 const asn_TYPE_descriptor_t *td,
883 const asn_oer_constraints_t *constraints, void **sptr,
884 const void *ptr, size_t size) {
885 asn_dec_rval_t ok = {RC_OK, 0};
889 size_t real_body_len;
893 if(!constraints) constraints = td->encoding_constraints.oer_constraints;
894 if(constraints && constraints->value.width != 0) {
895 /* If we're constrained to a narrow float/double representation, we
896 * shouldn't have ended up using REAL. Expecting NativeReal. */
900 len_len = oer_fetch_length(ptr, size, &real_body_len);
901 if(len_len < 0) ASN__DECODE_FAILED;
902 if(len_len == 0) ASN__DECODE_STARVED;
904 ptr = (const char *)ptr + len_len;
907 if(real_body_len > size) ASN__DECODE_STARVED;
909 buf = CALLOC(1, real_body_len + 1);
910 if(!buf) ASN__DECODE_FAILED;
913 st = (*sptr = CALLOC(1, sizeof(REAL_t)));
922 memcpy(buf, ptr, real_body_len);
923 buf[real_body_len] = '\0';
926 st->size = real_body_len;
928 ok.consumed = len_len + real_body_len;
932 #endif /* ASN_DISABLE_OER_SUPPORT */
934 #ifndef ASN_DISABLE_PER_SUPPORT
937 REAL_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
938 const asn_TYPE_descriptor_t *td,
939 const asn_per_constraints_t *constraints, void **sptr,
940 asn_per_data_t *pd) {
941 (void)constraints; /* No PER visible constraints */
942 return OCTET_STRING_decode_uper(opt_codec_ctx, td, 0, sptr, pd);
946 REAL_encode_uper(const asn_TYPE_descriptor_t *td,
947 const asn_per_constraints_t *constraints, const void *sptr,
948 asn_per_outp_t *po) {
949 (void)constraints; /* No PER visible constraints */
950 return OCTET_STRING_encode_uper(td, 0, sptr, po);
954 REAL_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
955 const asn_TYPE_descriptor_t *td,
956 const asn_per_constraints_t *constraints,
957 void **sptr, asn_per_data_t *pd) {
958 (void)constraints; /* No PER visible constraints */
959 return OCTET_STRING_decode_aper(opt_codec_ctx, td, 0, sptr, pd);
963 REAL_encode_aper(const asn_TYPE_descriptor_t *td,
964 const asn_per_constraints_t *constraints,
965 const void *sptr, asn_per_outp_t *po) {
966 (void)constraints; /* No PER visible constraints */
967 return OCTET_STRING_encode_aper(td, 0, sptr, po);
970 #endif /* ASN_DISABLE_PER_SUPPORT */
972 asn_random_fill_result_t
973 REAL_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
974 const asn_encoding_constraints_t *constraints,
976 asn_random_fill_result_t result_ok = {ARFILL_OK, 1};
977 asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
978 asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
979 static const double values[] = {
980 0, -0.0, -1, 1, -M_E, M_E, -3.14, 3.14, -M_PI, M_PI, -255, 255,
982 -2251799813685248.0, 2251799813685248.0,
984 -4503599627370496.0, 4503599627370496.0,
986 -1267650600228229401496703205376.0, 1267650600228229401496703205376.0,
992 -FLT_TRUE_MIN, FLT_TRUE_MIN,
995 -DBL_TRUE_MIN, DBL_TRUE_MIN,
997 INFINITY, -INFINITY, NAN};
1003 if(max_length == 0) return result_skipped;
1005 d = values[asn_random_between(0, sizeof(values) / sizeof(values[0]) - 1)];
1010 st = (REAL_t*)(*sptr = CALLOC(1, sizeof(REAL_t)));
1012 return result_failed;
1016 if(asn_double2REAL(st, d)) {
1018 ASN_STRUCT_RESET(*td, st);
1020 ASN_STRUCT_FREE(*td, st);
1022 return result_failed;
1025 result_ok.length = st->size;