Use a simple implementation instead, this is not performance critical.
Török Edvin authored on 2010/05/14 17:09:16... | ... |
@@ -932,6 +932,13 @@ int32_t cli_bcapi_jsnorm_done(struct cli_bc_ctx *ctx , int32_t id) |
932 | 932 |
return 0; |
933 | 933 |
} |
934 | 934 |
|
935 |
+static inline double myround(double a) |
|
936 |
+{ |
|
937 |
+ if (a < 0) |
|
938 |
+ return a-0.5; |
|
939 |
+ return a+0.5; |
|
940 |
+} |
|
941 |
+ |
|
935 | 942 |
int32_t cli_bcapi_ilog2(struct cli_bc_ctx *ctx, uint32_t a, uint32_t b) |
936 | 943 |
{ |
937 | 944 |
double f; |
... | ... |
@@ -939,14 +946,14 @@ int32_t cli_bcapi_ilog2(struct cli_bc_ctx *ctx, uint32_t a, uint32_t b) |
939 | 939 |
return 0x7fffffff; |
940 | 940 |
/* log(a/b) is -32..32, so 2^26*32=2^31 covers the entire range of int32 */ |
941 | 941 |
f = (1<<26)*log((double)a / b) / log(2); |
942 |
- return (int32_t)round(f); |
|
942 |
+ return (int32_t)myround(f); |
|
943 | 943 |
} |
944 | 944 |
|
945 | 945 |
int32_t cli_bcapi_ipow(struct cli_bc_ctx *ctx, int32_t a, int32_t b, int32_t c) |
946 | 946 |
{ |
947 | 947 |
if (!a && b < 0) |
948 | 948 |
return 0x7fffffff; |
949 |
- return (int32_t)round(c*pow(a,b)); |
|
949 |
+ return (int32_t)myround(c*pow(a,b)); |
|
950 | 950 |
} |
951 | 951 |
|
952 | 952 |
uint32_t cli_bcapi_iexp(struct cli_bc_ctx *ctx, int32_t a, int32_t b, int32_t c) |
... | ... |
@@ -955,7 +962,7 @@ uint32_t cli_bcapi_iexp(struct cli_bc_ctx *ctx, int32_t a, int32_t b, int32_t c) |
955 | 955 |
if (!b) |
956 | 956 |
return 0x7fffffff; |
957 | 957 |
f= c*exp((double)a/b); |
958 |
- return (uint32_t)round(f); |
|
958 |
+ return (uint32_t)myround(f); |
|
959 | 959 |
} |
960 | 960 |
|
961 | 961 |
int32_t cli_bcapi_isin(struct cli_bc_ctx *ctx, int32_t a, int32_t b, int32_t c) |
... | ... |
@@ -964,7 +971,7 @@ int32_t cli_bcapi_isin(struct cli_bc_ctx *ctx, int32_t a, int32_t b, int32_t c) |
964 | 964 |
if (!b) |
965 | 965 |
return 0x7fffffff; |
966 | 966 |
f = c*sin((double)a/b); |
967 |
- return (int32_t)round(f); |
|
967 |
+ return (int32_t)myround(f); |
|
968 | 968 |
} |
969 | 969 |
|
970 | 970 |
int32_t cli_bcapi_icos(struct cli_bc_ctx *ctx, int32_t a, int32_t b, int32_t c) |
... | ... |
@@ -973,7 +980,7 @@ int32_t cli_bcapi_icos(struct cli_bc_ctx *ctx, int32_t a, int32_t b, int32_t c) |
973 | 973 |
if (!b) |
974 | 974 |
return 0x7fffffff; |
975 | 975 |
f = c*cos((double)a/b); |
976 |
- return (int32_t)round(f); |
|
976 |
+ return (int32_t)myround(f); |
|
977 | 977 |
} |
978 | 978 |
|
979 | 979 |
int32_t cli_bcapi_memstr(struct cli_bc_ctx *ctx, const uint8_t* h, int32_t hs, |