2 * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
5 #ifndef ASN_TYPE_REAL_H
6 #define ASN_TYPE_REAL_H
8 #include <asn_application.h>
9 #include <asn_codecs_prim.h>
11 #define _ISOC99_SOURCE /* For ilogb() and quiet NAN */
13 #define _BSD_SOURCE /* To reintroduce finite(3) */
16 #include <sys/resource.h> /* For INFINITY */
20 #if !(defined(NAN) || defined(INFINITY))
21 static volatile double real_zero CC_NOTUSED = 0.0;
27 #define INFINITY (1.0/0.0)
34 typedef enum specialRealValue {
39 extern struct specialRealValue_s {
43 } specialRealValue[3];
45 typedef ASN__PRIMITIVE_TYPE_t REAL_t;
47 extern asn_TYPE_descriptor_t asn_DEF_REAL;
48 extern asn_TYPE_operation_t asn_OP_REAL;
50 #define REAL_free ASN__PRIMITIVE_TYPE_free
52 #if !defined(ASN_DISABLE_PRINT_SUPPORT)
53 asn_struct_print_f REAL_print;
54 #endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
56 asn_struct_compare_f REAL_compare;
58 #define REAL_constraint asn_generic_no_constraint
60 #if !defined(ASN_DISABLE_BER_SUPPORT)
61 #define REAL_decode_ber ber_decode_primitive
62 #define REAL_encode_der der_encode_primitive
63 #endif /* !defined(ASN_DISABLE_BER_SUPPORT) */
65 #if !defined(ASN_DISABLE_XER_SUPPORT)
66 xer_type_decoder_f REAL_decode_xer;
67 xer_type_encoder_f REAL_encode_xer;
68 #endif /* !defined(ASN_DISABLE_XER_SUPPORT) */
70 #if !defined(ASN_DISABLE_JER_SUPPORT)
71 jer_type_encoder_f REAL_encode_jer;
72 #endif /* !defined(ASN_DISABLE_JER_SUPPORT) */
74 #if !defined(ASN_DISABLE_OER_SUPPORT)
75 oer_type_decoder_f REAL_decode_oer;
76 oer_type_encoder_f REAL_encode_oer;
77 #endif /* !defined(ASN_DISABLE_OER_SUPPORT) */
79 #if !defined(ASN_DISABLE_UPER_SUPPORT)
80 per_type_decoder_f REAL_decode_uper;
81 per_type_encoder_f REAL_encode_uper;
82 #endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */
83 #if !defined(ASN_DISABLE_APER_SUPPORT)
84 per_type_decoder_f REAL_decode_aper;
85 per_type_encoder_f REAL_encode_aper;
86 #endif /* !defined(ASN_DISABLE_APER_SUPPORT) */
88 #if !defined(ASN_DISABLE_RFILL_SUPPORT)
89 asn_random_fill_f REAL_random_fill;
90 #endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */
92 /***********************************
93 * Some handy conversion routines. *
94 ***********************************/
96 ssize_t REAL__dump(double d, int canonical, asn_app_consume_bytes_f *cb, void *app_key);
99 * Convert between native double type and REAL representation (DER).
101 * 0: Value converted successfully
102 * -1: An error occurred while converting the value: invalid format.
104 int asn_REAL2double(const REAL_t *real_ptr, double *d);
105 int asn_double2REAL(REAL_t *real_ptr, double d);
108 * Downcast double to float while checking that no overflow occurs.
109 * This allows stricter control of the input data.
111 * 0: The conversion was successful (perhaps with a loss of precision)
112 * -1: The conversion created overflow into infinities.
113 * The (outcome) is ALWAYS set to a value you'd expect from the
114 * standard silent float to double conversion behavior.
116 int asn_double2float(double d, float *outcome);
122 #endif /* ASN_TYPE_REAL_H */