2

There is a data type in C89 (ANSI C) standard called long double, but there is no any mathematical function to support long double (<math.h>). For example, sin function accepts a long argument.

C99 supports mathematical functions for long double.

My question is, when there is no any mathematical functions to support long double in ANSI C, islong double useful?

Oleksi
  • 12,947
  • 4
  • 56
  • 80
Amir Saniyan
  • 13,014
  • 20
  • 92
  • 137
  • 8
    What about `+`, `-`, `*` and `/`? – Oliver Charlesworth Mar 24 '12 at 21:50
  • For these type of applications that used `long double` for best results, +,-,*,/ are not enough. – Amir Saniyan Mar 24 '12 at 21:57
  • for x86_64 float and have been replaced by SSE. However, at least with GCC long double still uses x87 even when float and double use SSE. So if one wants to use x87 for some of the code long double is one way to get to it. With MSVC long double appears to be just a synonym for double though so it won't get you x87 when double uses SSE. Perhaps your question was: is x87 still useful (besides for compatibly) or is 80-bit floating point still useful? That's an interesting question. – Z boson May 12 '16 at 12:30

2 Answers2

0

Just because math.h doesn't support something doesn't mean you can't make it yourself.

The type existing is a good thing, because it means there is a cross-platform way to request something with more or equal precision to a long. This couldn't be done if it wasn't in the language somewhere (your best bet would be to hack something together with a struct or array of longs / doubles).

The functions are just for convenience; sometimes a built-in sin processor function can be used, but sometimes not, and instead the sin function simply contains an algorithm to produce the answer, or look it up, using standard operations.

You could copy the sinl functions for your target platform from C99 to C89 if you wanted. There's a big list of implementations here: http://sourceware.org/git/?p=glibc.git;a=tree;f=sysdeps/ieee754;hb=HEAD

Or just stick to C99.

Dave
  • 44,275
  • 12
  • 65
  • 105
0

Yes, "long double" is absolutely useful if you wish to compute an expression with more than double precision.

An interesting side question is "What exactly IS 'long double'"?

The answer is platform- and/or compiler dependent:

http://en.wikipedia.org/wiki/Long_double

paulsm4
  • 114,292
  • 17
  • 138
  • 190