printing the integral part of a floating point number

后端 未结 7 485
不知归路
不知归路 2021-01-13 23:03

I am trying to figure out how to print floating point numbers without using library functions. Printing the decimal part of a floating point number turned out to be quite ea

7条回答
  •  余生分开走
    2021-01-13 23:52

    It appears that the work horse for the float to string conversion is the dtoa() function. See dtoa.c in newlib for how they do it.

    Now, how does printf manage to print the correct result?

    I think it is close to magic. At least the source looks like some kind of dark incantation.

    Does it use some bigint facilities internally?

    Yes, search for _Bigint in the linked source file.

    Or is there some floating point trick I am missing?

    Likely.

提交回复
热议问题