float *avaliarPop(int **pop, int size, int genes, double a, double b) { int i; float *v; v = (float*) malloc(size * sizeof (float)); //printf("\n Calculando Valores da FO:"); for (i = 0; i < size; i++) { if (bitsToFloat(pop[i]) < a) { pop[i] = floatToBits(a - bitsToFloat(pop[i])); } if (bitsToFloat(pop[i]) > b) { pop[i] = floatToBits(bitsToFloat(pop[i]) - b); } v[i] = fo_01(bitsToFloat(pop[i])); } /* printf("\n Vetor de valores da fo:\n"); for (i = 0; i < size; i++) { printf("\ny = %.3f", v[i]); } */ return v; }
int excheck(uint32_t val) { float f = bitsToFloat(val); int i = f2h(f); float f2 = h2f(i); if (memcmp(&f, &f2, 4)) { printf("error: %g(0x%0x)->0x%x->%g(0x%0x)\n", f, floatToBits(f), i, f2, floatToBits(f2)); return 1; } return 0; }
void printfloat(float f) { int32_t t = floatToBits(f); printbits(t, 31, 31); printbits(t, 30, 23); printbits(t, 22, 0); }
int testroundrange(int inc) { int count = 0; // check all legal float32 values within legal float16 range float f1 = 2.9802320611338473e-08; // min float16 float f2 = 65519; // max float 16 unsigned int i1 = floatToBits(f1); unsigned int i2 = floatToBits(f2); for (unsigned int i = i1; i < i2; i+=inc) count += testround(bitsToFloat(i)); // and the negatives f1 = -2.9802320611338473e-08; // min float16 f2 = -65519; // max float 16 i1 = floatToBits(f1); i2 = floatToBits(f2); for (unsigned int i = i1; i < i2; i+=inc) count += testround(bitsToFloat(i)); return count; }
void printall() { for (int i = 0; i < 65536; i++) { float f = h2f(i); printf("0x%x -> %g 0x%x\n", i, f, floatToBits(f)); } for (int e = -10; e < 10; e++) { double f = pow(10.0, e); int i = f2h(f); printf("%g -> 0x%x ->%g\n", f, i, h2f(i)); } }
int overflowtest(float f) { uint32_t fi = floatToBits(f); int i = f2h(f); int e = 0x7c00 | ((fi>>16)&0x8000); if (i != e) { printf("error: %g->0x%x->%g, expected 0x%x->%sinf\n", f, i, h2f(i), e, (e&0x8000) ? "-" : ""); return 1; } return 0; }
float frexp(float _a, int32_t* _outExp) { const uint32_t ftob = floatToBits(_a); const uint32_t masked0 = uint32_and(ftob, UINT32_C(0x7f800000) ); const uint32_t exp0 = uint32_srl(masked0, 23); const uint32_t masked1 = uint32_and(ftob, UINT32_C(0x807fffff) ); const uint32_t bits = uint32_or(masked1, UINT32_C(0x3f000000) ); const float result = bitsToFloat(bits); *_outExp = int32_t(exp0 - 0x7e); return result; }
BX_CONST_FUNC float ldexp(float _a, int32_t _b) { const uint32_t ftob = floatToBits(_a); const uint32_t masked = uint32_and(ftob, UINT32_C(0xff800000) ); const uint32_t expsign0 = uint32_sra(masked, 23); const uint32_t tmp = uint32_iadd(expsign0, _b); const uint32_t expsign1 = uint32_sll(tmp, 23); const uint32_t mantissa = uint32_and(ftob, UINT32_C(0x007fffff) ); const uint32_t bits = uint32_or(mantissa, expsign1); const float result = bitsToFloat(bits); return result; }
void testeCadBits() { //Teste função para converter de valor numérico para vetor binário // Todos os possíveis valores do espaço de busca convertidos para binário // Espaço de busca de -2.048: 0.001 : 2.048 int *cr, i, *cd; float j, n; printf("VALORES DE X|\t\t\tCADEIA DE BITS (CROMOSSOMOS)\t\t| F(x)= x*sin(10*pi*x)+1"); for (j = -2.048; j <= 2.048; j += 0.001) { cr = floatToBits(j); printf("\n x= %.3f | floatToBits(x): ", j); for (i = 0; i <= 11; i++) { printf("%d", cr[i]); } n = bitsToFloat(cr); printf(" >> bitToFloat(*bits): %.3f ", n); //aplicando a função objetivo printf("| y = %.3f", fo_01(j)); } printf("\n\n"); }
template <> inline U32 hash<Vec4f> (const Vec4f& value) { return hashBits(floatToBits(value.x), floatToBits(value.y), floatToBits(value.z), floatToBits(value.w)); }
template <> inline U32 hash<F32> (const F32& value) { return hashBits(floatToBits(value)); }
template <> inline bool equals<F32> (const F32& a, const F32& b) { return (floatToBits(a) == floatToBits(b)); }
U32 computeHash() const { return hashBits(hash<String>(m_name), floatToBits(m_SAHNodeCost), floatToBits(m_SAHTriangleCost), hashBits(m_triBatchSize, m_nodeBatchSize, m_minLeafSize, m_maxLeafSize)); }