This repository was archived by the owner on Mar 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathwin_funcs.h
More file actions
64 lines (57 loc) · 2.2 KB
/
win_funcs.h
File metadata and controls
64 lines (57 loc) · 2.2 KB
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
#ifndef __WIN_FUNCS_H
#define __WIN_FUNCS_H 1
#define _USE_MATH_DEFINES
#include <math.h>
#include <winsock.h>
#include <sys/timeb.h>
#define ROUND_FUNC(type,suff) inline type round##suff(type x) \
{ \
if (x >= 0.0##suff){ \
type y = floor##suff(x); \
if (x - y >= 0.5##suff) \
y += 1.0##suff; \
return y; \
}else{ \
type y = ceil##suff(x); \
if (y - x >= 0.5##suff) \
y -= 1.0##suff; \
return y; \
} \
}
ROUND_FUNC(float,f)
ROUND_FUNC(double,)
inline void gettimeofday(struct timeval* t,void* timezone)
{ struct _timeb timebuffer;
_ftime( &timebuffer );
t->tv_sec=timebuffer.time;
t->tv_usec=1000*timebuffer.millitm;
}
inline double rint( double x)
// Copyright (C) 2001 Tor M. Aamodt, University of Toronto
// Permisssion to use for all purposes commercial and otherwise granted.
// THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY, OR ANY CONDITION OR
// OTHER TERM OF ANY KIND INCLUDING, WITHOUT LIMITATION, ANY WARRANTY
// OF MERCHANTABILITY, SATISFACTORY QUALITY, OR FITNESS FOR A PARTICULAR
// PURPOSE.
{
if( x > 0 ) {
__int64 xint = (__int64) (x+0.5);
if( xint % 2 ) {
// then we might have an even number...
double diff = x - (double)xint;
if( diff == -0.5 )
return double(xint-1);
}
return double(xint);
} else {
__int64 xint = (__int64) (x-0.5);
if( xint % 2 ) {
// then we might have an even number...
double diff = x - (double)xint;
if( diff == 0.5 )
return double(xint+1);
}
return double(xint);
}
}
#endif /* __WIN_FUNCS_H */