From: Vincenzo Mercuri on
Hi all,
I've been always told of the C language as the best choice
to accomplish any kind of task in numerical algorithms implementation.
I'd like to do some serious programming in numerical analysis and
I'd like to read some opinion about whether C has too many limitations
or it is far a better choice than Fortran is. I have some questions
that may seem trivial and not topical to this group (I've already
posted the same questions in comp.lang.c). Here they are:

1 -- is there any reason not to learn Fortran (a new language for me)
and focus on C (and C numerical libraries) potentialities?

2 -- is Fortran considered the best choice in this field only because
of its construct and syntax that makes easier to handle
mathematical entities?

3 -- what about the Standard IEEE 754 (IEC 60559:1989) conformance?
is that intrinsecal to the language or the implementation?
which language can offer a full support to the IEEE Standard,
C or Fortran?

4 -- what about performance? would you bet on C or Fortran? :-)


Thank you in advance.

--
Vincenzo Mercuri
From: Vincenzo Mercuri on
Vincenzo Mercuri wrote:

> I've been always told of the C language as the best choice
[...]
> 2 -- is Fortran considered the best choice in this field only because
> of its construct and syntax that makes easier to handle
> mathematical entities?

(considered the best choice not by the same people who told me of
C to be the best one)


--
Vincenzo Mercuri
From: glen herrmannsfeldt on
Vincenzo Mercuri <comp(a)lang.c> wrote:

> I've been always told of the C language as the best choice
> to accomplish any kind of task in numerical algorithms implementation.

Who told you that?

> I'd like to do some serious programming in numerical analysis and
> I'd like to read some opinion about whether C has too many limitations
> or it is far a better choice than Fortran is. I have some questions
> that may seem trivial and not topical to this group (I've already
> posted the same questions in comp.lang.c). Here they are:

I have no idea what kind of answers you will get in comp.lang.c,
though likely not very useful ones.

> 1 -- is there any reason not to learn Fortran (a new language for me)
> and focus on C (and C numerical libraries) potentialities?

Both languages can do a fairly good job for most numerical
analysis problems. There are good and bad parts of each.
Some will only point out the good or bad parts, but it depends
a lot on what you want to do and how you want to do it.

> 2 -- is Fortran considered the best choice in this field only because
> of its construct and syntax that makes easier to handle
> mathematical entities?

I believe that the main reason is that, traditionally, most numerical
work was done in Fortran. You can find 50 year old libraries of
numerical analysis programs. (You probably don't want to use
them, though.) If you don't want to start from the beginning,
then using existing libraries is likely easier in Fortran.

There aren't that many syntax differences that are important
in writing numerical code. One is that Fortran has an operator
for exponentiation (**), where C uses a function call (pow).
On the other hand, C uses an operator for mod (%), where Fortran
uses a function call.

C is a lower level language than Fortran. You have to do some
things yourself in C, but for many people that isn't a problem.

> 3 -- what about the Standard IEEE 754 (IEC 60559:1989) conformance?
> is that intrinsecal to the language or the implementation?
> which language can offer a full support to the IEEE Standard,
> C or Fortran?

IEEE 754 (why 1989 and not 2008?) is not intrinsic to either,
and likely neither offers full support. Fortran 2003 includes
a module and many intrinsic functions, and those help write
conforming code. Though not standard, many of the IEEE 754 features
were available in C earlier than in Fortran.

> 4 -- what about performance? would you bet on C or Fortran? :-)

I wouldn't bet. If you are careful in writing the appropriate
low-level code in C, it can often be faster than Fortran.
If you are not so careful, a good optimizing Fortran compiler
might generate faster code, or it might not.

Many Fortran features have higher overhead than the code that
would usually be written in C to do a similar function.

-- glen
From: Nick Maclaren on
In article <i3s1br$dks$1(a)speranza.aioe.org>,
glen herrmannsfeldt <gah(a)ugcs.caltech.edu> wrote:
>Vincenzo Mercuri <comp(a)lang.c> wrote:
>
>> I've been always told of the C language as the best choice
>> to accomplish any kind of task in numerical algorithms implementation.
>
>Who told you that?

