개발

[ChatGPT가 알려주는] overflow, underflow 파이썬 예시

2024. 2. 19. 21:10
목차
  1. 1. Overflow
  2. 2. Underflow

Overflow and underflow are two concepts that refer to the limits of numerical representation in computing. They can happen in various programming contexts, including in Python, especially when dealing with floating-point numbers or integers that exceed the maximum or minimum size that can be represented.

 

1. Overflow

Overflow occurs when a calculation produces a result that is larger than the maximum value that can be represented in the allocated space. In Python, integers(int) are arbitrary-precision, meaning they can grow to accommodate any number as long as your machine's memory can handle it. However, overflow is still relevant in the context of fixed-size data types such as floating-point numbers(float) and when using external libraries that rely on C or other languages where integers have fixed sizes.

import sys
import math

# Trying to represent an extremely large floating-point number
# Close to the maximum float
large_number = 1.79e308  

# This will result in 'inf', indicating overflow
print(large_number * 10)  

>>>> inf

 

2. Underflow

Underflow occurs when a calculation produces a result closer to zero than the smallest value that can be represented in the allocated space. In Python, this is most commonly seen with floating-point numbers when the result of a calculation is so close to zero that it cannot be represented accurately, leading to a loss of precision.

# Very small difference
small_number = 1e-323

# This will result in 0.0, indicating underflow
print(small_number / 10)  

>>>> 0.0

 

 

 

[출처]

  • ChatGPT(https://chat.openai.com/share/574c905d-e642-467b-b144-74a7c438d94b)

 

 

728x90
저작자표시 비영리 변경금지 (새창열림)

'개발' 카테고리의 다른 글

[websocket] (1) python websocket 서버 생성 & 클라이언트 테스트  (0) 2024.02.28
[ubuntu] mpi4py 설치 시 에러  (0) 2024.02.23
[ubuntu] nohup 파일 생성 시 현재 날짜로 생기게 하기  (0) 2024.02.15
[ubuntu] crontab 사용법 간단정리  (1) 2024.02.10
[ubuntu] 좀비 프로세스 죽이기(defunct)  (1) 2024.01.13
  1. 1. Overflow
  2. 2. Underflow
'개발' 카테고리의 다른 글
  • [websocket] (1) python websocket 서버 생성 & 클라이언트 테스트
  • [ubuntu] mpi4py 설치 시 에러
  • [ubuntu] nohup 파일 생성 시 현재 날짜로 생기게 하기
  • [ubuntu] crontab 사용법 간단정리
Fine애플
Fine애플
이것저것
Fine애플
끄적끄적
Fine애플
전체
오늘
어제
  • 분류 전체보기 (167)
    • 논문 및 개념 정리 (27)
    • Pattern Recognition (8)
    • 개발 (57)
    • python 메모 (45)
    • pytorch, tensorflow (5)
    • 알고리즘 (9)
    • Toy Projects (4)
    • 통계이론 (2)
    • Reinforcement Learning (10)

블로그 메뉴

  • 홈

공지사항

인기 글

태그

  • pandas
  • 개발환경
  • 자연어
  • 언어모델
  • 딥러닝
  • nlp
  • transformer
  • Bert
  • miniconda
  • PyTorch
  • reinforcement learning
  • tensorflow
  • python
  • 알고리즘
  • Docker
  • GPU
  • Probability
  • BigBird
  • container
  • ubuntu

최근 댓글

최근 글

hELLO · Designed By 정상우.
Fine애플
[ChatGPT가 알려주는] overflow, underflow 파이썬 예시
상단으로

티스토리툴바

개인정보

  • 티스토리 홈
  • 포럼
  • 로그인

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.