투케이2K

50. (C++) ldexp 함수 사용해 x * (2exp) 의 값을 계산 실시 본문

C++

50. (C++) ldexp 함수 사용해 x * (2exp) 의 값을 계산 실시

투케이2K 2023. 3. 11. 10:43
반응형

[개발 환경 설정]

개발 언어 : C++

 

[소스 코드]

 

// -----------------------------------------------------------------------------------------
//
// Created by KGH on 2023-02-12.
//
// -----------------------------------------------------------------------------------------





// -----------------------------------------------------------------------------------------
// TODO [헤더 파일 import]

#include "Test.h"
#include <android/log.h>
// -----------------------------------------------------------------------------------------





// -----------------------------------------------------------------------------------------
// TODO [include 및 define 문 정의]
#include <iostream>
#include <string>
#include <math.h>

using namespace std;
// -----------------------------------------------------------------------------------------




// -----------------------------------------------------------------------------------------
// TODO [구현부 소스 코드 작성]
int main(void)
{

    /**
     * ------------------------------------
     * [요약 설명]
     * ------------------------------------
     * 1. ldexp() 함수는 x * (2exp)의 값을 계산합니다
     * ------------------------------------
     * 2. 결과가 오버플로인 경우, 함수는 큰 결과에 대해 +HUGE_VAL, 작은 결과에 대해 -HUGE_VAL을 리턴하고 errno를 ERANGE로 설정합니다
     * ------------------------------------
     * */


    // [변수 선언 실시]
    double x, y;
    int p;

    x = 1.5;
    p = 5;
    y = ldexp(x,p);


    // [로그 출력 실시]
    //*
    __android_log_print(ANDROID_LOG_WARN, "[C++] [LOG]", "%s", "=====================================================");
    __android_log_print(ANDROID_LOG_INFO, "[C++] [LOG]", "%lf times 2 to the power of %d is %lf\n", x, p, y);
    __android_log_print(ANDROID_LOG_WARN, "[C++] [LOG]", "%s", "=====================================================");
    // */


    return 0;
}
// --------------------------------------------------------------------------------------

[결과 출력]

 

W/[C++] [LOG]: =====================================================
I/[C++] [LOG]: 1.500000 times 2 to the power of 5 is 48.000000
W/[C++] [LOG]: =====================================================

 

반응형
Comments