🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #41506

GCC printf( ) messes up with UnixLib 3.6(e)

#41506
From: Graham Seale
Date: Fri, 22 Mar 1996 00:00
122 lines
3960 bytes
Hello Programmers

Please forgive that I need a little handholding. Some of the stuff in
this group looks intimidating, but you seem more approachable than the
guys at comp.unix.questions. 

I use gcc 2.4.5 ported to a ARM610 RISC machine (Acorn's RiscPC600).
It links to a (supplied) Unixlib version 3.6(e).
A new port of GCC 2.7.2 with Unixlib 4.0 is promised "shortly".

I had been using this setup as the main practical support tool for a C
module in software design from the Farnborough College of Technology. 

I have found an apparent bug in the Unixlib 3.6(e) that causes the
printf() function to mess up on floating point numbers. We know the
problem is in the library, not in the gcc compiler. I have a trivial
program to demonstrate it, and I seek to discover:-

a) Whether this bug is already generally known - and any advice.
b) Whether it can be replicated on other machines.
c) Suggestions for a fix/workaround  

* We have already checked that GCC compiles the program without errors when
  linked to an alternative (Norcroft) library.

* The problem can be reproduced with the alternative Norcroft compiler, if
  it is linked to use UnixLib instead of its own library.
  
There follows a listing of simple addition of numbers.
I include an embedded comment field showing what happens when Unixlib
is used with gcc.

Begin Example Program 
_______________________________________________________________________


/*GNU GCC example program for UnixLib 3.6(e)    */
/*Floating point Test No.1                      */
/*This uses %f format when printing values      */

main()
{
  float x,y,t;
  printf("\n Floating Point Test No.1");
  printf("\n It uses the default f to format the output\n");
  printf("\n # First simple test addition #");
  printf("\n (80.22 + 91.69 = 171.91 correct to about 7 digits.)\n");

  /* First simple test addition */

  x=80.22;   printf("\n x = %f",x);
  y=91.69;   printf("\n y = %f",y);
  t=x+y;

  printf("\n t = %f",t);
  printf("\n________________________________________________\n");



  /* Second test addition */
  printf("\n # Second simple test addition #");
  printf("\n (38.22 + 91.69 = 130.00  Wrong!!\n");

  x=38.22;   printf("\n x = %f",x);
  y=91.69;   printf("\n y = %f",y);
  t=x+y;

  printf("\n t = %f",t);
  printf("\n_________________________________________________\n");


  /* Third test addition */
  printf("\n # Third simple test addition #");
  printf("\n 8.22 + 91.69 = something strange!\n");

  x=8.22;    printf("\n x = %f",x);
  y=91.69;   printf("\n y = %f",y);
  t=x+y;
  printf("\n t = %f",t);
  printf("\n      |\n  Why did this happen??");
}

/*    ***** LISTING OF OUTPUT FROM FPTest1 *****

 Floating Point Test No.1
 It uses the default f to format the output

 # First simple test addition #
 (80.22 + 91.69 = 171.91 correct to about 7 digits.)

 x = 80.220001
 y = 91.690002
 t = 171.910003
________________________________________________

 # Second simple test addition #
 (38.22 + 91.69 = 130.00  Wrong!!

 x = 38.220001
 y = 91.690002
 t = 130.000000
_________________________________________________

 # Third simple test addition #
 8.22 + 91.69 = something strange!

 x = 8.220000
 y = 91.690002
 t = :0.000000
      |
  Why did this happen??
 */



____________________________________________________________________
end of program example

My thanks in advance

-- 
Graham Seale
Technical Details
Message-ID: <19960322.222639.23@southlin.demon.co.uk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,3b6b37c5b69484e4,start
X-Google-Attributes: gid11318c,public
From: graham@southlin.demon.co.uk (Graham Seale)
Subject: GCC printf( ) messes up with UnixLib 3.6(e)
Date: 1996/03/22
Message-ID: <19960322.222639.23@southlin.demon.co.uk>
X-Deja-AN: 143801477
distribution: world
x-nntp-posting-host: southlin.demon.co.uk
reply-to: graham@southlin.demon.co.uk
newsgroups: gnu.gcc.help