File: fltlib.h

package info (click to toggle)
lush 1.0%2Bfinal-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,256 kB
  • ctags: 4,254
  • sloc: ansic: 45,498; sh: 3,138; cpp: 2,456; makefile: 372; lisp: 79; python: 5
file content (197 lines) | stat: -rw-r--r-- 6,592 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/***********************************************************************
 * 
 *  LUSH Lisp Universal Shell
 *    Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
 *  Includes parts of TL3:
 *    Copyright (C) 1987-1999 Leon Bottou and Neuristique.
 *  Includes selected parts of SN3.2:
 *    Copyright (C) 1991-2001 AT&T Corp.
 * 
 *  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
 *  (at your option) 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, USA
 * 
 ***********************************************************************/

/***********************************************************************
 * $Id: fltlib.h,v 1.4 2004/02/09 20:59:51 leonb Exp $
 **********************************************************************/

#ifndef FLTLIB_H
#define FLTLIB_H

#ifndef DEFINE_H
#include "define.h"
#endif

#ifdef __cplusplus
extern "C" { 
#ifndef __cplusplus
}
#endif
#endif

/* 'real' is the natural floating point type */
#define real double

/* 'flt' is a fast single precision floating point type */
#define flt  float

/* Constants */
#define Fzero 	((flt)0.0)
#define Fone	((flt)1.0)
#define Ftwo	((flt)2.0)
#define Fminus	((flt)-1.0)
#define Fhalf	((flt)0.5)
/* ... double precision */
#define Dzero 	((double)0.0)
#define Done	((double)1.0)
#define Dtwo	((double)2.0)
#define Dminus	((double)-1.0)
#define Dhalf	((double)0.5)

/* Compatibility */
#define Ftor(x) ((real)(x))
#define Ftod(x) ((double)(x))
#define rtoF(x) ((flt)(x))
#define dtoF(x) ((flt)(x))


/* Standard Math routines */
#define Fsqrt(x)	((flt)sqrt((double)x))
#define Finv(x)		((flt)(1.0/(double)x))
#define Fsin(x)		((flt)sin((double)x))
#define Fcos(x)		((flt)cos((double)x))
#define Ftan(x)		((flt)tan((double)x))
#define Fasin(x)	((flt)asin((double)x))
#define Facos(x)	((flt)acos((double)x))
#define Fatan(x)	((flt)atan((double)x))
#define Fexp(x)         ((flt)exp((double)x))
#define Fexpm1(x)       ((flt)expm1((double)x))
#define Flog(x)         ((flt)log((double)x))
#define Flog1p(x)       ((flt)log1p((double)x))
#define Fsinh(x)        ((flt)sinh((double)x))
#define Fcosh(x)        ((flt)cosh((double)x))
#define Ftanh(x)        ((flt)tanh((double)x))
#define Fatanh(x)       ((flt)atanh((double)x))
/* ... double precision */
#define Dsqrt(x)	((double)sqrt((double)x))
#define Dinv(x)		((double)(1.0/(double)x))
#define Dsin(x)		((double)sin((double)x))
#define Dcos(x)		((double)cos((double)x))
#define Dtan(x)		((double)tan((double)x))
#define Dasin(x)	((double)asin((double)x))
#define Dacos(x)	((double)acos((double)x))
#define Datan(x)	((double)atan((double)x))
#define Dexp(x)         ((double)exp((double)x))
#define Dexpm1(x)       ((double)expm1((double)x))
#define Dlog(x)         ((double)log((double)x))
#define Dlog1p(x)       ((double)log1p((double)x))
#define Dsinh(x)        ((double)sinh((double)x))
#define Dcosh(x)        ((double)cosh((double)x))
#define Dtanh(x)        ((double)tanh((double)x))
#define Datanh(x)       ((double)atanh((double)x))


