---
jupytext:
formats: md:myst
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: Python 3
language: python
name: python3
---Section IEEE754: Zero vs Non - Zero¶
Illustrates that 0.0 is equal to -0.0.¶
program zero_vs_minus_zero
implicit none
real :: zero = 0.0, minus_zero
minus_zero = sign(zero, -1.0)
print '(A, 2F7.2)', '0 vs. -0: ', zero, minus_zero
if (zero == minus_zero) then
print '(A)', "Yes...."
print '(A)', '0 == -0'
else
print '(A)', "No...."
print '(A)', '0 /= -0'
end if
print '(A, F5.1)', 'sqrt(0.0) = ', sqrt(zero)
print '(A, F5.1)', 'sqrt(-0.0) = ', sqrt(minus_zero)
end program zero_vs_minus_zeroThe above program is compiled and run using Fortran Package Manager (fpm):
import os
root_dir = os.getcwd()code_dir = root_dir + "/" + "Fortran_Code/Section_IEEE754_Zero_vs_Non_Zero"os.chdir(code_dir)build_status = os.system("fpm build 2>/dev/null")fpm run output is piped into sed to suppress the status of the run command and only print the output of the executable.
exec_status = os.system("fpm run 2>/dev/null")0 vs. -0: 0.00 -0.00
0 == -0
sqrt(0.0) = 0.0
sqrt(-0.0) = -0.0