1 /*$Id: l_compar.h,v 26.98 2008/10/24 06:10:07 al Exp $ -*- C++ -*-
2  * Copyright (C) 2001 Albert Davis
3  * Author: Albert Davis <aldavis@gnu.org>
4  *
5  * This file is part of "Gnucap", the Gnu Circuit Analysis Package
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA.
21  */
22 //testing=script,complete 2006.07.13
23 #ifndef L_COMPAR_H
24 #define L_COMPAR_H
25 #include "md.h"
26 /*--------------------------------------------------------------------------*/
27 /* uporder: returns true if a,b,c are in non-decreasing order */
28 template <class T>
up_order(T a,T b,T c)29 inline bool up_order(T a, T b, T c)
30 {
31   return (a<=b) && (b<=c);
32 }
33 
34 /* inorder: returns true if b is between a and c */
35 template <class T>
in_order(T a,T b,T c)36 inline bool in_order(T a, T b, T c)
37 {
38   return up_order(a,b,c) || up_order(c,b,a);
39 }
40 
41 /* torange: returns b, clipped to range a..c */
42 template <class T>
to_range(T a,T b,T c)43 inline T to_range(T a, T b, T c)
44 {
45   return std::min(std::max(a,b),c);
46 }
47 /*--------------------------------------------------------------------------*/
48 /*--------------------------------------------------------------------------*/
49 #endif
50