Fortran icon indicating copy to clipboard operation
Fortran copied to clipboard

Function to calculate the square root of a number

Open ITZ-NIHALPATEL opened this issue 2 months ago • 0 comments

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_module containing the calculate_sqrt function, which computes the square root of a non-negative number using Fortran's intrinsic SQRT function and returns -1.0 for negative inputs.

Test coverage:

  • Created tests_square_root.f90 program 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_test subroutine for floating-point comparison with tolerance, providing clear pass/fail output and stopping execution on test failure.

ITZ-NIHALPATEL avatar Oct 25 '25 11:10 ITZ-NIHALPATEL