Someone seriously lacking in Clue?

>> 3 -- what about the Standard IEEE 754 (IEC 60559:1989) conformance?
>> is that intrinsecal to the language or the implementation?
>> which language can offer a full support to the IEEE Standard,
>> C or Fortran?
>
>IEEE 754 (why 1989 and not 2008?) is not intrinsic to either,
>and likely neither offers full support. Fortran 2003 includes
>a module and many intrinsic functions, and those help write
>conforming code. Though not standard, many of the IEEE 754 features
>were available in C earlier than in Fortran.

Neither offer full support, and the C support is seriously flawed,
much more than the slightly flawed Fortran support. Nobody who
has to ask this sort of question on a newsgroup has the chance of
a flea in a furnace of writing reliable numerical code using C's
IEEE 754 features, even ignoring portability (which is damn-near
impossible). I would have to sweat blood, and I know as much about
this area as anyone I know of.

Nobody supports IEC 60559:2008 yet, as far as I know, and it is far
from certain that it will get industry acceptance. It may simply
get kicked into the long grass by the community, in much the same
way that full C99 support has been.

>> 4 -- what about performance? would you bet on C or Fortran? :-)
>
>I wouldn't bet. If you are careful in writing the appropriate
>low-level code in C, it can often be faster than Fortran.
>If you are not so careful, a good optimizing Fortran compiler
>might generate faster code, or it might not.

Even if you are careful. Fortran is a vastly more optimisable
language than C, and beats the living daylights out of C on most
HPC systems, and usually when writing shared-memory parallel code.


Regards,
Nick Maclaren.
From: glen herrmannsfeldt on
Nick Maclaren <nmm(a)gosset.csi.cam.ac.uk> wrote:
> In article <i3s1br$dks$1(a)speranza.aioe.org>,
> glen herrmannsfeldt <gah(a)ugcs.caltech.edu> wrote:
>>Vincenzo Mercuri <comp(a)lang.c> wrote:

>>> I've been always told of the C language as the best choice
>>> to accomplish any kind of task in numerical algorithms implementation.
(snip regarding IEEE 754)

> Neither offer full support, and the C support is seriously flawed,
> much more than the slightly flawed Fortran support. Nobody who
> has to ask this sort of question on a newsgroup has the chance of
> a flea in a furnace of writing reliable numerical code using C's
> IEEE 754 features, even ignoring portability (which is damn-near
> impossible). I would have to sweat blood, and I know as much about
> this area as anyone I know of.

I agree, but they you can always write what you want in assembler...
Non-portable, though.

Then again, different people have different ideas about
what they mean by IEEE 754.

> Nobody supports IEC 60559:2008 yet, as far as I know, and it is far
> from certain that it will get industry acceptance. It may simply
> get kicked into the long grass by the community, in much the same
> way that full C99 support has been.

IBM has some support for the decimal float modes. Since they
did much of the work to get it into the standard, that isn't
too surprising. I don't know in detail how much of the standard
they support, though.

>>> 4 -- what about performance? would you bet on C or Fortran? :-)

>>I wouldn't bet. If you are careful in writing the appropriate
>>low-level code in C, it can often be faster than Fortran.
>>If you are not so careful, a good optimizing Fortran compiler
>>might generate faster code, or it might not.

> Even if you are careful. Fortran is a vastly more optimisable
> language than C, and beats the living daylights out of C on most
> HPC systems, and usually when writing shared-memory parallel code.

Yes, but if you aren't careful you can write some very un-optimizable
code in Fortran. Some that are easy to write using for loops
in C, but are instead written using Fortran array intrinsic
functions requiring temporary arrays and much more processing
to get the desired result.

With the assumption that you know what you want the compiled
code to look like, it is much easier to write C code to
generate that result than Fortran code.

-- glen