File: thinfnan.h

package info (click to toggle)
therion 5.3.9-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 16,956 kB
  • sloc: ansic: 127,467; cpp: 89,790; tcl: 24,110; perl: 2,051; makefile: 1,003; asm: 201; python: 54; sh: 4
file content (118 lines) | stat: -rw-r--r-- 2,792 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
 * @file thinfnan.h
 * Therion number constants.
 */
  
/* Copyright (C) 2000 Stacho Mudrak
 * 
 * $Date: $
 * $RCSfile: $
 * $Revision: $
 *
 * -------------------------------------------------------------------- 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * --------------------------------------------------------------------
 */
 
#ifndef thinfnan_h
#define thinfnan_h

#include <math.h>


// nan handling
#ifdef NAN

#ifdef THLINUX
#define thnan NAN
#define thisnan isnan
#else
#define thnan -9e99
#define thisnan(number) (number == thnan)
#endif

#else

#define thnan -9e99
#define thisnan(number) (number == thnan)

#endif


// infinity handling
#ifdef INFINITY

#ifdef THLINUX
#define thinf INFINITY
#define thisinf isinf
#else
#define thinf 1e100
#define thisinf(number) (number >= thinf ? 1 : (number <= -thinf ? -1 : 0))
#endif

#else

#define thinf 1e100
#define thisinf(number) (number >= thinf ? 1 : (number <= -thinf ? -1 : 0))

#endif

/**
 * Update double variable if nan.
 *
 * @param oval Original value
 * @param uval Update value
 */
 
void thnan_update(double & oval, double uval);


/**
 * A inf nan printing macro.
 *
 * -Inf -> -999.999 
 *  Inf ->  999.999
 *  NaN -> 1000.0001
 */
 
#define thinn(cislo) (thisnan(cislo) ? 1000.0001 : \
    (thisinf(cislo) == 1 ? 999.999 : \
    (thisinf(cislo) == -1 ? -999.999 : cislo)))


// infnan.h
#endif

/**
 * Print number in nan format.
 */

#define thprintinfnan(cislo) {\
  if (thisnan(cislo)) \
    thprintf("thnan"); \
  else if (thisinf(cislo) == 1) \
    thprintf("thinf"); \
  else if (thisinf(cislo) == -1) \
    thprintf("-thinf"); \
  else \
    thprintf("%lg",cislo);}


#define THPI 3.1415926535898
#define thnanpow2(cislo) ((thisnan(cislo) ? 0.0 : cislo) * (thisnan(cislo) ? 0.0 : cislo))
#define thdxyz2length(dx,dy,dz) (sqrt(thnanpow2(dx) + thnanpow2(dy) + thnanpow2(dz)))
#define thdxyz2b(dx,dy,dz) (270 - (atan2(dy,dx) / THPI * 180.0 + 180))
#define thdxyz2bearing(dx,dy,dz) (thdxyz2b(dx,dy,dz) < 0.0 ? thdxyz2b(dx,dy,dz) + 360.0 : thdxyz2b(dx,dy,dz))
#define thdxyz2clino(dx,dy,dz) (atan2(dz,sqrt(thnanpow2(dx) + thnanpow2(dy))) / THPI * 180.0)