Signed zero

Signed zero

Bild des Benutzers ToKr

Hello, I have a question about signes zero-values in a FORMAT-output.

The following code gives me as output -0.00.

    program TestNegZero
    implicit none
    real*8 dTest
    
    dTest=-0.001
    write(*,'(f5.2)')dTest
     
    end program TestNegZero

In my old compiler (Compaq Visual Fortran), I got as output 0.00. I would like to achieve to get this output again, because I have a big program with calculation-outputs and there are now many cases with  -0,00 as output.

Till now, I did not find a setting to manipulate the behaviour, is there a solution?

Thanks a lot for any advice and greetings from germany (therefore my english is not so perfect)

Greetings, Torsten
4 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers Steve Lionel (Intel)

The CVF behavior was a bug. The standard requires that there be a sign when the original value is negative, even if it rounds to zero. There's no way to change this, sorry.

Steve
Bild des Benutzers ToKr

OK, thanks for the info.

I just found out, that with the compiler-setting /vms (enable VMS Compatibility) the output is not signes anymore, but I think, this setting will for sure make me other problems.

So it seems, the onliest solution is to round myself every output. 

Greetings, Torsten
Bild des Benutzers Steve Lionel (Intel)

No, /vms is doing something different here - it's establishing Fortran carriage control so that the sign is interpreted as carriage control. If you change the format to "1x,f5.2" you'll see the sign, even with /vms.

You could use an internal write and write to a string, and then if the string was equal to "-0.00" change it to " 0.00".

Steve

Melden Sie sich an, um einen Kommentar zu hinterlassen.