Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Signed zero

ToKr
Beginner
565 Views

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

The following code gives me as output -0.00.

[fortran]

    program TestNegZero

    implicit none

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

[/fortran]

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)

0 Kudos
3 Replies
Steven_L_Intel1
Employee
565 Views

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.

0 Kudos
ToKr
Beginner
565 Views

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. 

0 Kudos
Steven_L_Intel1
Employee
565 Views

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

0 Kudos
Reply