Re: Sensibly printed floats?

From: Eric Sosman (esosman_at_acm-dot-org.invalid)
Date: 01/08/05


Date: Sat, 08 Jan 2005 08:53:27 -0500

Adam Warner wrote:
> Hi all,
>
> I'm used to ANSI Common Lisp implementations sanely printing single and
> double floats. By sane I mean the printed decimal representation mimics
> the underlying binary precision of the float. For example:
>
> [1]> (coerce 2/3 'single-float)
> 0.6666667
> [2]> (coerce 2/300 'single-float)
> 0.006666667
> [3]> (coerce 2/3 'double-float)
> 0.6666666666666666d0
> [4]> (coerce 2/300 'double-float)
> 0.006666666666666667d0
> [5]> (coerce 2/30000 'double-float)
> 6.666666666666667d-5
>
> Does C99 provide a method to print floats this way (apart from `f', `d'
> etc. exponential markers)?

     I'm not entirely sure I understand what you mean by
"this way," but perhaps the "%g" conversion specifier is
what you're looking for.

-- 
Eric.Sosman@sun.com


Relevant Pages

  • Re: Microcontroller Project
    ... any sane person would want to do on an 8051. ... I guess you're calling me insane then...... ... If floats are needed in an 8051 project, ...
    (sci.electronics.design)
  • Sensibly printed floats?
    ... double floats. ... By sane I mean the printed decimal representation mimics ... the underlying binary precision of the float. ...
    (comp.lang.c)

Loading