! dd_to_dp2.f90
!
! K. Myneni, 16 Sep 2026
!
! Convert a double double precision (DD) input to two
!   double precision (DP) numbers and display them in
!   scientific notation and their hex values.
!
! Build:
!   $ gfortran -O3 -o dd_to_dp2 dd_to_dp2.f90 ddmodule.o ddfuna.o ddfune.o second.o
!
! Build assumes you have built the Fortran ddfun-v04 package using the
!   shell script gnu-complib-dd.scr
! The script will generate the .o files for linking to the program below.
!
! Revisions:
!   2026-09-18 km; directly access the two DP numbers of DD variable

program ddtodp2
        use ddmodule
        implicit none
        real (ddknd) a(2)
        type (dd_real) t1, t2
        print *, 'Enter a double double (DD) number:'
        call ddread(5,t1)
        print *, 'The input DD number is:'
        call ddwrite(6,40,32,t1)
        ! a(1) = dble(t1)
        ! t2 = t1 - ddreal(a(1))
        ! a(2) = dble(t2)
        a(1) = t1%ddr(1)
        a(2) = t1%ddr(2)
        print *, 'The two double precision (DP) numbers are:'
        write(*,*) a(1), a(2)
        print *, 'The two DP hex values are:'
        write(*, '(Z16,2X,Z16)') a(1), a(2)
end program ddtodp2

