Re: "typedef" in F95/2003?



On Wed, 23 May 2007, Richard Maine wrote:

Chip Coldwell <coldwell@xxxxxxxxxxxxxxxxx> wrote:

You can get nearly the same result by defining assignment operators in
Fortran 95,

No, you can't. Literal constants appear in other contexts than as the
sole thing on the RHS of an assignment. If you do

foo = 1.23

then the 1.23 is a single precision constant.

Right, and "foo" is whatever I've declared it to be. In the case of the
quad double types from the Hida/Bailey package, there exists a defined
assignment operator for this combination.

Nothing you can do with a defined assignment will change that. If foo is
a double or a quad, you'll have just lost precision.

How do you figure that? If I put a single precision value (the literal
constant) into a quad double variable, I've gained precision, right?

And if you do

call sub(1.23)

then assignment doesn't have anything to do with the question. If the
dummy argument is anything other than a single real, then it won't work
at all.

Right, but it could. In C++, if "sub" were declared with a quad double
dummy argument, the compiler would generate a temporary quad double
variable, assign the single precision value 1.23 to it using the defined
assignment operator, and then pass the temporary to the called function.
Clearly that's not possible unless "sub" has an explicit interface, so
perhaps it's ruled out for Fortran on that basis.

For another example, your

function foo
type(qd_real) :: foo
type(qd_real) :: one = 1.0
type(qd_real) :: two = 2.0

Is invalid because initializers don't use defined assignment, even if
you have such a thing.

Fair enough. Bad example.

You are just talking about ways to avoid using quad literal copnstants.
That's not the same thing as defining how to write them.

In practice, the authors of the library solved this problem by providing
functions for assignment to quad double variables from character strings.
So put your literal in quotes if you need the full precision to represent
its value.

However, that is not my point; in fact, this whole discussion has wandered
off into the weeds.

I'm not worried about precision, or the loss thereof. I'm not arguing
about whether or not you need to be able to represent literal constants of
an arbitrary derived type. What I am trying to understand is why
introducing "typealias" into the language makes coping with literal
constants more difficult for the compiler writer. Maybe I'm a little
thick about this, but I just don't understand your explanation.

It was judged that, on the whole, this would work so poorly for this
purpose that it would be a disservice to claim that the typealias
feature addressed this problem, when most users would find that it
wouldn't work for them in practice. If you disagree with that judgement,
so be it.

I don't agree or disagree. I simply don't understand the basis for that
judgement.

Chip

--
Charles M. "Chip" Coldwell
"Turn on, log in, tune out"

.



Relevant Pages

  • Re: BLAS: dgemm
    ... to a procedure requiring double precision data, ... be 'single precision correct' instead of 'double precision correct'. ... Where is the compiler supposed to get ...
    (comp.lang.fortran)
  • Re: increasing width
    ... which I get every time I want to declare real. ... used to declare single or double precision variables. ... easily support more than one "kind" of single precision variable. ... have at least 13 digits of precision, ...
    (comp.lang.fortran)
  • Re: increasing width
    ... Some fellow over in sci.math.num-analysis tells me I can get at least 6 more sig figs, if instead of declaring as type real, I declare as real. ... used to declare single or double precision variables. ... easily support more than one "kind" of single precision variable. ... have at least 13 digits of precision, ...
    (comp.lang.fortran)
  • Re: Singles to Doubles
    ... of the original code difference between direct promotion as opposed to ... Double you would have gotten full precision to start with... ... You have successfully read the existing single precision data directly ...
    (microsoft.public.vb.general.discussion)
  • Re: KIND related issues on NAGware f95 v 4.1
    ... precision. ... What leads you to believe that the version you have supports quad ... If the compiler supports quad precision, ... that the standard syntax will get it. ...
    (comp.lang.fortran)