Originally posted by: dullard
Its been a long time since I used Fortran. But since your exponent is an integer, doesn't Fortran force the final answer to be an integer. 1/2.0 written as an integer is not 0.5. Of course, I could be wrong. That is one reason that Fortran sucks - it is so easy to be wrong with your assumptions.
Implicit type conversions are always integer to real when the two are mixed, though in the case of an exponent it is desirable to use an integer for the power, because it's not possible to raise a negative number to a real power (because Fortran would be taking the ln of a negative number). In this case, though, the expression means exactly what it says, or in the normal sense:Originally posted by: dullard
Its been a long time since I used Fortran. But since your exponent is an integer, doesn't Fortran force the final answer to be an integer. 1/2.0 written as an integer is not 0.5. Of course, I could be wrong. That is one reason that Fortran sucks - it is so easy to be wrong with your assumptions.
Well then your professor made a simple mistake that Fortran lets you make. This one always got me when I tried to program in Fortran:Originally posted by: ProviaFan
Implicit type conversions are always integer to real when the two are mixed, though in the case of an exponent it is desirable to use an integer for the power, because it's not possible to raise a negative number to a real power (because Fortran would be taking the ln of a negative number). In this case, though, the expression means exactly what it says, or in the normal sense.
Originally posted by: DAGTA
Why are you still learning Fortran? How about something that might actually be useful after school.
We use "f90" on the Solaris systems, which does support mixed-mode arithmetic. I've not used any other Fortran compilers before this.Originally posted by: joshsquall
All of the compilers I've used (meaning 2 of them) don't support mixed-mode arithmetic.
I don't know why he made the mistake he made, or what thought process brought him to it, but what you have shown there is exactly what he was [trying to] lecture on.Originally posted by: dullard
Well then your professor made a simple mistake that Fortran lets you make. This one always got me when I tried to program in Fortran:Originally posted by: ProviaFan
Implicit type conversions are always integer to real when the two are mixed, though in the case of an exponent it is desirable to use an integer for the power, because it's not possible to raise a negative number to a real power (because Fortran would be taking the ln of a negative number). In this case, though, the expression means exactly what it says, or in the normal sense.
16.0**(1/4). It evaluates to be 1.
But 16.0**(1.0/4.0) evaluates to be 2.0.
So, I just learned early on to always use real numbers for exponents in Fortran. Then do a check to make certain the number isn't negative.