Author Topic: How to print floating point numbers  (Read 12322 times)

Offline nullptr

  • Jr. Member
  • *
  • Posts: 27
How to print floating point numbers
« on: May 13, 2013, 08:46:01 AM »
Hi all,

How to print floats single and double precission using libc on linux in 64 bit code. could some give some examples.

thanks in advance.

Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: How to print floating point numbers
« Reply #1 on: May 14, 2013, 02:01:37 AM »
Try looking at the docs first, try some code, and when stuck, post what you are having trouble with. 

http://www.cplusplus.com/reference/cstdio/fprintf/
http://www.cplusplus.com/reference/cstdio/printf/

Offline Gerhard

  • Jr. Member
  • *
  • Posts: 51
Re: How to print floating point numbers
« Reply #2 on: May 14, 2013, 12:45:39 PM »
Hi nullptr,

printing floating point values via libc under 64 bit Linux is little bit tricky. I've attached for you a simple test program and I hope it'll show you the right direction. The tricky part is to ensure the 16 bit alignment of the stack.

Gerhard

Offline nullptr

  • Jr. Member
  • *
  • Posts: 27
Re: How to print floating point numbers
« Reply #3 on: May 14, 2013, 12:59:21 PM »
Thanks for replies. I'll follow the links and try the code.