1
/***********************************************************************
4
* Created: December 21, 2004
5
* Author: Ivan Vilata i Balaguer - reverse:com.carabos@ivilata
7
* Function inlining and some castings for 64-bit adressing
8
* Francesc Altet 2004-12-27
10
* $Source: /cvsroot/pytables/pytables/src/typeconv.c,v $
11
* $Id: typeconv.c 1009 2005-06-15 13:39:15Z faltet $
13
***********************************************************************/
15
/* Type conversion functions for PyTables types which are stored
16
* with a different representation between Numarray and HDF5.
24
#if (!defined _ISOC99_SOURCE && !defined __USE_ISOC99)
25
long int lround(double x)
39
return (long int)(trunx);
41
#endif /* !_ISOC99_SOURCE && !__USE_ISOC99 */
44
void conv_float64_timeval32(void *base,
45
unsigned long byteoffset,
46
unsigned long bytestride,
47
PY_LONG_LONG nrecords,
48
unsigned long nelements,
52
unsigned long element, gapsize;
59
assert(bytestride > 0);
60
assert(nelements > 0);
62
/* Byte distance from end of field to beginning of next field. */
63
gapsize = bytestride - nelements * sizeof(double);
65
fieldbase = (double *)((unsigned char *)(base) + byteoffset);
67
for (record = 0; record < nrecords; record++) {
68
for (element = 0; element < nelements; element++) {
70
/* Convert from float64 to timeval32. */
71
tv.i64 = (((PY_LONG_LONG)(*fieldbase) << 32)
72
| (lround((*fieldbase - (int)(*fieldbase)) * 1e+6)
76
/* Convert from timeval32 to float64. */
78
/* the next computation is 64 bit-platforms aware */
79
*fieldbase = 1e-6 * (int)tv.i64 + (tv.i64 >> 32);
84
fieldbase = (double *)((unsigned char *)(fieldbase) + gapsize);
86
/* XXX: Need to check if this works on platforms which require
87
64-bit data to be aligned. ivb(2005-01-07) */
90
assert(fieldbase == (base + byteoffset + bytestride * nrecords));