카테고리

asm (27) bootloader_x86_grub (1) C (92) compile (11) config (76) CPP (13) CSS (1) debugging (7) gimp (1) Go (1) html (1) Java (1) JavaScript (1) kernel (19) LibreOffice (3) Linux system progamming (21) MFC (1) opencv (4) OpenGL (1) PHP (1) Python (4) qemu (29) shell (3) socket (7) troubleshooting (2) ubuntu18.04 (2) windows (1)

2018/12/06

CPP Floating_type 실수 연산

#include <iostream>
#include <iomanip>
using namespace std;

int main() {
// 실수 연산는 컴퓨터 연산시 오차를 가진다.
// 오차를 최소화 하기 위해 실수 연산을 사용한다.

float fValue = 76.4;

cout << fValue << endl;

cout << "size of fValue " << sizeof(float) << endl;
cout << scientific << fValue << endl; // 지수 표현
cout << fixed << fValue << endl; // 부동 소수점 기본 6자리수 표시
cout << setprecision(20) << fixed << fValue << endl; // 부동 소수점 20 자리 지정

// 실수 연산는 컴퓨터 연산시 오차를 가진다. 검증
double dValue = 76.4;
cout << setprecision(20) << fixed << dValue << endl; // 부동 소수점 20 자리 지정

// 실수 연산는 컴퓨터 연산시 오차를 가진다. 검증
long double lValue = 123.456789876543210;
cout << setprecision(20) << fixed << lValue << endl;
cout << "size of long double " << sizeof(lValue) << endl;

return 0;
}

댓글 없음:

댓글 쓰기