program TEST_LONGLOG_LONGEXP
! Tests:
! 1. log(x^2) = 2.*log(x)
! 2. e^(2x)   = (e^x)**2

use QUADRUPLE_PRECISION
implicit none

type (QUAD)                        :: X, LHS, RHS, DIFF
integer, allocatable, dimension(:) :: SEED
integer                            :: K, I
real (kind=DP), parameter          :: HALF = 0.5_DP, SMALL = 1.0e-16_DP

!     Set the random number seed.

call random_seed(size=K)
allocate (SEED(K))
call random_seed(get=SEED)
write(unit=*, fmt=*) "Old random number seeds: ", SEED

write(unit=*, fmt="(a, i4, a)") " Enter ", K, " integers as random number seeds: "
read(unit=*, fmt=*) SEED
call random_seed(put=SEED)

do I = 1, 10
  call random_number(X%HI)
  X%HI = (X%HI - HALF) / X%HI
  X%LO = X%HI * SMALL
                                       ! log(x^2) = 2.*log(x)
  LHS = log(X * X)
  if (X%HI > 0.0_DP) then
    RHS = log(X)
  else
    RHS = log(-X)
  end if
  RHS = 2.0_DP * RHS
  DIFF = LHS - RHS
  write(unit=*, fmt="(a, g13.5, a, g12.4)") " lhs =", LHS%HI, "  Diff. =", DIFF%HI
                                       ! e^(2x) = (e^x)**2
  LHS = 2.0_DP * X
  LHS = exp(LHS)
  RHS = exp(X)
  RHS = RHS * RHS
  DIFF = LHS - RHS
  write(unit=*, fmt="(a, g13.5, a, g12.4)") " lhs =", LHS%HI, "  Diff. =", DIFF%HI
end do

stop
end program TEST_LONGLOG_LONGEXP
