5 static bool PtexHalfInit(uint32_t* h2fTable, uint16_t* f2hTable)
7 union {
int i;
float f; } u;
9 for (
int h = 0; h < 65536; h++) {
10 int s = (h & 0x8000)<<16;
14 if (
unsigned(e-1) < ((31<<10)-1)) {
16 u.i = s|(((e+0x1c000)|m)<<13);
20 if (!(h&0x8000)) u.f =
float(5.9604644775390625e-08*m);
21 else u.f = float(-5.9604644775390625e-08*m);
25 u.i = s|0x7f800000|(m<<13);
30 for (
int i = 0; i < 512; i++) {
32 int e = (f & 0x7f800000) - 0x38000000;
34 if (
unsigned(e-1) < ((31<<23)-1)) {
35 int s = ((f>>16) & 0x8000);
38 f2hTable[i] = (uint16_t)((s|((e|m)>>13))+((f>>12)&1));
48 FILE* fp = fopen(
"PtexHalfTables.h",
"w");
50 perror(
"Can't write PtexHalfTable.h");
53 uint32_t h2fTable[65536];
54 uint16_t f2hTable[512];
56 fprintf(fp,
"PTEXAPI uint32_t PtexHalf::h2fTable[65536] = {");
57 for (
int i = 0; i < 65536; i++) {
58 if (i % 8 == 0) fprintf(fp,
"\n");
59 fprintf(fp,
" 0x%08x", h2fTable[i]);
60 if (i != 65535) fprintf(fp,
",");
62 fprintf(fp,
"\n};\n");
63 fprintf(fp,
"PTEXAPI uint16_t PtexHalf::f2hTable[512] = {");
64 for (
int i = 0; i < 512; i++) {
65 if (i % 8 == 0) fprintf(fp,
"\n");
66 fprintf(fp,
" 0x%04x", f2hTable[i]);
67 if (i != 511) fprintf(fp,
",");
69 fprintf(fp,
"\n};\n");