EAPI int eina_convert_itoa(int n, char *s) EINA_ARG_NONNULL(2);
EAPI int eina_convert_xtoa(unsigned int n, char *s) EINA_ARG_NONNULL(2);
+
EAPI int eina_convert_dtoa(double d, char *des) EINA_ARG_NONNULL(2);
EAPI Eina_Bool eina_convert_atod(const char *src, int length, long long *m, long *e) EINA_ARG_NONNULL(1,3,4);
+
EAPI int eina_convert_fptoa(Eina_F32p32 fp, char *des) EINA_ARG_NONNULL(2);
+EAPI Eina_Bool eina_convert_atofp(const char *src, int length, Eina_F32p32 *fp) EINA_ARG_NONNULL(1,3);
/**
* @}
}
}
-static inline Eina_F32p32 eina_f32p32_mul2(Eina_F32p32 fp)
-{
- int64_t low;
- int64_t high;
-
- low = (fp & 0x00000000ffffffffLL) << 1;
- high = (fp >> 32) << 33;
-
- return low + high;
-}
-
-static inline Eina_F32p32 eina_f32p32_mul16(Eina_F32p32 fp)
-{
- int64_t low;
- int64_t high;
-
- low = (fp & 0x00000000ffffffffLL) << 4;
- high = (fp >> 32) << 36;
-
- return low + high;
-}
-
/**
* @endcond
*/
return length + eina_convert_itoa(p, des);
}
+EAPI Eina_Bool
+eina_convert_atofp(const char *src, int length, Eina_F32p32 *fp)
+{
+ long long m;
+ long e;
+
+ if (!eina_convert_atod(src, length, &m, &e))
+ return EINA_FALSE;
+
+ if (fp)
+ {
+ e += 32;
+
+ if (e > 0) *fp = m << e;
+ else *fp = m >> e;
+ }
+
+ return EINA_TRUE;
+}
+
/**
* @}
*/
{
char tmp1[128];
char tmp2[128];
+ Eina_F32p32 fpc;
+ double fpd;
int l1;
int l2;
l1 = eina_convert_dtoa(d, tmp1);
l2 = eina_convert_fptoa(fp, tmp2);
+/* fprintf(stderr, "[%s](%i) vs [%s](%i)\n", tmp1, l1, tmp2, l2); */
fail_if(l1 != l2);
fail_if(length != l1);
fail_if(strcmp(tmp1, tmp2) != 0);
+ fail_if(!eina_convert_atofp(tmp2, l2, &fpc));
+/* fprintf(stderr, "%016x vs %016x\n", fpc, fp); */
+ fail_if(fpc != fp);
+
+ fail_if(!eina_convert_atofp(tmp1, l1, &fpc));
+ fpd = eina_f32p32_double_to(fpc);
+/* fprintf(stderr, "%0.16f vs %0.16f\n", fpd, d); */
+ fail_if(fabs(fpd - d) > DBL_MIN);
+
d = -d;
fp = -fp;
fail_if(l1 != l2);
fail_if(length + 1 != l1);
fail_if(strcmp(tmp1, tmp2) != 0);
+
+ fail_if(!eina_convert_atofp(tmp2, l2, &fpc));
+/* fprintf(stderr, "%016x vs %016x\n", fpc, fp); */
+ fail_if(fpc != fp);
+
+ fail_if(!eina_convert_atofp(tmp1, l1, &fpc));
+ fpd = eina_f32p32_double_to(fpc);
+/* fprintf(stderr, "%0.16f vs %0.16f\n", fpd, d); */
+ fail_if(fabs(fpd - d) > DBL_MIN);
}
START_TEST(eina_convert_fp)