scaled Subroutine

private pure subroutine scaled(a, k, im, ok)

(), correctly rounded to an integer, when the result is about to . ok is false if (no exact power of ten).

Since doubles of that size are integers (their spacing is 2 or more), the rounded product or quotient is an integer, and only its exact rounding error has to be added (rounded).

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: a
integer, intent(in) :: k
integer(kind=int64), intent(out) :: im
logical, intent(out) :: ok

Calls

proc~~scaled~~CallsGraph proc~scaled scaled proc~two_prod two_prod proc~scaled->proc~two_prod proc~split split proc~two_prod->proc~split

Called by

proc~~scaled~~CalledByGraph proc~scaled scaled proc~add_real text_buffer%add_real proc~add_real->proc~scaled proc~add_real_list text_buffer%add_real_list proc~add_real_list->proc~add_real proc~add_real_array text_buffer%add_real_array proc~add_real_array->proc~add_real_list proc~write_json_real_array write_json_real_array proc~write_json_real_array->proc~add_real_list proc~generate_eclipse_data mission_type%generate_eclipse_data proc~generate_eclipse_data->proc~write_json_real_array proc~segment_trajectory_json segment_trajectory_json proc~segment_trajectory_json->proc~add_real_array proc~export_trajectory_json_file mission_type%export_trajectory_json_file proc~export_trajectory_json_file->proc~segment_trajectory_json proc~halo_solver_main halo_solver_main proc~halo_solver_main->proc~generate_eclipse_data proc~halo_solver_main->proc~export_trajectory_json_file

Source Code

    pure subroutine scaled(a, k, im, ok)

    real(dp),intent(in) :: a
    integer,intent(in) :: k
    integer(int64),intent(out) :: im
    logical,intent(out) :: ok

    real(dp) :: p, q, hi, lo, r

    im = 0
    ok = abs(k) <= 22
    if (.not. ok) return

    if (k >= 0) then
        ! a*p = hi + lo exactly:
        p = p10(k)
        call two_prod(a, p, hi, lo)
        im = int(hi, int64) + nint(lo, int64)
    else
        ! a/p = q + r/p, with the remainder r = a - q*p computed exactly:
        p = p10(-k)
        q = a / p
        call two_prod(q, p, hi, lo)
        r = (a - hi) - lo
        im = int(q, int64) + nint(r/p, int64)
    end if

    end subroutine scaled