sunrain_hjb的BLOG
Develop Helpful and Effective apps to make Jobs easier and Better!
ADL User Guide for Open AT. OS v6.1

    今天在调试程序时,发现了ARM-GCCsprintf()的一个问题,它不支持浮点数。以前从来没碰到这个问题,而且认为这肯定不会有问题,折腾了半天,最后在ADL_User_Guide中找到了答案。ARM-GCC下的sprintf()确实不支持%f,文档中给出了相应的解决方法。

     Important remark about GCC compiler:

When using GCC compiler, due to internal standard C library architecture, it is strongly not recommended to use the "%f" mode in the wm_sprintf function in order to convert a float variable to a string. This leads to an ARM exception (product reset).

A way around for this conversion is:

float MyFloat; // float to display

ascii MyString [ 100 ]; // destination string

s16 d,f;

d = (s16) MyFloat * 1000; // Decimal precision: 3 digits

f = ( MyFLoat * 1000 ) - d; // Decimal precision: 3 digits

                  wm_sprintf ( MyString, "%d.%03d", (s16)MyFloat, f ); // Decimal precision: 3 digits

    实践证明,经验主义要不得,看文档很重要,而且要看仔细。

posted on 2009-02-21 22:13  sunrain_hjb  阅读(2998)  评论(2编辑  收藏  举报

Map