42 #if BINIO_ENABLE_STRING 44 #define STRINGBUFSIZE 256 61 if (endian_test.byte != 1) f |=
BigEndian;
67 if (
sizeof(
float) == 4 &&
sizeof(double) == 8) {
69 if (dat[0] == 0x40 && dat[1] == 0xD0 && !dat[2] && !dat[3])
72 if (dat[3] == 0x40 && dat[2] == 0xD0 && !dat[1] && !dat[0])
113 if (size >
sizeof(
Int)) {
116 "The size of the integer to be read exceeds our system's biggest type");
120 for (i = 0; i < size; i++) {
137 unsigned int size = 0;
157 if (!swap && ((size ==
sizeof(
float)) || (size ==
sizeof(
double)))) {
160 getRaw((
char *)&f, size);
164 getRaw((
char *)&d, size);
169 for (i = 0; i < size; i++)
171 in[size - i - 1] = getByte();
181 return *(
double *)in;
186 return ieee_single2float(in);
188 return ieee_double2float(in);
200 signed int sign = data[0] >> 7 ? -1 : 1;
201 unsigned int exp = ((data[0] << 1) & 0xff) | ((data[1] >> 7) & 1),
202 fracthi7 = data[1] & 0x7f;
203 Float fract = fracthi7 * 65536.0 + data[2] * 256.0 + data[3];
206 if (!exp && !fracthi7 && !data[2] && !data[3])
return sign * 0.0;
210 if (!fracthi7 && !data[2] && !data[3]) {
234 return sign *
pow(2, -126.) * fract *
pow(2, -23.);
236 return sign *
pow(2, exp - 127.) * (fract *
pow(2, -23.) + 1);
243 signed int sign = data[0] >> 7 ? -1 : 1;
244 unsigned int exp = ((
unsigned int)(data[0] & 0x7f) << 4) | (data[1] >> 4),
245 fracthi4 = data[1] & 0xf;
246 Float fract = fracthi4 *
pow(2, 48.) + data[2] *
pow(2, 40.) +
247 data[3] *
pow(2, 32.) + data[4] *
pow(2, 24.) +
248 data[5] *
pow(2, 16.) + data[6] *
pow(2, 8.) + data[7];
251 if (!exp && !fracthi4 && !data[2] && !data[3] && !data[4] && !data[5] &&
252 !data[6] && !data[7])
257 if (!fracthi4 && !data[2] && !data[3] && !data[4] && !data[5] && !data[6] &&
282 return sign *
pow(2, -1022.) * fract *
pow(2, -52.);
284 return sign *
pow(2, exp - 1023.) * (fract *
pow(2, -52.) + 1);
300 if (!exp)
return 1.0;
302 for (i = 1; i < (exp < 0 ? -exp : exp); i++) val *= base;
304 if (exp < 0) val = 1.0 / val;
313 for (i = 0; i < maxlen; i++) {
314 str[
i] = (char)getByte();
325 unsigned long maxlen,
329 for (i = 0; i < maxlen; i++) {
330 str[
i] = (char)getByte();
331 if (str[i] == delim ||
err) {
341 #if BINIO_ENABLE_STRING 349 tempstr.append(buf, read);
357 Int val = readInt(size);
363 Float val = readFloat(ft);
365 if (!
err)
switch (ft) {
390 for (i = 0; i < amount; i++) getByte();
403 if (size >
sizeof(
Int)) {
406 "The size of the integer to be stored exceeds our system's biggest type");
410 for (i = 0; i < size; i++) {
412 putByte((
unsigned char)(val >> ((size - i - 1) * 8)) & 0xff);
414 putByte((
unsigned char)val & 0xff);
424 unsigned int size = 0;
430 float outf = (float)f;
431 double outd = (double)f;
445 if (!swap && ((size ==
sizeof(
float)) || (size ==
sizeof(
double)))) {
447 putRaw((
char *)&outf, size);
450 putRaw((
char *)&outd, size);
477 float2ieee_single(f, buf);
481 float2ieee_double(f, buf);
494 if (swap) out += size - 1;
495 for (i = 0; i < size; i++) {
510 #ifdef BINIO_WITH_MATH 541 #define FloatToUnsigned(f) ((unsigned long)(f)) 543 #define FloatToUnsigned(f) \ 544 ((unsigned long)(((long)((f)-2147483648.0)) + 2147483647L + 1)) 548 #define SEXP_OFFSET 127 550 #define SEXP_POSITION (32 - SEXP_SIZE - 1) 569 fMant = frexp(num, &expon);
573 bits = sign | 0x7F800000;
584 mantissa = (long)(fMant * (
double)(1L << shift));
585 bits = sign | mantissa;
598 bytes[0] = (
unsigned char)(bits >> 24);
599 bytes[1] = (
unsigned char)(bits >> 16);
600 bytes[2] = (
unsigned char)(bits >> 8);
601 bytes[3] = (
unsigned char)bits;
604 #define DEXP_MAX 2047 605 #define DEXP_OFFSET 1023 607 #define DEXP_POSITION (32 - DEXP_SIZE - 1) 627 fMant = frexp(num, &expon);
631 first = sign | 0x7FF00000;
649 fsMant = ldexp(fMant, shift);
650 mantissa = (long)floor(fsMant);
651 first = sign | mantissa;
658 mantissa = (long)floor(fsMant);
668 bytes[0] = (
unsigned char)(first >> 24);
669 bytes[1] = (
unsigned char)(first >> 16);
670 bytes[2] = (
unsigned char)(first >> 8);
671 bytes[3] = (
unsigned char)first;
672 bytes[4] = (
unsigned char)(second >> 24);
673 bytes[5] = (
unsigned char)(second >> 16);
674 bytes[6] = (
unsigned char)(second >> 8);
675 bytes[7] = (
unsigned char)second;
678 #endif // BINIO_WITH_MATH 683 if (!amount) amount = strlen(str);
685 for (i = 0; i < amount; i++) {
693 #if BINIO_ENABLE_STRING 695 return writeString(str.c_str());
void read(HitranRelaxationMatrixData &hitran, ArrayOfAbsorptionLines &bands, const String &basedir, const Numeric linemixinglimit, const Numeric fmin, const Numeric fmax, const Numeric stot, const ModeOfLineMixing mode)
Read from HITRAN online line mixing file.
Float ieee_single2float(Byte *data)
virtual void seek(long, Offset=Set)=0
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
unsigned long writeString(const char *str, unsigned long amount=0)
Numeric sign(const Numeric &x)
sign
void swap(ComplexVector &v1, ComplexVector &v2)
Swaps two objects.
Float readFloat(FType ft)
void float2ieee_single(Float f, Byte *data)
Float peekFloat(FType ft)
unsigned long readString(char *str, unsigned long amount)
Int readInt(unsigned int size)
static const Flags system_flags
void float2ieee_double(Float f, Byte *data)
Numeric pow(const Rational base, Numeric exp)
Power of.
void writeFloat(Float f, FType ft)
void writeInt(Int val, unsigned int size)
void ignore(unsigned long amount=1)
static Flags detect_system_flags()
#define FloatToUnsigned(f)
void setFlag(Flag f, bool set=true)
Float ieee_double2float(Byte *data)
Int peekInt(unsigned int size)