forked from mosamosa/GSD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.cpp
70 lines (53 loc) · 1.26 KB
/
tools.cpp
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
65
66
67
68
69
70
/*
* GSD
*
* Copyright (C) 2008 mosa Ÿe5bW6vDOJ. <[email protected]>
*
* This is free software with ABSOLUTELY NO WARRANTY.
*
* You can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License.
*
*/
#include <windows.h>
#include <stdio.h>
#include <math.h>
#include "tools.h"
#define BUFLEN 512
//-----------------------------------------------------------------------------
int dprintf(const char *format, ...)
{
va_list ap;
char buffer[BUFLEN];
int iret;
va_start(ap, format);
iret = vsprintf(buffer, format, ap);
va_end(ap);
OutputDebugString(buffer);
return iret;
}
//-----------------------------------------------------------------------------
double pc2time(__int64 t)
{
static __int64 freq = 1;
if(freq == 1)
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
if(freq > 0)
return ((double)t / (double)freq);
else
return 0.0;
}
//-----------------------------------------------------------------------------
double round(double n)
{
int i;
bool plus = n > 0.0;
n = fabs(n);
i = (int)n;
n -= (double)i;
if(n >= 0.5)
return plus ? (double)(i+1) : -(double)(i+1);
else
return plus ? (double)i : -(double)i;
}
//-----------------------------------------------------------------------------