473,320 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

long double in C89?

Could someone who has access to the C89 specification please confirm
whether the type long double existed in that spec.? The only copy I
have is from the early draft stages, and it wasn't in that (tatty paper
copy). I have tests in some of my source code from the early 90s to
detect whether long double was present (including float.h and testing
for some of the macros), but that may have been for non-conforming
compilers.

(gcc -std=c89 -pedantic accepts it, so it may well be OK, unless gcc has
it as an un-noticed extension...)

Thanks,

Chris C
Nov 14 '05 #1
7 3321
Chris Croughton wrote:
Could someone who has access to the C89 specification please confirm
whether the type long double existed in that spec.?


Yes, it's there.

--
Er*********@sun.com

Nov 14 '05 #2
Chris Croughton <ch***@keristor.net> wrote:

Could someone who has access to the C89 specification please confirm
whether the type long double existed in that spec.?


It did.

-Larry Jones

I thought my life would seem more interesting with a musical
score and a laugh track. -- Calvin
Nov 14 '05 #3
On Thu, 06 Jan 2005 14:29:03 -0500, Eric Sosman
<er*********@sun.com> wrote:
Chris Croughton wrote:
Could someone who has access to the C89 specification please confirm
whether the type long double existed in that spec.?


Yes, it's there.


Thanks, I can now take out a load of conditional code which was making
things really messy (since I'm not intending that code to target any
compilers before C89). It was getting to be a fire hazard (er,
maintenance hazard)...

Chris C
Nov 14 '05 #4
la************@ugs.com writes:
Chris Croughton <ch***@keristor.net> wrote:

Could someone who has access to the C89 specification please confirm
whether the type long double existed in that spec.?


It did.


One possible source of confusion is that some versions of gcc
incorrectly warn about the "L" length modifier in printf calls:

% cat tmp.c
#include <stdio.h>

int main(void)
{
long double foo = 1.0L;
printf("foo = %Lf\n", foo);
return 0;
}
% gcc --version
2.95.2
% gcc -ansi -pedantic -Wall tmp.c
tmp.c: In function `main':
tmp.c:6: warning: ANSI C does not support the `L' length modifier

In fact, the C90 standard does explicitly support this modifier. This
has been corrected in more recent versions of gcc.