/* Piecewise functions */
#define Ffloor(x)       ((flt)floor((double)x))
#define Fabs(x)         (((x)<Fzero)?-(x):(x))
#define Fsgn(x)         (((x)<Fzero)?Fminus:Fone)
#define Fpiece(x)       (((x)<Fminus)?Fminus:(((x)<Fone)?x:Fone))
#define Frect(x)        ((((x)>Fminus)&&((x)<Fone))?Fone:Fzero)
/* ... double precision */
#define Dfloor(x)       ((double)floor((double)x))
#define Dabs(x)         (((x)<Dzero)?-(x):(x))
#define Dsgn(x)         (((x)<Dzero)?Dminus:Done)
#define Dpiece(x)       (((x)<Dminus)?Dminus:(((x)<Done)?x:Done))
#define Drect(x)        ((((x)>Dminus)&&((x)<Done))?Done:Dzero)

/* Rational approximation of TANH, SIGMOIDS */
/* Declarations for EXP(-|X|), EXP(-X2)     */
LUSHAPI flt FQtanh(flt x);
LUSHAPI flt FQDtanh(flt x);
LUSHAPI flt FQstdsigmoid(flt x);
LUSHAPI flt FQDstdsigmoid(flt x);
LUSHAPI flt FQexpmx(flt x);
LUSHAPI flt FQDexpmx(flt x);
LUSHAPI flt FQexpmx2(flt x);
LUSHAPI flt FQDexpmx2(flt x);

/* Spline interpolation */
LUSHAPI void Fsplinit(int size, flt *parm);
LUSHAPI flt Fspline(flt x, int size, flt *parm);
LUSHAPI flt Fdspline(flt x, int size, flt *parm);

/* Random functions */
LUSHAPI flt Frand(void);
LUSHAPI flt Fgauss(void);
LUSHAPI void Fseed(int x);

/* Rational approximation of TANH, SIGMOIDS */
/* Declarations for EXP(-|X|), EXP(-X2)     */
LUSHAPI real DQtanh(real x);
LUSHAPI real DQDtanh(real x);
LUSHAPI real DQstdsigmoid(real x);
LUSHAPI real DQDstdsigmoid(real x);
LUSHAPI real DQexpmx(real x);
LUSHAPI real DQDexpmx(real x);
LUSHAPI real DQexpmx2(real x);
LUSHAPI real DQDexpmx2(real x);

/* Spline interpolation */
LUSHAPI void Dsplinit(int size, real *parm);
LUSHAPI real Dspline(real x, int size, real *parm);
LUSHAPI real Ddspline(real x, int size, real *parm);

/* Random functions */
LUSHAPI real Drand(void);
LUSHAPI real Dgauss(void);
LUSHAPI void Dseed(int x);

/* ------------------------------------------------------- */

#ifdef __cplusplus
}
#else
# define HAVE_COMPLEXREAL
# ifdef HAVE_COMPLEX
#  include <complex.h>
typedef complex double complexreal;
extern LUSHAPI complexreal Ci;
LUSHAPI real Carg(complexreal z);
LUSHAPI real Cabs(complexreal z);
#  define Creal(z)  (creal(z))
#  define Cimag(z)  (cimag(z))
#  define Cnew(r,i) ((r)+Ci*(i))
#  define Cadd(x,y) ((x)+(y))
#  define Csub(x,y) ((x)-(y))
#  define Cmul(x,y) ((x)*(y))
#  define Cdiv(x,y) ((x)/(y))
#  define Cconj(z)  (conj(z))
# else  /* HAVE_COMPLEX */
struct complexreal_s { double r,i; };
typedef struct complexreal_s complexreal;
extern LUSHAPI complexreal Ci;
LUSHAPI real Carg(complexreal z);
LUSHAPI real Cabs(complexreal z);
#  define Creal(z)  ((z).r)
#  define Cimag(z)  ((z).i)
LUSHAPI complexreal Cnew(real, real);
LUSHAPI complexreal Cadd(complexreal, complexreal);
LUSHAPI complexreal Csub(complexreal, complexreal);
LUSHAPI complexreal Cmul(complexreal, complexreal);
LUSHAPI complexreal Cdiv(complexreal, complexreal);
LUSHAPI complexreal Cconj(complexreal z);
# endif  /* HAVE_COMPLEX */
#endif  /* __cplusplus */
#endif /* FLTLIB_H */