Go to the documentation of this file.
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)))) {
169 for (i = 0; i < size; i++)
181 return *(
double *)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;
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++) {
325 unsigned long maxlen,
329 for (i = 0; i < maxlen; i++) {
331 if (str[i] == delim ||
err) {
341 #if BINIO_ENABLE_STRING
349 tempstr.append(buf,
read);
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);
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
Float peekFloat(FType ft)
unsigned long readString(char *str, unsigned long amount)
void float2ieee_double(Float f, Byte *data)
#define FloatToUnsigned(f)
Numeric sign(const Numeric &x)
sign
void swap(ComplexVector &v1, ComplexVector &v2)
Swaps two objects.
void writeFloat(Float f, FType ft)
void writeInt(Int val, unsigned int size)
void ignore(unsigned long amount=1)
virtual void seek(long, Offset=Set)=0
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
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.
Numeric pow(const Rational base, Numeric exp)
Power of.
virtual void putByte(Byte)=0
Int peekInt(unsigned int size)
Float ieee_double2float(Byte *data)
static Flags detect_system_flags()
virtual void putRaw(const char *c, streamsize n)=0
static const Flags system_flags
Float ieee_single2float(Byte *data)
virtual void getRaw(char *c, streamsize n)=0
void setFlag(Flag f, bool set=true)
unsigned long writeString(const char *str, unsigned long amount=0)
Int readInt(unsigned int size)
Float readFloat(FType ft)
void float2ieee_single(Float f, Byte *data)