-
Notifications
You must be signed in to change notification settings - Fork 0
/
borland.c
43 lines (37 loc) · 948 Bytes
/
borland.c
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
#ifdef __BORLANDC__
#include<stdio.h>
#include<Windows.h>
#include "./include/borland.h"
int fopen_s(FILE** pFile, const char *filename, const char *mode) {
*pFile = fopen(filename, mode);
if(*pFile == NULL) return -1;
return 0;
}
int localtime_s(struct tm* const tmDest, time_t const* const sourceTime) {
*tmDest = *localtime(sourceTime);
return 0;
}
float roundf(float x) {
union {
float value;
uint32_t word;
} data;
int exponent;
data.value = x;
exponent = (int)((data.word & 0x7F800000) >> 23) - 127;
if(exponent < 23) {
if(exponent < 0) {
data.word &= 0x80000000;
if(exponent == -1) data.word |= 127 << 23;
} else {
uint32_t exponent_mask = 0x007FFFFF >> exponent;
if((data.word & exponent_mask) == 0) return data.value;
data.word += 0x00400000 >> exponent;
data.word &= ~exponent_mask;
}
} else {
return data.value;
}
return data.value;
}
#endif