3 * Copyright 2009 Free Software Foundation, Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef INCLUDED_VRT_TYPES_H
19 #define INCLUDED_VRT_TYPES_H
23 /* macros for dealing with fixed point numbers */
24 #define _FXPT_C(_type, _x, _rp) ((_type)((_x)*(1ll << _rp)))
25 #define _FXPT_TO_INT(_x, _one) (((_x) + ((_one)/2))/(_one))
26 #define _FXPT_TO_DOUBLE(_x, _one) ((double)(_x) * (1.0/(_one)))
28 /***********************************************************************
29 * The VRT Altitude Type (meters)
30 **********************************************************************/
31 typedef int32_t vrt_altitude_t;
32 #define VRT_ALTITUDE_RP 5
33 #define VRT_ALTITUDE_C(_x) _FXPT_C(vrt_altitude_t, _x, VRT_ALTITUDE_RP)
35 static inline vrt_altitude_t
36 double_to_vrt_altitude(double num){
37 return VRT_ALTITUDE_C(num);
41 vrt_altitude_round_to_int(vrt_altitude_t fx){
42 return _FXPT_TO_INT(fx, VRT_ALTITUDE_C(1));
46 vrt_altitude_to_double(vrt_altitude_t fx){
47 return _FXPT_TO_DOUBLE(fx, VRT_ALTITUDE_C(1));
50 /***********************************************************************
51 * The VRT Geolocation Angle Type (degrees)
52 **********************************************************************/
53 typedef int32_t vrt_geo_angle_t;
54 #define VRT_GEO_ANGLE_RP 22
55 #define VRT_GEO_ANGLE_C(_x) _FXPT_C(vrt_geo_angle_t, _x, VRT_GEO_ANGLE_RP)
57 static inline vrt_geo_angle_t
58 double_to_vrt_geo_angle(double num){
59 return VRT_GEO_ANGLE_C(num);
63 vrt_geo_angle_round_to_int(vrt_geo_angle_t fx){
64 return _FXPT_TO_INT(fx, VRT_GEO_ANGLE_C(1));
68 vrt_geo_angle_to_double(vrt_geo_angle_t fx){
69 return _FXPT_TO_DOUBLE(fx, VRT_GEO_ANGLE_C(1));
72 /***********************************************************************
73 * The VRT Frequency Type (Hz)
74 **********************************************************************/
75 typedef int64_t vrt_freq_t;
76 #define VRT_FREQ_RP 20
77 #define VRT_FREQ_C(_x) _FXPT_C(vrt_freq_t, _x, VRT_FREQ_RP)
79 static inline vrt_freq_t
80 double_to_vrt_freq(double num){
81 return VRT_FREQ_C(num);
85 vrt_freq_round_to_int(vrt_freq_t fx){
86 return _FXPT_TO_INT(fx, VRT_FREQ_C(1));
90 vrt_freq_to_double(vrt_freq_t fx){
91 return _FXPT_TO_DOUBLE(fx, VRT_FREQ_C(1));
94 /***********************************************************************
95 * The VRT Gain Type (dB)
96 **********************************************************************/
97 typedef int16_t vrt_gain_t;
99 #define VRT_GAIN_C(_x) _FXPT_C(vrt_gain_t, _x, VRT_GAIN_RP)
101 static inline vrt_gain_t
102 double_to_vrt_gain(double num){
103 return VRT_GAIN_C(num);
106 static inline int16_t
107 vrt_gain_round_to_int(vrt_gain_t fx){
108 return _FXPT_TO_INT(fx, VRT_GAIN_C(1));
112 vrt_gain_to_double(vrt_gain_t fx){
113 return _FXPT_TO_DOUBLE(fx, VRT_GAIN_C(1));
116 /***********************************************************************
117 * The VRT Temperature Type (Celcius)
118 **********************************************************************/
119 typedef int16_t vrt_temp_t;
120 #define VRT_TEMP_RP 6
121 #define VRT_TEMP_C(_x) _FXPT_C(vrt_temp_t, _x, VRT_TEMP_RP)
123 static inline vrt_temp_t
124 double_to_vrt_temp(double num){
125 return VRT_TEMP_C(num);
128 static inline int16_t
129 vrt_temp_round_to_int(vrt_temp_t fx){
130 return _FXPT_TO_INT(fx, VRT_TEMP_C(1));
134 vrt_temp_to_double(vrt_temp_t fx){
135 return _FXPT_TO_DOUBLE(fx, VRT_TEMP_C(1));
138 #endif /* INCLUDED_VRT_TYPES_H */