수학#
소개#
수학 기능에는 내장 파이썬 함수와 VEXcode AIM에서 자동으로 사용 가능한 math 모듈이 모두 포함되어 있습니다. 이러한 도구를 사용하면 기본 산술 연산부터 고급 삼각 함수, 반올림 및 로그 연산에 이르기까지 모든 작업을 수행할 수 있습니다.
이 함수와 상수를 사용하여 로봇의 위치, 각도, 거리 및 기타 수치 값을 계산할 수 있습니다. 또한 도(degrees)와 라디안(radians) 간 변환, 수식 평가, 무한대(infinity) 및 NaN과 같은 특수 값 처리도 가능합니다.
다음은 사용 가능한 수학 함수, 상수 및 유틸리티 목록입니다.
내장 함수 – 파이썬에 포함된 일반적인 수학 도구입니다.
abs– 숫자의 절댓값을 반환합니다.round– 숫자를 지정된 소수 자릿수로 반올림합니다.min– 입력값 중 가장 작은 값을 반환합니다.max– 입력 값 중 가장 큰 값을 반환합니다.sum– 반복 가능한 모든 값을 더합니다.divmod– 몫과 나머지를 튜플로 반환합니다.pow– 선택적으로 모듈러스를 사용하여 숫자를 거듭제곱합니다.int– 값을 정수로 변환합니다.float– 값을 부동 소수점 숫자로 변환합니다.
상수 – math 모듈에서 미리 정의된 값입니다.
math.pi– 상수 π(파이).math.tau– 상수 tau(2π).math.e– 오일러 수, 자연로그의 밑.math.inf– 양의 무한대.math.nan– 숫자가 아님(NaN).
삼각법 – 각도를 계산하고 변 사이의 관계를 파악합니다.
math.sin– 라디안의 각도의 사인.math.cos– 라디안의 각도의 코사인.math.tan– 라디안의 각도의 탄젠트.math.atan– 라디안 값의 아크탄젠트.math.atan2– 사분면을 고려하여 라디안의 y/x의 아크탄젠트.math.asin– 라디안 값의 아크사인.math.acos– 라디안 값의 아크코사인.math.degrees– 라디안을 도로 변환합니다.math.radians– 도를 라디안으로 변환합니다.
Hyperbolics – Advanced trig-related functions.
math.sinh– 값의 쌍곡선 사인.math.cosh– 값의 쌍곡 코사인.math.tanh– 값의 쌍곡 탄젠트.math.asinh– 역 쌍곡선 사인.math.acosh– 역 쌍곡 코사인.math.atanh– 역 쌍곡선 탄젠트.
반올림 및 절댓값 – 정밀도 또는 방향을 조정합니다.
math.ceil– 가장 가까운 정수로 반올림합니다.math.floor– 가장 가까운 정수로 내림합니다.math.trunc– 소수 부분을 제거합니다.math.fabs– 절대값을 부동소수점으로 반환합니다.
지수와 로그 - 거듭제곱, 제곱근, 로그 계산
math.pow– 숫자를 거듭제곱합니다.math.sqrt– 제곱근을 반환합니다.math.exp– e의 x제곱을 계산합니다.math.log– 자연로그(밑 e).math.log10– 밑이 10인 로그.math.log2– 밑이 2인 로그.math.factorial– 정수의 팩토리얼.math.expm1–e^x - 1에 대한 더 정확한 결과.
부동 소수점 연산 – 부동 소수점 값을 검사하거나 분해합니다.
math.modf– 부동 소수점의 소수 부분과 정수 부분을 반환합니다.math.frexp– 숫자를 가수와 지수로 분해합니다.math.fmod– 피제수의 부호가 있는 나머지.math.copysign– 다른 값의 부호를 가진 값을 반환합니다.math.ldexp–x * (2 ** exp)계산합니다.
비교 및 근사치 – 허용 오차 또는 범주를 사용하여 값을 확인하십시오.
math.isclose– 두 값이 대략적으로 같은지 테스트합니다.math.isfinite– 숫자가 유한한지 확인합니다.math.isinf– 숫자가 무한대인지 확인합니다.math.isnan– 값이 NaN인지 확인합니다.
오차 및 감마 - 특수 수학 함수.
math.gamma– 감마 함수(일반화된 팩토리얼).math.lgamma– 로그 감마.math.erf– 오류 함수.math.erfc– 보완 오류 함수.
내장 함수#
파이썬은 프로젝트 내에서 수학 연산을 수행할 수 있도록 여러 가지 내장 함수를 제공합니다.
abs#
abs 숫자의 절댓값을 반환하며, 음수 부호를 제거합니다.
Usage:
abs(x)
매개변수 |
설명 |
|---|---|
|
정수 또는 실수. |
# Get the absolute value of -10
abs_result = abs(-10)
robot.screen.print(abs_result)
# abs_result = 10
round#
round 숫자를 지정된 소수점 자릿수까지 반올림합니다.
Usage:
round(x, ndigits)
매개변수 |
설명 |
|---|---|
|
정수 또는 실수. |
|
선택 사항입니다. 소수점 이하 자릿수를 지정합니다. 기본값은 0입니다. |
# Round 5.7 to the nearest integer
round_int_result = round(5.7)
robot.screen.print(round_int_result)
# round_int_result = 6
# Round 3.14159 to 2 decimal places
round_result = round(3.14159, 2)
robot.screen.print(round_result)
# round_result = 3.14
min#
min 여러 인자 또는 반복 가능한 객체 중에서 가장 작은 값을 반환합니다.
Usage:
min(arg1, arg2, …) or min(sequence)
매개변수 |
설명 |
|---|---|
|
비교할 숫자들. |
|
숫자가 포함된 리스트, 튜플 또는 기타 시퀀스. |
# Get the smallest number from 3, 7, and 1
min_result = min(3, 7, 1)
robot.screen.print(min_result)
# min_result = 1
# Get the smallest value from a list
min_list_result = min([10, 4, 25, 1])
robot.screen.print(min_list_result)
# min_list_result = 1
max#
max 여러 인자 또는 반복 가능한 객체 중에서 가장 큰 값을 반환합니다.
Usage:
max(arg1, arg2, …) or max(sequence)
매개변수 |
설명 |
|---|---|
|
비교할 숫자들. |
|
숫자가 포함된 리스트, 튜플 또는 기타 시퀀스. |
# Get the largest number from 3, 7, and 1
max_result = max(3, 7, 1)
robot.screen.print(max_result)
# max_result = 7
# Get the largest value from a list
max_list_result = max([10, 4, 25, 1])
robot.screen.print(max_list_result)
# max_list_result = 25
sum#
sum 하고, 선택적으로 시작 값을 지정하여 반복 가능한 객체의 모든 값을 더합니다.
Usage:
sum(sequence, start)
매개변수 |
설명 |
|---|---|
|
숫자가 포함된 리스트, 튜플 또는 기타 시퀀스. |
|
선택 사항입니다. 합계에 더할 값입니다. 기본값은 0입니다. |
# Calculate the sum of a list of numbers
sum_result = sum([1, 2, 3, 4, 5])
robot.screen.print(sum_result)
# sum_result = 15
# Calculate the sum of a list with a starting value of 10
sum_with_start = sum([1, 2, 3], 10)
robot.screen.print(sum_with_start)
# sum_with_start = 16
divmod#
divmod 나눗셈 연산의 몫과 나머지를 포함하는 튜플을 반환합니다.
Usage:
divmod(a, b)
매개변수 |
설명 |
|---|---|
|
배당금. |
|
제수. |
# Perform integer division and remainder of 10 / 3
divmod_result = divmod(10, 3)
robot.screen.print(divmod_result)
# divmod_result = (3, 1)
pow#
pow 숫자를 거듭제곱하고 선택적으로 나머지 연산을 수행합니다.
Usage:
pow(x, y, mod)
매개변수 |
설명 |
|---|---|
|
기본 숫자. |
|
지수. |
|
선택 사항입니다. 나머지 값입니다. 제공된 경우 |
# Calculate 2 raised to the power of 3
pow_result = pow(2, 3)
robot.screen.print(pow_result)
# pow_result = 8
# Calculate (5 ** 3) % 7
pow_mod_result = pow(5, 3, 7)
robot.screen.print(pow_mod_result)
# pow_mod_result = 6
int#
int 숫자 또는 문자열을 정수로 변환합니다. 문자열에서 정수로 변환할 때 진법 변환도 지원합니다.
Usage:
int(x, base)
매개변수 |
설명 |
|---|---|
|
변환할 숫자, 문자열 또는 기타 객체입니다. |
|
선택 사항입니다. 변환에 사용할 진법입니다. 기본값은 10입니다. |
# Convert a float to an integer to get rid of decimals
price = 19.99
price_int = int(price)
robot.screen.print(f"{price_int} coins")
# Output: 19 coins
# Convert a string into an integer to use in calculations
user_input = "55"
user_number = int(user_input)
robot.screen.print(user_number * 2)
# Output: 110
float#
float 은 숫자 또는 문자열을 부동 소수점 숫자로 변환합니다.
Usage:
float(x)
매개변수 |
설명 |
|---|---|
|
변환할 숫자, 문자열 또는 기타 객체입니다. |
# Convert division result to a float
num_apples = 6
num_people = 2
apples_per_person = float(num_apples) / num_people
robot.screen.print(apples_per_person)
# Output: 3.00
# Convert a string into a float to use in calculations
user_input = "23.4"
user_number = float(user_input)
robot.screen.print(user_number * 3)
# Output: 70.20
수학 모듈#
MicroPython의 math 모듈은 일반적인 수학 계산을 수행하기 위한 추가 메서드를 제공합니다. 이러한 메서드에는 삼각 함수, 로그 함수 및 기타 수치 연산이 포함됩니다.
VEXcode에서는 math 모듈이 기본적으로 임포트됩니다.
Constants#
상수는 프로젝트 기간 동안 고정된 상태로 유지되는 미리 정의된 값입니다. 상수는 별도의 정의나 할당 없이 계산에 사용할 수 있습니다.
파이#
pi 원의 둘레와 지름의 비율인 수학 상수 π를 나타냅니다.
Usage:
math.pi
# Calculate the area of a circle with radius 5 using pi
circle_area = math.pi * 5 * 5
robot.screen.print(circle_area)
# circle_area = 78.54
타우#
tau 2π의 값을 나타냅니다.
Usage:
math.tau
# Calculate the circumference of a circle with radius
circumference = math.tau * 5
robot.screen.print(circumference)
# circumference = 31.42
이자형#
e 자연로그의 밑을 나타냅니다.
Usage:
math.e
# Calculate e raised to the power of 2
e_power = math.pow(math.e, 2)
robot.screen.print(e_power)
# e_power = 7.39
정보#
inf 부동소수점 형식으로 양의 무한대를 나타냅니다.
Usage:
math.inf
# Check if infinity is infinite
inf_value = math.inf
if math.isinf(inf_value):
robot.screen.print("Infinity")
# Prints "Infinity"
난#
nan “숫자가 아님”(NaN)을 나타내는 특수 부동 소수점 값입니다.
Usage:
math.nan
# Check if nan is Not a Number
nan_value = math.nan
if math.isnan(nan_value):
robot.screen.print("Not a Number")
# Prints "Not a Number"
Trigonometry#
죄#
sin 함수는 라디안 단위 각도의 사인 값을 계산하여 부동 소수점 값으로 반환합니다.
Usage:
math.sin(x)
매개변수 |
설명 |
|---|---|
|
라디안 단위의 각도를 나타내는 실수 또는 정수입니다. |
# Calculate the sine of 30 degrees in radians
sine_result = math.sin(math.radians(30))
robot.screen.print(sine_result)
# sine_result = 0.50
코사인#
cos 라디안 단위 각도의 코사인 값을 계산하여 부동 소수점 값을 반환합니다.
Usage:
math.cos(x)
매개변수 |
설명 |
|---|---|
|
라디안 단위의 각도를 나타내는 실수 또는 정수입니다. |
# Calculate the cosine of 60 degrees in radians
cosine_result = math.cos(math.radians(60))
robot.screen.print(cosine_result)
# cosine_result = 0.50
탠 껍질#
tan 라디안 단위 각도의 탄젠트 값을 계산하여 부동 소수점 값을 반환합니다.
Usage:
math.tan(x)
매개변수 |
설명 |
|---|---|
|
라디안 단위의 각도를 나타내는 실수 또는 정수입니다. |
# Calculate the tangent of 45 degrees in radians
tangent_result = math.tan(math.radians(45))
robot.screen.print(tangent_result)
# tangent_result = 1.00
아탄#
atan 함수는 숫자의 역탄젠트(호탄젠트) 값을 계산하고, 그 값을 라디안 단위의 부동소수점 값으로 반환합니다.
Usage:
math.atan(x)
매개변수 |
설명 |
|---|---|
|
실수 또는 정수. |
# Calculate the arc tangent of 1 in degrees
arc_tangent_result = math.degrees(math.atan(1.0))
robot.screen.print(arc_tangent_result)
# arc_tangent_result = 45.00
아탄2#
atan2 y/x의 역탄젠트의 주값을 계산하고 라디안 단위의 각도를 나타내는 부동 소수점을 반환합니다.
Usage:
math.atan2(y, x)
매개변수 |
설명 |
|---|---|
|
y좌표를 나타내는 실수 또는 정수입니다. |
|
x좌표를 나타내는 실수 또는 정수입니다. |
# Calculate the inverse tangent of 1/1 in degrees
atan2_result = math.degrees(math.atan2(1.0, 1.0))
robot.screen.print(atan2_result)
# atan2_result = 45.00
아신#
asin 숫자의 역사인(아크사인) 값을 계산하고 라디안 단위의 각도를 나타내는 부동 소수점 값을 반환합니다.
Usage:
math.asin(x)
매개변수 |
설명 |
|---|---|
|
-1과 1 사이의 부동 소수점 또는 정수. |
# Calculate the arc sine of 0.5 in degrees
arc_sine_result = math.degrees(math.asin(0.5))
robot.screen.print(arc_sine_result)
# arc_sine_result = 30.00
아코스#
`acos 는 숫자의 역코사인(아크코사인) 값을 계산하고, 그 값을 라디안 단위의 부동소수점 값으로 반환합니다.
Usage:
math.acos(x)
매개변수 |
설명 |
|---|---|
|
-1과 1 사이의 부동 소수점 또는 정수. |
# Calculate the arc cosine of 0.5 in degrees
arc_cosine_result = math.degrees(math.acos(0.5))
robot.screen.print(arc_cosine_result)
# arc_cosine_result = 60.00
학위#
degrees 각도를 라디안에서 도로 변환합니다.
Usage:
math.degrees(x)
매개변수 |
설명 |
|---|---|
|
라디안 단위의 각도를 나타내는 실수 또는 정수입니다. |
# Convert pi radians to degrees
degrees_result = math.degrees(math.pi)
robot.screen.print(degrees_result)
# degrees_result = 180.00
라디안#
radians 각도를 도에서 라디안으로 변환합니다.
Usage:
math.radians(x)
매개변수 |
설명 |
|---|---|
|
각도를 도 단위로 나타내는 실수 또는 정수입니다. |
# Convert 180 degrees to radians
radians_result = math.radians(180)
robot.screen.print(radians_result)
# radians_result = 3.14
Hyperbolics#
신#
sinh x 의 쌍곡선 사인 값을 계산합니다.
Usage:
math.sinh(x)
매개변수 |
설명 |
|---|---|
|
입력값을 나타내는 부동 소수점 또는 정수입니다. |
# Calculate the hyperbolic sine of 1
sinh_result = math.sinh(1)
robot.screen.print(sinh_result)
# sinh_result = 1.18
곤봉#
cosh x 의 쌍곡 코사인을 계산합니다.
Usage:
math.cosh(x)
매개변수 |
설명 |
|---|---|
|
입력값을 나타내는 부동 소수점 또는 정수입니다. |
# Calculate the hyperbolic cosine of 1
cosh_result = math.cosh(1)
robot.screen.print(cosh_result)
# cosh_result = 1.54
탄#
tanh x 의 쌍곡선 탄젠트를 계산합니다.
Usage:
math.tanh(x)
매개변수 |
설명 |
|---|---|
|
입력값을 나타내는 부동 소수점 또는 정수입니다. |
# Calculate the hyperbolic tangent of 1
tanh_result = math.tanh(1)
robot.screen.print(tanh_result)
# tanh_result = 0.76
아신#
asinh x 의 역 쌍곡선 사인을 계산합니다.
Usage:
math.asinh(x)
매개변수 |
설명 |
|---|---|
|
입력값을 나타내는 부동 소수점 또는 정수입니다. |
# Calculate the inverse hyperbolic sine of 1
asinh_result = math.asinh(1)
robot.screen.print(asinh_result)
# asinh_result = 0.88
아코쉬#
acosh x 의 역 쌍곡 코사인을 계산합니다.
Usage:
math.acosh(x)
매개변수 |
설명 |
|---|---|
|
1보다 크거나 같은 부동 소수점 또는 정수. |
# Calculate the inverse hyperbolic cosine of 2
acosh_result = math.acosh(2)
robot.screen.print(acosh_result)
# acosh_result = 1.32
아탄#
atanh x 의 역 쌍곡선 탄젠트를 계산합니다.
Usage:
math.atanh(x)
매개변수 |
설명 |
|---|---|
|
-1과 1 사이의 부동 소수점 값(-1과 1은 제외). |
# Calculate the inverse hyperbolic tangent of 0.5
atanh_result = math.atanh(0.5)
robot.screen.print(atanh_result)
# atanh_result = 0.55
Rounding & Absolute Values#
천장#
ceil 은 숫자를 가장 가까운 정수로 올림합니다.
Usage:
math.ceil(x)
매개변수 |
설명 |
|---|---|
|
반올림할 부동 소수점 또는 정수입니다. |
# Round 3.7 up to the nearest integer
ceil_result = math.ceil(3.7)
robot.screen.print(ceil_result)
# ceil_result = 4
바닥#
floor 은 숫자를 가장 가까운 정수로 내림합니다.
Usage:
math.floor(x)
매개변수 |
설명 |
|---|---|
|
반올림할 부동 소수점 또는 정수입니다. |
# Round 3.7 down to the nearest integer
floor_result = math.floor(3.7)
robot.screen.print(floor_result)
# floor_result = 3
잘린 부분#
trunc 은 반올림 없이 숫자의 소수 부분을 제거합니다.
Usage:
math.trunc(x)
매개변수 |
설명 |
|---|---|
|
소수점 이하 자릿수가 잘릴 수 있는 값입니다. |
# Remove the decimal part of 3.7
trunc_result = math.trunc(3.7)
robot.screen.print(trunc_result)
# trunc_result = 3
팹스#
fabs 은 숫자의 절댓값을 부동 소수점으로 반환합니다.
Usage:
math.fabs(x)
매개변수 |
설명 |
|---|---|
|
실수 또는 정수. |
# Get the absolute value of -3.7
fabs_result = math.fabs(-3.7)
robot.screen.print(fabs_result)
# fabs_result = 3.70
Exponents & Logarithms#
파워#
pow 은 x를 y제곱하고 두 입력값이 모두 정수이더라도 부동소수점을 반환합니다.
Usage:
math.pow(x, y)
매개변수 |
설명 |
|---|---|
|
부동소수점 또는 정수형을 밑으로 합니다. |
|
부동 소수점 또는 정수 지수. |
# Calculate 2 raised to the power of 3
power_result = math.pow(2, 3)
robot.screen.print(power_result)
# power_result = 8.00
제곱근#
sqrt 은 숫자의 제곱근을 계산하고 완전제곱수인 경우에도 부동소수점을 반환합니다.
Usage:
math.sqrt(x)
매개변수 |
설명 |
|---|---|
|
음수가 아닌 부동소수점 숫자 또는 정수. |
# Calculate the square root of 16
sqrt_result = math.sqrt(16)
robot.screen.print(sqrt_result)
# sqrt_result = 4.00
exp#
exp 숫자의 지수를 계산하고 부동 소수점을 반환합니다.
Usage:
math.exp(x)
매개변수 |
설명 |
|---|---|
|
실수 또는 정수. |
# Calculate e raised to the power of 1
exp_result = math.exp(1)
robot.screen.print(exp_result)
# exp_result = 2.72
통나무#
log 숫자의 자연 로그를 계산하고 부동 소수점 값을 반환합니다.
Usage:
math.log(x)
매개변수 |
설명 |
|---|---|
|
양의 부동 소수점 또는 정수. |
# Calculate the natural logarithm (base e) of 7.389056
log_result = math.log(7.389056)
robot.screen.print(log_result)
# log_result = 2.00
로그10#
log10 숫자의 밑이 10인 로그 값을 계산하고 부동 소수점 값을 반환합니다.
Usage:
math.log10(x)
매개변수 |
설명 |
|---|---|
|
양의 부동 소수점 또는 정수. |
# Calculate the base-10 logarithm of 1000
log10_result = math.log10(1000)
robot.screen.print(log10_result)
# log10_result = 3.00
로그2#
log2 숫자의 밑이 2인 로그 값을 계산하고, x 2의 거듭제곱인 경우에도 부동 소수점을 반환합니다.
Usage:
math.log2(x)
매개변수 |
설명 |
|---|---|
|
양의 부동 소수점 또는 정수. |
# Calculate the base-2 logarithm of 8
log2_result = math.log2(8)
robot.screen.print(log2_result)
# log2_result = 3.00
계승#
factorial 정수 x의 팩토리얼을 반환합니다. 이는 x 까지의 모든 양의 정수의 곱입니다.
Usage:
math.factorial(x)
매개변수 |
설명 |
|---|---|
|
음수가 아닌 정수. |
# Calculate 5 factorial (5!)
factorial_result = math.factorial(5)
robot.screen.print(factorial_result)
# factorial_result = 120
실험1#
expm1 ex - 1를 계산하는데, 이는 작은 x 에 대해 더 정확합니다.
Usage:
math.expm1(x)
매개변수 |
설명 |
|---|---|
|
지수 값. |
# Compute expm1(1) (e^1 - 1)
expm1_result = math.expm1(1)
robot.screen.print(expm1_result)
# expm1_result = 1.72
Floating Point Operations#
모드#
modf 숫자를 소수 부분과 정수 부분으로 분해하고 튜플 (fractional part, integer part)모두 부동 소수점으로 반환합니다.
Usage:
math.modf(x)
매개변수 |
설명 |
|---|---|
|
분해할 부동 소수점 또는 정수입니다. |
# Decompose 3.14159 into fractional and integer parts
fractional_part, integer_part = math.modf(3.14159)
robot.screen.print(fractional_part)
robot.screen.next_row()
robot.screen.print(integer_part)
# fractional_part = 0.14
# integer_part = 3.00
프렉스#
frexp 숫자를 가수와 지수로 분해하고 가수가 부동 소수점이고 지수가 정수인 튜플 (mantissa, exponent)을 반환합니다.
Usage:
math.frexp(x)
매개변수 |
설명 |
|---|---|
|
분해할 부동 소수점 또는 정수입니다. |
# Decompose 16 into its mantissa and exponent
mantissa, exponent = math.frexp(16)
robot.screen.print(mantissa)
robot.screen.next_row()
robot.screen.print(exponent)
# mantissa = 0.50
# exponent = 5
fmod#
fmod 피제수의 부호를 유지하면서 나눗셈의 나머지를 반환합니다(x).
Usage:
math.fmod(x, y)
매개변수 |
설명 |
|---|---|
|
배당금. |
|
제수. |
# Calculate remainder of 10 / 3
# that preserves the sign of 10
fmod_result = math.fmod(10, 3)
robot.screen.print(fmod_result)
# fmod_result = 1.00
저작권 표시#
copysign y 의 부호를 가진 x를 반환합니다.
Usage:
math.copysign(x, y)
매개변수 |
설명 |
|---|---|
|
수정할 값입니다. |
|
부호가 복사될 값입니다. |
# Return -10 with the sign of 3 (positive)
copysign_result = math.copysign(-10, 3)
robot.screen.print(copysign_result)
# copysign_result = 10.00
ldexp#
ldexp x * (2 ** exp)계산하며 이는 x * 2exp{code} 과 같습니다.
Usage:
math.ldexp(x, exp)
매개변수 |
설명 |
|---|---|
|
기본값. |
|
지수. |
# Compute 3 * (2 ** 4)
ldexp_result = math.ldexp(3, 4)
robot.screen.print(ldexp_result)
# ldexp_result = 48.00
Comparison & Approximation#
이즈클로즈#
isclose 두 숫자가 허용 오차 범위 내에서 대략적으로 같은지 확인합니다.
Usage:
math.isclose(a, b, rel_tol, abs_tol)
매개변수 |
설명 |
|---|---|
|
비교할 첫 번째 숫자입니다. |
|
비교할 두 번째 숫자입니다. |
|
선택 사항입니다. a와 b 사이의 최대 허용 차이(크기에 대한 상대적 차이). 기본값은 1e-09(매우 작음)입니다. |
|
선택 사항입니다. 0에 가까운 숫자를 비교할 때 유용한 고정 오차 범위입니다. 기본값은 0.0입니다. |
참고: rel_tol 과 abs_tol 이 모두 제공된 경우, 먼저 충족되는 조건이 결과에 영향을 미칩니다.
# Check if 1.000000001 and 1.0 are close
# within the default tolerance
isclose_result = math.isclose(1.000000001, 1.0)
robot.screen.print(isclose_result)
# isclose_result = True
# Check if 0.0000001 and 0.0 are close
# using absolute tolerance
isclose_result = math.isclose(0.0000001, 0.0, abs_tol=1e-07)
robot.screen.print(isclose_result)
# isclose_result = True
# Check if 1000000.0 and 1000000.1 are close
# with a stricter tolerance
isclose_result = math.isclose(1000000.0, 1000000.1, rel_tol=1e-10)
robot.screen.print(isclose_result)
# isclose_result = False
무한하다#
isfinite 숫자가 유한한지 확인합니다. 이 메서드는 부울 값을 반환합니다.
True– 숫자는 유한합니다.False– 숫자는 무한합니다.
Usage:
math.isfinite(x)
매개변수 |
설명 |
|---|---|
|
확인할 부동 소수점 또는 정수입니다. |
# Check if 42 is a finite number (returns True)
is_finite_true = math.isfinite(42)
robot.screen.print(is_finite_true)
# is_finite_true = True
# Check if infinity is a finite number (returns False)
is_finite_false = math.isfinite(math.inf)
robot.screen.print(is_finite_false)
# is_finite_false = False
isinf#
isinf 무한대인지 확인합니다. 이 메서드는 부울 값을 반환합니다.
True– 숫자는 무한합니다.False– 숫자는 유한합니다.
Usage:
math.isinf(x)
매개변수 |
설명 |
|---|---|
|
확인할 부동 소수점 또는 정수입니다. |
# Check if infinity is an infinite number (returns True)
is_inf_true = math.isinf(math.inf)
robot.screen.print(is_inf_true)
# is_inf_true = True
# Check if 42 is an infinite number (returns False)
is_inf_false = math.isinf(42)
robot.screen.print(is_inf_false)
# is_inf_false = False
이스난#
isnan (숫자가 아님)인지 확인합니다. 이 메서드는 부울 값을 반환합니다.
True– 해당 숫자는 NaN입니다.False– 해당 숫자는 유효한 숫자입니다.
Usage:
math.isnan(x)
매개변수 |
설명 |
|---|---|
|
확인할 부동 소수점 또는 정수입니다. |
# Check if NaN (Not a Number) is NaN (returns True)
is_nan_true = math.isnan(math.nan)
robot.screen.print(is_nan_true)
# is_nan_true = True
# Check if 42 is NaN (returns False)
is_nan_false = math.isnan(42)
robot.screen.print(is_nan_false)
# is_nan_false = False
Error and Gamma Calculations#
감마#
gamma 실수와 복소수에 대한 팩토리얼 함수를 일반화한 x의 감마 함수를 계산합니다. 정수 n, gamma(n) = (n-1)!.
Usage:
math.gamma(x)
매개변수 |
설명 |
|---|---|
|
양의 부동 소수점 또는 정수. |
# Calculate the gamma function of 5 (equivalent to 4!)
gamma_result = math.gamma(5)
robot.screen.print(gamma_result)
# gamma_result = 24.00
이감마#
lgamma gamma 함수의 자연로그를 계산합니다.
Usage:
math.lgamma(x)
매개변수 |
설명 |
|---|---|
|
양의 부동 소수점 또는 정수. |
# Calculate the natural logarithm of the
# gamma function of 5
lgamma_result = math.lgamma(5)
robot.screen.print(lgamma_result)
# lgamma_result = 3.18
erf#
erf x 의 오차 함수를 계산합니다.
Usage:
math.erf(x)
매개변수 |
설명 |
|---|---|
|
입력값을 나타내는 부동 소수점 또는 정수입니다. |
# Calculate the error function of 1
erf_result = math.erf(1)
robot.screen.print(erf_result)
# erf_result = 0.84
erfc#
erfc 1 - erf(x) 로 정의되는 x의 보완 오차 함수를 계산합니다.
Usage:
math.erfc(x)
매개변수 |
설명 |
|---|---|
|
입력값을 나타내는 부동 소수점 또는 정수입니다. |
# Calculate the complementary error function of 1
erfc_result = math.erfc(1)
robot.screen.print(erfc_result)
# erfc_result = 0.16