1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2013 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _Standard_Integer_HeaderFile
16 #define _Standard_Integer_HeaderFile
18 #include <Standard_TypeDef.hxx>
19 #include <Standard_values.h>
25 // ------------------------------------------------------------------
26 // Abs : Returns the absolute value of an Integer
27 // ------------------------------------------------------------------
28 inline Standard_Integer Abs (const Standard_Integer Value)
30 return Value >= 0 ? Value : -Value;
33 // ------------------------------------------------------------------
34 // Hascode : Computes a hascoding value for a given Integer
35 // ------------------------------------------------------------------
36 inline Standard_Integer HashCode (const Standard_Integer theMe,
37 const Standard_Integer theUpper)
39 //return (Abs (theMe) % theUpper) + 1;
40 return ((theMe & 0x7fffffff ) % theUpper) + 1;
43 // ------------------------------------------------------------------
44 // IsEqual : Returns Standard_True if two integers are equal
45 // ------------------------------------------------------------------
46 inline Standard_Boolean IsEqual (const Standard_Integer theOne,
47 const Standard_Integer theTwo)
49 return theOne == theTwo;
52 #if (defined(_LP64) || defined(__LP64__) || defined(_WIN64)) || defined(__APPLE__)
53 // ------------------------------------------------------------------
54 // Hascode : Computes a hascoding value for a given unsigned integer
55 // ------------------------------------------------------------------
56 inline Standard_Integer HashCode (const Standard_Utf32Char theMe,
57 const Standard_Integer theUpper)
59 return ((theMe & 0x7fffffff ) % theUpper) + 1;
62 // ------------------------------------------------------------------
63 // IsEqual : Returns Standard_True if two integers are equal
64 // ------------------------------------------------------------------
65 inline Standard_Boolean IsEqual (const Standard_Utf32Char theOne,
66 const Standard_Utf32Char theTwo)
68 return theOne == theTwo;
72 // ------------------------------------------------------------------
73 // IsEven : Returns Standard_True if an integer is even
74 // ------------------------------------------------------------------
75 inline Standard_Boolean IsEven (const Standard_Integer Value)
76 { return Value % 2 == 0; }
79 // ------------------------------------------------------------------
80 // IsOdd : Returns Standard_True if an integer is odd
81 // ------------------------------------------------------------------
82 inline Standard_Boolean IsOdd (const Standard_Integer Value)
83 { return Value % 2 == 1; }
85 // ------------------------------------------------------------------
86 // Max : Returns the maximum integer between two integers
87 // ------------------------------------------------------------------
88 inline Standard_Integer Max (const Standard_Integer Val1,
89 const Standard_Integer Val2)
91 return Val1 >= Val2 ? Val1 : Val2;
94 // ------------------------------------------------------------------
95 // Min : Returns the minimum integer between two integers
96 // ------------------------------------------------------------------
97 inline Standard_Integer Min (const Standard_Integer Val1,
98 const Standard_Integer Val2)
100 return Val1 <= Val2 ? Val1 : Val2;
103 // ------------------------------------------------------------------
104 // Modulus : Returns the remainder of division between two integers
105 // ------------------------------------------------------------------
106 inline Standard_Integer Modulus (const Standard_Integer Value,
107 const Standard_Integer Divisor)
108 { return Value % Divisor; }
110 // ------------------------------------------------------------------
111 // Square : Returns the square of an integer
112 // ------------------------------------------------------------------
113 inline Standard_Integer Square(const Standard_Integer Value)
114 { return Value * Value; }
116 // ------------------------------------------------------------------
117 // IntegerFirst : Returns the minimum value of an integer
118 // ------------------------------------------------------------------
119 inline Standard_Integer IntegerFirst()
122 // ------------------------------------------------------------------
123 // IntegerLast : Returns the maximum value of an integer
124 // ------------------------------------------------------------------
125 inline Standard_Integer IntegerLast()
128 // ------------------------------------------------------------------
129 // IntegerSize : Returns the size in digits of an integer
130 // ------------------------------------------------------------------
131 inline Standard_Integer IntegerSize()
132 { return BITS(Standard_Integer); }