swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: float/double


From: Rick Riolo
Subject: Re: float/double
Date: Fri, 31 Jul 1998 09:05:56 -0400 (EDT)

Well, just as a data point: 
Here is what my 3rd edition of harbison and steele says (p310):

  An optional size specification, expressed as the character h,
  meaning short, or as the character l (lowercase letter L), meaning long 
  or double, or as the character L meaning long double.
  ...
  The letter l [lowercase l] maybe used with the e, f, or g operation
  to indicate assignment to a location of type double rather than float.

So to me it says one should be able to use lf.
Yet here is what I get with this little test program using gcc
under hpux:

badger-rlr)cat testl.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void main ( ) {
    float f;
    double d;
    long double ld;

    f = 1.0; d = 2.0; ld = 3.0;
    printf("float f         %f\n", f );
    printf("float lf       %lf\n", f ); /* line 14 */
    printf("double f        %f\n", d );
    printf("double lf      %lf\n", d ); /* line 16 */
    printf("long double f   %f\n", ld );
    printf("long double lf %lf\n", ld ); /* line 18 */
    printf("long double Lf %Lf\n", ld );
}
badger-rlr)gcc -Wall testl.c
testl.c: In function `main':
testl.c:12: warning: use of `l' length character with `f' type character
testl.c:14: warning: use of `l' length character with `f' type character
testl.c:15: warning: double format, long double arg (arg 2)
testl.c:16: warning: use of `l' length character with `f' type character
badger-rlr)a.out
float f         1.000000
float lf       1.000000
double f        2.000000
double lf      2.000000
long double f   3.000000
long double lf 3.000000
Bus error (core dumped)

Note it doesn't seem to like %lf (a warning, but it works) for
any of these types.  It catches the use of %f with long double,
but that prints out the right number.   But then it crashes
when it tries to print out %Lf with a long double variable!
(It crashes if I #ifdef-out everything but that last line.)

 - r

Rick Riolo                           address@hidden
Program for Study of Complex Systems (PSCS)
4477 Randall Lab                
University of Michigan         Ann Arbor MI 48109-1120
Phone: 734 763 3323                  Fax: 734 763 9267
http://www.pscs.umich.edu/PEOPLE/rlr-home.html

On Thu, 30 Jul 1998, Chimera wrote:

> Date: Thu, 30 Jul 1998 16:02:06 -0700
> From: Chimera <address@hidden>
> To: address@hidden
> Subject: float/double
> 
> Here is what should be a beginners question, but it is biting me now.
> 
> According to the man page and reference texts, putting "l" in front of
> "d" or "f" in printf or scanf implies a "long" value.  The problem I am
> encountering is that "%ld" is accepted, but "%lf" isn't.  Is this
> telling me that there is no difference between a float and a double on
> the machine?  Note I am talking Unix.
> 
> Cheers,
> 
>    D3
> 
> --
> *********************************************************************
> * Doug Donalson                 Office: (805) 893-2962
> * Ecology, Evolution,           Home:   (805) 961-4447
> * and Marine Biology            email address@hidden
> * UC Santa Barbara
> * Santa Barbara Ca. 93106
> *********************************************************************
> *
> *   The most exciting phrase to hear in science, the one that
> *   heralds new discoveries, is not "EUREKA" (I have found it) but
> *   "That's funny ...?"
> *
> *       Isaac Asimov
> *
> *********************************************************************
> 
> 
> 
>                   ==================================
>    Swarm-Support is for discussion of the technical details of the day
>    to day usage of Swarm.  For list administration needs (esp.
>    [un]subscribing), please send a message to <address@hidden>
>    with "help" in the body of the message.
>                   ==================================
> 

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]