파이썬[Python]: decimal - compare_total_mag 메서드

decimal 모듈 - compare_total_mag 메서드(method)


/// 설명

두 Decimal 의 인스턴스 추상화 되어진 표현을 비교합니다.(두 인스턴스에 절대값을 적용합니다.)

참고: compare_total()

※ 형식
Decimal().compare_total_mag(other, context=None)

reference
https://docs.python.org/3/library/decimal.html#module-decimal

/// 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import decimal
 
print(decimal.Decimal('-1').compare_total_mag(decimal.Decimal('1')))  # 0
print(decimal.Decimal('1').compare_total_mag(decimal.Decimal('-1.0')))  # 1
print(decimal.Decimal('-1.0').compare_total_mag(decimal.Decimal('1')))  # -1
print(decimal.Decimal('1e+1').compare_total_mag(decimal.Decimal('-10')))  # 1
print(decimal.Decimal('-10').compare_total_mag(decimal.Decimal('10.0')))  # 1
print(decimal.Decimal('10.0').compare_total_mag(decimal.Decimal('-1e+1')))  # -1
 
print(decimal.Decimal('NaN').compare_total_mag(decimal.Decimal('-1e+1')))  # 1
print(decimal.Decimal('NaN').compare_total_mag(decimal.Decimal('10.0')))  # 1
print(decimal.Decimal('NaN').compare_total_mag(decimal.Decimal('NaN')))  # 0
 
# abs(a) < abs(b)            ---> Decimal('-1')
# abs(a) == abs(b)           ---> Decimal('0')
# abs(a) > abs(b)            ---> Decimal('1')
 
cs

* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

파이썬[Python]: 내장함수 - from_bytes 메서드

파이썬[Python]: 내장함수 - __len__ 메서드

파이썬[Python]: kivy - 한글 사용

파이썬[Python]: 내장함수 - bit_length 메서드

C 언어: sin 함수, cos 함수, tan 함수