STK++ 0.9.13
STK_Misc.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff, Université Lille 1, Inria
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23*/
24
25/*
26 * Project: Base
27 * Purpose: Define miscenaleous utility functions.
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 *
30 **/
31
37#ifndef STK_MISC_H
38#define STK_MISC_H
39
40#include <cmath> // for sqrt
41#include <cstdlib> // for rand
42
43namespace STK
44{
52template<typename Type>
53inline Type sign(Type const& x, Type const& y = Type(1))
54{ return( (x<0) ? -y : y); }
55
61inline Real frand()
62{ return (Real)rand() / (RAND_MAX+1.0);}
63
72inline bool isOdd(int const& x)
73{ return( (x%2) == 1 ); }
74
83inline bool isEven(int const& x)
84{ return( (x%2) == 0 ); }
85
93inline Real norm(Real const& x, Real const& y)
94{
95 Real absx = std::abs(x), absy = std::abs(y);
96 return (absx > absy) ?
97 (absx * std::sqrt(Real(1.0+(absy/absx)*(absy/absx))))
98 : (absy == 0.0 ? 0.0 : absy * std::sqrt(Real(1.0+(absx/absy)*(absx/absy))));
99}
100
101} // namespace STK
102
103#endif /* STK_MISC_H */
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
bool isEven(int const &x)
is x an even number ?
Definition STK_Misc.h:83
bool isOdd(int const &x)
is x a odd number ?
Definition STK_Misc.h:72
Type sign(Type const &x, Type const &y=Type(1))
template sign value sign(x) * y: Type should be an integral type
Definition STK_Misc.h:53
Real frand()
frand() generate a Real uniform number.
Definition STK_Misc.h:61
Real norm(Real const &x, Real const &y)
Computation of sqrt(x^2 + y^2) without underflow or overflow.
Definition STK_Misc.h:93
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.