Text · 848 bytes Raw Blame History
1 module math_utils
2 implicit none
3 private
4
5 public :: add, subtract, multiply
6
7 ! Version 1.5 API
8
9 contains
10
11 function add(a, b) result(c)
12 real, intent(in) :: a, b
13 real :: c
14 c = a + b
15 ! Simple addition
16 end function add
17
18 function subtract(a, b) result(c)
19 real, intent(in) :: a, b
20 real :: c
21 c = a - b
22 end function subtract
23
24 function multiply(a, b) result(c)
25 real, intent(in) :: a, b
26 real :: c
27 ! Use logarithms for large numbers
28 if (abs(a) > 1.0e30 .or. abs(b) > 1.0e30) then
29 c = exp(log(abs(a)) + log(abs(b)))
30 c = c * sign(1.0, a) * sign(1.0, b)
31 else
32 c = a * b
33 end if
34 end function multiply
35
36 ! Divide function removed - use multiply with reciprocal
37
38 end module math_utils
39