- /* mathtp.h by K.Tsuru */
- /********************************
- Mathematical template functions
- include non ANSI functions.
- *********************************/
- #ifndef MATH_TEMPLATE_H
- #define MATH_TEMPLATE_H
- #include <iostream> // added since ver 2.21
- #include <algorithm> // for min() and max() since ver 2.19
- using namespace std; // ver. 2.19
-
- /**************************************************
- It returns 10^n by long, defined in "ipow10.cpp"
- If n < 0, it returns 0.
- It does not check that 10^n < LONG_MAX.
- ***************************************************/
- long ipow10(int n);
-
- /**************************************************
- 10^n double version defined in "dpow10.cpp"
- 'n' can be negative.
- [notice] "pow(10.0, 2)" returns 99.999999.... , then
- int k = pow(10.0,2); you get k=99.
- ***************************************************/
- double dpow10(const int n);
-
- // difference |a-b|
- template <class Type> inline Type diff(Type a, Type b){
- return (a > b) ? (a - b) : (b - a);
- }
- // sign of a, when a == 0 return zero.
- template <class Type> inline int Sgn(Type a){
- if(a != 0) return ( a > 0 ) ? 1 : -1;
- return 0;
- }
-
- // It returns "true" if x and y have same sign.
- template <class Type> inline bool sameSign(Type x, Type y){ // ver 2.17
- return (x > 0) == (y > 0);
- }
-
- // return the figures of n. n must have integer type.
- template <class Type> int iFigures(Type n){
- int f = 0;
- while(n){
- n /= (Type)10;
- f++;
- }
- return f;
- }
- // "n" is 2^n ? since ver.2.18
- template <class Type> inline bool isPow2(Type n){
- return (n > 0) && ( (n & (n - 1)) == 0 );
- }
-
- // return ceil(u/v)
- template <class Type> inline Type ceil(Type u, Type v){
- Type n = u/v;
- if(u % v) n++;
- return n;
- }
- /*******************
- usable for SLong, SDouble class
- usage : cin >> a; ( s = cin )
- ********************/
- template <class Type> inline istream& operator>>(istream& s, Type& a) // added since version 2.21
- {
- string buf;
- std::getline(s, buf);
- a = buf.data();
- return s;
- }
- #endif // MATH_TEMPLATE_H
mathtp.h : last modifiled at 2017/02/16 21:48:49(2,059 bytes)
created at 2016/04/11 11:18:59
The creation time of this html file is 2017/10/11 16:07:52 (Wed Oct 11 16:07:52 2017).