ShovelingLife
A Game Programmer
ShovelingLife
전체 방문자
오늘
어제
  • 분류 전체보기 (1074) N
    • 그래픽스 (57)
      • 공통 (19)
      • 수학 물리 (22)
      • OpenGL & Vulkan (1)
      • DirectX (14)
    • 게임엔진 (183)
      • Unreal (69)
      • Unity (103)
      • Cocos2D-X (3)
      • 개인 플젝 (8)
    • 코딩테스트 (221)
      • 공통 (7)
      • 프로그래머스 (22)
      • 백준 (162)
      • LeetCode (19)
      • HackerRank (2)
      • 코딩테스트 알고리즘 (8)
    • CS (235)
      • 공통 (21)
      • 네트워크 (44)
      • OS & 하드웨어 (55)
      • 자료구조 & 알고리즘 (98)
      • 디자인패턴 (6)
      • UML (4)
      • 데이터베이스 (7)
    • 프로그래밍 언어 (349) N
      • C++ (168) N
      • C# (90)
      • Java (9)
      • Python (33)
      • SQL (30)
      • JavaScript (8)
      • React (7)
    • 그 외 (10) N
      • Math (5)
      • 일상 (5)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

  • Source Code 좌측 상단에 복사 버튼 추가 완료
  • 언리얼 엔진 C++ 빌드시간 단축 꿀팁
  • 게임 업계 코딩테스트 관련
  • 1인칭 시점으로 써내려가는 글들

인기 글

태그

  • 알고리즘
  • 배열
  • string
  • 티스토리챌린지
  • 프로그래머스
  • 함수
  • 언리얼
  • C++
  • C
  • 백준
  • SQL
  • 포인터
  • 그래픽스
  • 오블완
  • Unity
  • c#
  • 파이썬
  • 유니티
  • 클래스
  • 문자열

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
ShovelingLife

A Game Programmer

프로그래밍 언어/C++

[C++] 쓰레기값 거르기(아주 작은값) numeric_limits

2023. 9. 16. 15:22

numeric_limits 클래스

template <class Type>
    class numeric_limits

epsilon

함수는 1과 데이터 형식에 대해 나타낼 수 있는 1보다 큰 가장 작은 값 사이의 차이를 반환

// numeric_limits_epsilon.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "The difference between 1 and the smallest "
        << "value greater than 1" << endl
        << "for float objects is: "
        << numeric_limits<float>::epsilon( ) << endl;
   cout << "The difference between 1 and the smallest "
        << "value greater than 1" << endl
        << "for double objects is: "
        << numeric_limits<double>::epsilon( ) << endl;
   cout << "The difference between 1 and the smallest "
        << "value greater than 1" << endl
        << "for long double objects is: "
        << numeric_limits<long double>::epsilon( ) << endl;
}

 

결과

The difference between 1 and the smallest value greater than 1
for float objects is: 1.19209e-007
The difference between 1 and the smallest value greater than 1
for double objects is: 2.22045e-016
The difference between 1 and the smallest value greater than 1
for long double objects is: 2.22045e-016

 

사용 예시

float f_tmp;
if(fabsf(f_tmp) < std::numeric_limits<float>::epsilon()) return;

 

https://kinggodrobotics.tistory.com/1

저작자표시 (새창열림)

'프로그래밍 언어 > C++' 카테고리의 다른 글

[C] open, close, read 함수에 대하여  (0) 2023.09.17
[C] 이스케이프 문자(Escape Character)  (0) 2023.09.16
[C] 쓰레기값과 초기화  (0) 2023.09.16
[C++] sort , stable_sort  (0) 2023.09.16
[C] gets 함수는 사용하지 말아야 한다.  (0) 2023.09.10
    '프로그래밍 언어/C++' 카테고리의 다른 글
    • [C] open, close, read 함수에 대하여
    • [C] 이스케이프 문자(Escape Character)
    • [C] 쓰레기값과 초기화
    • [C++] sort , stable_sort
    ShovelingLife
    ShovelingLife
    Main skill stack => Unity C# / Unreal C++ Studying Front / BackEnd, Java Python

    티스토리툴바