shithub: femtolisp

ref: 362ffe51df8f1f4f8b3b9bff10c0def2d7aec9a0
dir: /ieee754.h/

View raw version
#pragma once

union ieee754_float {
	float f;

	struct {
#if BYTE_ORDER == BIG_ENDIAN
	unsigned int negative:1;
	unsigned int exponent:8;
	unsigned int mantissa:23;
#elif BYTE_ORDER == LITTLE_ENDIAN
	unsigned int mantissa:23;
	unsigned int exponent:8;
	unsigned int negative:1;
#else
#error which endian?
#endif
	}ieee;
};

#define IEEE754_FLOAT_BIAS 0x7f

union ieee754_double {
	double d;

	struct {
#if BYTE_ORDER == BIG_ENDIAN
	unsigned int negative:1;
	unsigned int exponent:11;
	unsigned int mantissa0:20;
	unsigned int mantissa1:32;
#else
	unsigned int mantissa1:32;
	unsigned int mantissa0:20;
	unsigned int exponent:11;
	unsigned int negative:1;
#endif
	}ieee;
};

#define IEEE754_DOUBLE_BIAS 0x3ff