#include <math.h>
#include <stdio.h>
float sin_0(float x)
{
}
float cos_0(float x)
{
}
float cosm1_0(float x)
{
}
float sinf_trad(float x)
{
float h = x - 0x1.2660bcp-6f;
return 0x1.265caep-6f * cos_0(h) + 0x1.ffead8p-1f * sin_0(h);
}
float sinf_new(float x)
{
float h = x - 0x1.2660bcp-6f;
return 0x1.265caep-6f + (0x1.265caep-6f * cosm1_0(h) + 0x1.ffead8p-1f * sin_0(h));
}
double m_err_trad, s_err_trad;
double m_err_new, s_err_new;
int main(){
for (float f = 0.01f; f <= 0.025f; f = nextafterf(f, 3.0f))
{
float trad = sinf_trad(f);
float new = sinf_new(f);
double err_trad
= fabs(r
- trad
); double err_new
= fabs(r
- new
); s_err_trad += err_trad * err_trad;
s_err_new += err_new * err_new;
err_trad /= r;
err_new /= r;
if (err_trad > m_err_trad) m_err_trad = err_trad;
if (err_new > m_err_new) m_err_new = err_new;
}
printf("relative error, traditional: %e, new: %e\n", m_err_trad
, m_err_new
); printf("sum of squares of absolute error, traditional: %e, new: %e\n", s_err_trad
, s_err_new
); }
I2luY2x1ZGUgPG1hdGguaD4KI2luY2x1ZGUgPHN0ZGlvLmg+CgpmbG9hdCBzaW5fMChmbG9hdCB4KQp7CiAgcmV0dXJuIHNpbih4KTsKfQoKZmxvYXQgY29zXzAoZmxvYXQgeCkKewogIHJldHVybiBjb3MoeCk7Cn0KCmZsb2F0IGNvc20xXzAoZmxvYXQgeCkKewogIHJldHVybiBjb3MoeCktMS4wOwp9CgpmbG9hdCBzaW5mX3RyYWQoZmxvYXQgeCkKewogIGZsb2F0IGggPSB4IC0gMHgxLjI2NjBiY3AtNmY7CiAgCiAgcmV0dXJuIDB4MS4yNjVjYWVwLTZmICogY29zXzAoaCkgKyAweDEuZmZlYWQ4cC0xZiAqIHNpbl8wKGgpOwp9CgpmbG9hdCBzaW5mX25ldyhmbG9hdCB4KQp7CiAgZmxvYXQgaCA9IHggLSAweDEuMjY2MGJjcC02ZjsKICAKICByZXR1cm4gMH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