|
|||||||||||
Technical Support Support Resources
Product Information |
GENERAL: Pow Function Precision ProblemsInformation in this article applies to:
QUESTIONI'm using the pow function in my program and I have serious problems with it. For example, the following code generates incorrect results:
Is this a problem with my code or a problem with the pow function? ANSWERThere is no problem with the pow function. The problem is that the pow function accepts and returns floating-point numbers (which have a maximum precision of 7 decimal digits). The exp and log functions are used by pow for its calculations. Therefore, there is an additional loss of precision which yields the results you get. Another effect is that float to long conversions are rounded-down. This is an ANSI requirement. RESOLUTIONIf you use the C166 or C251 compiler you can solve this issue by using the double arithmetic library. If you use the C51 compiler or do not wish to use the double-precision arithmetic, you may rewrite your code as shown below to add +0.5 before the long conversion. This will give the results you expect.
If the arguments to the pow function are integers, you may consider using a series of multiplications instead. SEE ALSO
Last Reviewed: Thursday, February 25, 2021 | ||||||||||
|
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.