Your professor might have not gotten enough sleep if...

ProviaFan

Lifer
Mar 17, 2001
14,993
1
0
...if he asks the class to evaluate the Fortran expression:

something = 2.0 ** (-1)

and when I answer, tells me that 0.5 is not correct. :shocked:

That is all.
 

dullard

Elite Member
May 21, 2001
25,820
4,378
126
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.
 

Cooler

Diamond Member
Mar 31, 2005
3,835
0
0
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.

ah so thats how yoy expos in fortran i forgot its been such a long time.
 

ProviaFan

Lifer
Mar 17, 2001
14,993
1
0
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:

2^(-1)
 

dullard

Elite Member
May 21, 2001
25,820
4,378
126
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.
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:

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.
 

DAGTA

Diamond Member
Oct 9, 1999
8,172
1
0
Why are you still learning Fortran? How about something that might actually be useful after school.
 

Gunslinger08

Lifer
Nov 18, 2001
13,234
2
81
Originally posted by: DAGTA
Why are you still learning Fortran? How about something that might actually be useful after school.

You'd be amazed. In my Languages class I had to program in FORTRAN, SNOBOL, Ada, Pascal, Prolog, Lisp, etc.

Only one of those is even remotely useful anymore.
 

ProviaFan

Lifer
Mar 17, 2001
14,993
1
0
Originally posted by: joshsquall
All of the compilers I've used (meaning 2 of them) don't support mixed-mode arithmetic.
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: dullard
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.
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:

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.
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.