Hello, I wonder what's the best style today when writing a clipper function like this below. Thanks in advance And does is still make sense to use alternative sto std::powf() and C powf() for float^int?
// thisor this
Code:
//A float Clipping11(const float x) const { if (std::fabsf(x) < 1.0f) { return 1.1f * x - 0.1f * std::powf(x, 11.0f); } else { return -static_cast<float>(std::signbit(x)); } }
Code:
//B float Clipping11(const float x) { if (x >= -1.0f && x <= 1.0f) return 1.1f * x - 0.1f * std::powf(x, 11.0f); else return -static_cast<float>(std::signbit(x)); }
Code:
//C float Clipping11(const float x) { if (x < -1.0f) return -1.0f; else if (x > 1.0f) return 1.0f; else return 1.1f * x - 0.1f * powf(x, 11.0f); }
// this
Code:
float fastpow(float a, float b) // -2.0 ~ +2.0 approx { union { float f; uint32_t u; } temp{ 0.0f }; temp.f = a; temp.u = (uint32_t)(b * (float)(temp.u - 1064866808) + 1064866808); return temp.f; }
Code:
double my_pow(double x, size_t n) { double r = 1.0; while (n > 0) { r *= x; --n; } return r; }
Statistics: Posted by liqih — Sat Sep 14, 2024 3:40 pm — Replies 0 — Views 54