Fortran
Fortran copied to clipboard
Function to calculate the square root of a number
This pull request introduces a new Fortran module for calculating square roots and a dedicated test program to validate its functionality. The changes provide a reusable function for square root calculation, including error handling for negative inputs, and comprehensive test coverage with multiple scenarios.
New square root functionality:
- Added
square_root_modulecontaining thecalculate_sqrtfunction, which computes the square root of a non-negative number using Fortran's intrinsicSQRTfunction and returns-1.0for negative inputs.
Test coverage:
- Created
tests_square_root.f90program with six test cases covering zero, one, perfect squares, non-perfect squares, large numbers, and negative input scenarios for the square root function. - Implemented
assert_testsubroutine for floating-point comparison with tolerance, providing clear pass/fail output and stopping execution on test failure.