(Strictly speaking, this wasn't a violation of the standard. The
standard allows an implementation to issue any diagnostics it likes,
and doesn't require them to be truthful, and of course there's no
requirement to issue diagnostics for bad format strings. But it was
certainly a bug.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
On Fri, 07 Jan 2005 00:21:55 GMT, Keith Thompson
<ks***@mib.org> wrote:
la************@ugs.com writes:
Chris Croughton <ch***@keristor.net> wrote:

Could someone who has access to the C89 specification please confirm
whether the type long double existed in that spec.?
It did.


One possible source of confusion is that some versions of gcc
incorrectly warn about the "L" length modifier in printf calls:


Ah, I think I've seen that. At one time I certainly also had to deal
with some C compilers which didn't have long double or define LDBL_* in
float.h, but those may have been pre-ANSI ones which had adopted some
ANSI features (like prototypes) but not others.
In fact, the C90 standard does explicitly support this modifier. This
has been corrected in more recent versions of gcc.
It seems to have been corrected by 2.95.4 (and is definitely corrected
in the v3 ones).
(Strictly speaking, this wasn't a violation of the standard. The
standard allows an implementation to issue any diagnostics it likes,
and doesn't require them to be truthful, and of course there's no
requirement to issue diagnostics for bad format strings. But it was
certainly a bug.)


It was at least only a warning, even with -pedantic. I do wish they'd
added some other features earlier (like floating point constants in hex
and the A output type).

A problem is that since the C library is divorced from the compiler
itself, the compiler can't warn about things the library accepts or
doesn't implement. For instance, under Cygwin the compiler (gcc 3.3.3)
may be conforming but the library is definitely C99 deficient (only C89
printf formats, no snprintf, no ldexpl but does have ldexpf). As far as
I can see there is no portable way to test a library at compile time for
conforming to any standard (no equivalent of __STDC_VERSION__ for the
library).

Chris C
Nov 14 '05 #6
Chris Croughton <ch***@keristor.net> writes:
[...]
As far as I can see there is no portable way to test a library at
compile time for conforming to any standard (no equivalent of
__STDC_VERSION__ for the library).


Right, the standard's presumption is that the compiler and the library
are both part of the "implementation". (One way to work around this
is to add a configuration step to your build process that compiles and
executes small test programs to determine what's actually implemented,
then creates a header file that's included by the application.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #7
On Fri, 07 Jan 2005 21:10:44 GMT, Keith Thompson
<ks***@mib.org> wrote:
Chris Croughton <ch***@keristor.net> writes:
[...]
As far as I can see there is no portable way to test a library at
compile time for conforming to any standard (no equivalent of
__STDC_VERSION__ for the library).


Right, the standard's presumption is that the compiler and the library
are both part of the "implementation". (One way to work around this
is to add a configuration step to your build process that compiles and
executes small test programs to determine what's actually implemented,
then creates a header file that's included by the application.)


Oh, I do (I use GNU autoconf which generates a 'configure' script,
running that produces config.h with a load of defines; I also have a
separate program which determines some things which the autoconf script
can't do easily). However, things like whether the format specifiers in
printf conform (and work) are not at all easy to test. Nor are
functions missing (or worse present and non-working) always easy to
detect and duplicate in a portable way (things like ldexpl, for
example). Also the configure script depends on having a unix-like
environment (or at least a Bourne shell equivalent and several standard
utiities like sed), writing it as a C89 program would probably take more
space than the whole of the rest of the library...

Chris C
Nov 14 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Suzanne Vogel | last post by:
I'd like to convert a double to a binary representation. I can use the "&" bit operation with a bit mask to convert *non* float types to binary representations, but I can't use "&" on doubles. ...
12
by: jose luis fernandez diaz | last post by:
Hi, My OS is: cronos:jdiaz:tmp>uname -a HP-UX cronos B.11.11 U 9000/800 820960681 unlimited-user license I compile in 64-bits mode the program below:
3
by: RoSsIaCrIiLoIA | last post by:
I have rewrote the malloc() function of K&R2 chapter 8.7 typedef long Align; ^^^^ Here, should I write 'long', 'double' or 'long double'? I know that in my pc+compiler sizeof(long)=4,...
15
by: michael.mcgarry | last post by:
Hi, I have a question about floating point precision in C. What is the minimum distinguishable difference between 2 floating point numbers? Does this differ for various computers? Is this...
5
by: Daniel Rudy | last post by:
How does one covert a interger number in a unsigned long long int (64-bit) to long double (80-bit) storage? I looked at math.h and I found function that convert double to long long, but didn't...
10
by: Bryan Parkoff | last post by:
The guideline says to use %f in printf() function using the keyword float and double. For example float a = 1.2345; double b = 5.166666667; printf("%.2f\n %f\n", a, b);
69
by: fieldfallow | last post by:
Hello all, Before stating my question, I should mention that I'm fairly new to C. Now, I attempted a small demo that prints out the values of C's numeric types, both uninitialised and after...
67
by: lcw1964 | last post by:
This may be in the category of bush-league rudimentary, but I am quite perplexed on this and diligent Googling has not provided me with a clear straight answer--perhaps I don't know how to ask the...
52
by: lcw1964 | last post by:
Greetings, all, I am trying to port a little bit of math code to gcc, that in the original version used the long double version of several functions (in particular, atanl, fabsl, and expl). I...
10
by: ratcharit | last post by:
Currently using cosine function in math.h Currently I get: 1 = cos(1e^-7) Is there another way for cos to return value of high accuracy say: 0.999999 = cos(1e^-7)
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.