I am designing a class of 144 bit floats, and I can't figure out how to create a constant with class scope.
Here is the relevant information:
and
If I replace // XXXX with
float144 ten1() { fl.f.exp=(0x400 2); fl.f.mant.d[N1of2]=0x400000000000 0000; fl.f.mant.d[N0of2]=0; return fl; }
I get something that can serve as a constant, but I don't like carrying around the parentheses. I want something like
static const float144 ten1 { ten1.f.exp=0x40 02; ten1.f.mant.d[N1of2]=0x400000000000 0000; ten1.f.mant.d[N0of2]=0; };
but after 2 days, I've been unable to find anything the gcc compiler will accept.
Here is the relevant information:
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <endian.h>
#include <stdint.h>
#if BYTE_ORDER == 1234
#define N0of2 0
#define N1of2 1
#elif BYTE_ORDER == 4321
#define N0of2 1
#define N1of2 0
#endif
union UINT128 {
uint64_t d[2];
uint32_t i[4];
uint16_t s[8];
uint8_t c[16];
} __attribute__((packed)) ;
Code:
struct F144S {
#if __FLOAT_WORD_ORDER==1234
UINT128 mant;
int16_t exp;
#elif __FLOAT_WORD_ORDER==4321
int16_t exp;
UINT128 mant;
#endif
} __attribute__((packed)) ;
#include <ctype.h>
class float144 {
public:
union f_144 {
uint8_t c[18];
uint16_t s[9];
struct F144S f; } fl;
float144() { }
float144(f_144 x) { fl=x; }
// XXXX
};
float144 ten1() { fl.f.exp=(0x400 2); fl.f.mant.d[N1of2]=0x400000000000 0000; fl.f.mant.d[N0of2]=0; return fl; }
I get something that can serve as a constant, but I don't like carrying around the parentheses. I want something like
static const float144 ten1 { ten1.f.exp=0x40 02; ten1.f.mant.d[N1of2]=0x400000000000 0000; ten1.f.mant.d[N0of2]=0; };
but after 2 days, I've been unable to find anything the gcc compiler will accept.
Comment