수학#
소개#
수학 기능에는 내장 파이썬 함수와 VEXcode AIR에 자동으로 포함되는 math 모듈이 모두 포함되어 있습니다. 이러한 도구를 사용하면 기본적인 산술 연산부터 고급 삼각 함수, 반올림, 로그 연산까지 모든 작업을 수행할 수 있습니다.
이 함수와 상수를 사용하여 VEX AIR 드론 컨트롤러의 위치, 각도, 거리 및 기타 수치 값을 계산할 수 있습니다. 또한 도(degrees)와 라디안(radians) 간 변환, 수식 평가, 무한대(infinity) 및 NaN과 같은 특수 값 처리도 가능합니다.
참고: 명시적으로 달리 언급된 경우를 제외하고, 모든 반환 값은 소수점 다섯 자리까지 정확하게 표시되는 부동 소수점 값입니다. 소수점 다섯 자리보다 많은 자릿수를 가진 값은 반올림되고, 다섯 자리보다 적은 자릿수를 가진 값은 0으로 채워져 항상 정확히 다섯 자리까지 표시됩니다.
다음은 사용 가능한 수학 함수, 상수 및 유틸리티 목록입니다.
내장 함수 – 파이썬에 포함된 일반적인 수학 도구입니다.
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.asin– 라디안 값의 아크사인.math.acos– 라디안 값의 아크코사인.math.atan– 라디안 값의 아크탄젠트.math.atan2– 사분면을 고려하여 라디안의 y/x의 아크탄젠트.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.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)
controller.screen.print(abs_result)
# abs_result = 10
round#
round 은 지정된 소수점 자릿수까지 반올림한 숫자를 정수로 반환합니다.
Usage:
round(x, ndigits)
매개변수 |
설명 |
|---|---|
|
정수 또는 실수. |
|
선택 사항입니다. 소수점 이하 몇 자리까지 반올림할지(0~5자리)를 지정합니다. 기본값은 0입니다. 이 매개변수를 사용하면 |
# Round 5.7 to the nearest integer
round_int_result = round(5.7)
controller.screen.print(round_int_result)
# round_int_result = 6
# Round 3.14159 to 2 decimal places
round_result = round(3.14159, 2)
controller.screen.print(round_result)
# round_result = 3.14000
min#
min 여러 인자 또는 반복 가능한 객체 중에서 가장 작은 값을 반환합니다.
Usage:
min(arg1, arg2, …) or min(sequence)
매개변수 |
설명 |
|---|---|
|
비교할 숫자들. |
|
숫자가 포함된 리스트, 튜플 또는 기타 시퀀스. |
# Get the smallest number from 3, 7, and 1
min_result = min(3, 7, 1)
controller.screen.print(min_result)
# min_result = 1
# Get the smallest value from a list
min_list_result = min([10, 4, 25, 1])
controller.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)
controller.screen.print(max_result)
# max_result = 7
# Get the largest value from a list
max_list_result = max([10, 4, 25, 1])
controller.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])
controller.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)
controller.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)
controller.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)
controller.screen.print(pow_result)
# pow_result = 8
# Calculate (5 ** 3) % 7
pow_mod_result = pow(5, 3, 7)
controller.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)
controller.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)
controller.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
controller.screen.print(apples_per_person)
# Output: 3.00000
# Convert a string into a float to use in calculations
user_input = "23.4"
user_number = float(user_input)
controller.screen.print(user_number * 3)
# Output: 70.20000
수학 모듈#
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
controller.screen.print(circle_area)
# circle_area = 78.53982
타우#
tau 2π의 값을 나타냅니다.
Usage:
math.tau
# Calculate the circumference of a circle with radius
circumference = math.tau * 5
controller.screen.print(circumference)
# circumference = 31.41593
이자형#
e 자연로그의 밑을 나타냅니다.
Usage:
math.e
# Calculate e raised to the power of 2
e_power = math.pow(math.e, 2)
controller.screen.print(e_power)
# e_power = 7.38906
정보#
inf 부동소수점 형식으로 양의 무한대를 나타냅니다.
Usage:
math.inf
# Check if infinity is infinite
inf_value = math.inf
if math.isinf(inf_value):
controller.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):
controller.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))
controller.screen.print(sine_result)
# sine_result = 0.50000
코사인#
cos 라디안 단위 각도의 코사인 값을 계산하여 부동 소수점 값을 반환합니다.
Usage:
math.cos(x)
매개변수 |
설명 |
|---|---|
|
각도를 라디안 단위로 나타내는 부동 소수점 또는 정수입니다. |
# Calculate the cosine of 60 degrees in radians
cosine_result = math.cos(math.radians(60))
controller.screen.print(cosine_result)
# cosine_result = 0.50000
탠 껍질#
tan 라디안 단위 각도의 탄젠트 값을 계산하여 부동 소수점 값을 반환합니다.
Usage:
math.tan(x)
매개변수 |
설명 |
|---|---|
|
각도를 라디안 단위로 나타내는 부동 소수점 또는 정수입니다. |
# Calculate the tangent of 45 degrees in radians
tangent_result = math.tan(math.radians(45))
controller.screen.print(tangent_result)
# tangent_result = 1.00000
아신#
asin 숫자의 역사인(아크사인) 값을 계산하고 라디안 단위의 각도를 나타내는 부동 소수점 값을 반환합니다.
Usage:
math.asin(x)
매개변수 |
설명 |
|---|---|
|
-1과 1 사이의 부동 소수점 또는 정수. |
# Calculate the arc sine of 0.5 in radians
arc_sine_result = math.asin(0.5)
controller.screen.print(arc_sine_result)
# arc_sine_result = 0.52360
아코스#
`acos 는 숫자의 역코사인(아크코사인) 값을 계산하고, 그 값을 라디안 단위의 부동소수점 값으로 반환합니다.
Usage:
>math.acos(x)
매개변수 |
설명 |
|---|---|
|
-1과 1 사이의 부동 소수점 또는 정수. |
# Calculate the arc cosine of 0.5 in radians
arc_cosine_result = math.acos(0.5)
controller.screen.print(arc_cosine_result)
# arc_cosine_result = 1.04720
아탄#
atan 함수는 숫자의 역탄젠트(호탄젠트) 값을 계산하고, 그 값을 라디안 단위의 부동소수점 값으로 반환합니다.
Usage:
math.atan(x)
매개변수 |
설명 |
|---|---|
|
실수 또는 정수. |
# Calculate the arc tangent of 1 in radians
arc_tangent_result = math.atan(1)
controller.screen.print(arc_tangent_result)
# arc_tangent_result = 0.78540
아탄2#
atan2 y/x의 역탄젠트의 주값을 계산하고 라디안 단위의 각도를 나타내는 부동 소수점을 반환합니다.
Usage:
math.atan2(y, x)
매개변수 |
설명 |
|---|---|
|
y 좌표를 나타내는 실수 또는 정수입니다. |
|
x 좌표를 나타내는 실수 또는 정수입니다. |
# Calculate the inverse tangent of (4, 3) in radians
atan2_result = math.atan2(3, 4)
controller.screen.print(atan2_result)
# atan2_result = 0.64350
학위#
degrees 각도를 라디안에서 도로 변환합니다.
Usage:
math.degrees(x)
매개변수 |
설명 |
|---|---|
|
라디안 단위의 각도를 나타내는 실수 또는 정수입니다. |
# Convert pi radians to degrees
degrees_result = math.degrees(math.pi)
controller.screen.print(degrees_result)
# degrees_result = 180.00000
라디안#
radians 각도를 도에서 라디안으로 변환합니다.
Usage:
math.radians(x)
매개변수 |
설명 |
|---|---|
|
각도를 도 단위로 나타내는 실수 또는 정수입니다. |
# Convert 180 degrees to radians
radians_result = math.radians(180)
controller.screen.print(radians_result)
# radians_result = 3.14159
Hyperbolics#
신#
sinh x 의 쌍곡선 사인 값을 계산합니다.
Usage:
math.sinh(x)
매개변수 |
설명 |
|---|---|
|
입력값을 나타내는 부동 소수점 또는 정수입니다. |
# Calculate the hyperbolic sine of 1
sinh_result = math.sinh(1)
controller.screen.print(sinh_result)
# sinh_result = 1.7520
곤봉#
cosh x 의 쌍곡 코사인을 계산합니다.
Usage:
math.cosh(x)
매개변수 |
설명 |
|---|---|
|
입력값을 나타내는 부동 소수점 또는 정수입니다. |
# Calculate the hyperbolic cosine of 1
cosh_result = math.cosh(1)
controller.screen.print(cosh_result)
# cosh_result = 1.54308
탄#
tanh x 의 쌍곡선 탄젠트를 계산합니다.
Usage:
math.tanh(x)
매개변수 |
설명 |
|---|---|
|
입력값을 나타내는 부동 소수점 또는 정수입니다. |
# Calculate the hyperbolic tangent of 1
tanh_result = math.tanh(1)
controller.screen.print(tanh_result)
# tanh_result = 0.76159
아신#
asinh x 의 역 쌍곡선 사인을 계산합니다.
Usage:
math.asinh(x)
매개변수 |
설명 |
|---|---|
|
입력값을 나타내는 부동 소수점 또는 정수입니다. |
# Calculate the inverse hyperbolic sine of 1
asinh_result = math.asinh(1)
controller.screen.print(asinh_result)
# asinh_result = 0.88137
아코쉬#
acosh x 의 역 쌍곡 코사인을 계산합니다.
Usage:
math.acosh(x)
매개변수 |
설명 |
|---|---|
|
1보다 크거나 같은 부동 소수점 또는 정수. |
# Calculate the inverse hyperbolic cosine of 2
acosh_result = math.acosh(2)
controller.screen.print(acosh_result)
# acosh_result = 1.31696
아탄#
atanh x 의 역 쌍곡선 탄젠트를 계산합니다.
Usage:
math.atanh(x)
매개변수 |
설명 |
|---|---|
|
-1과 1 사이의 부동 소수점 값(-1과 1은 제외). |
# Calculate the inverse hyperbolic tangent of 0.5
atanh_result = math.atanh(0.5)
controller.screen.print(atanh_result)
# atanh_result = 0.54931
Rounding & Absolute Values#
천장#
ceil 은 숫자를 가장 가까운 정수로 올림합니다.
Usage:
math.ceil(x)
매개변수 |
설명 |
|---|---|
|
반올림할 부동 소수점 또는 정수입니다. |
# Round 3.7 up to the nearest integer
ceil_result = math.ceil(3.7)
controller.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)
controller.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)
controller.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)
controller.screen.print(fabs_result)
# fabs_result = 3.70000
Exponents & Logarithms#
파워#
pow x 을 y (xy) 제곱하고 float를 반환합니다.
Usage:
math.pow(x, y)
매개변수 |
설명 |
|---|---|
|
부동소수점 또는 정수형을 밑으로 합니다. |
|
부동 소수점 또는 정수 지수. |
# Calculate 2 raised to the power of 3
power_result = math.pow(2, 3)
controller.screen.print(power_result)
# power_result = 8.00000
제곱근#
sqrt 숫자의 제곱근을 계산하고 부동 소수점 값을 반환합니다.
Usage:
math.sqrt(x)
매개변수 |
설명 |
|---|---|
|
음수가 아닌 부동소수점 숫자 또는 정수. |
# Calculate the square root of 16
sqrt_result = math.sqrt(16)
controller.screen.print(sqrt_result)
# sqrt_result = 4.00000
exp#
exp 은 x (ex)의 거듭제곱으로 e를 반환하고 부동 소수점입니다.
Usage:
math.exp(x)
매개변수 |
설명 |
|---|---|
|
실수 또는 정수. |
# Calculate e raised to the power of 1
exp_result = math.exp(1)
controller.screen.print(exp_result)
# exp_result = 2.71828
통나무#
log 숫자의 자연 로그를 계산하고 부동 소수점 값을 반환합니다.
Usage:
math.log(x)
매개변수 |
설명 |
|---|---|
|
양의 부동 소수점 또는 정수. |
# Calculate the natural logarithm (base e) of 7.389056
log_result = math.log(7.389056)
controller.screen.print(log_result)
# log_result = 2.00000
로그10#
log10 숫자의 밑이 10인 로그 값을 계산하고 부동 소수점 값을 반환합니다.
Usage:
math.log10(x)
매개변수 |
설명 |
|---|---|
|
양의 부동 소수점 또는 정수. |
# Calculate the base-10 logarithm of 1000
log10_result = math.log10(1000)
controller.screen.print(log10_result)
# log10_result = 3.00000
로그2#
log2 숫자의 밑이 2인 로그를 계산하고 x가 2의 거듭제곱인 경우에도 부동 소수점을 반환합니다.
Usage:
math.log2(x)
매개변수 |
설명 |
|---|---|
|
양의 부동 소수점 또는 정수. |
# Calculate the base-2 logarithm of 8
log2_result = math.log2(8)
controller.screen.print(log2_result)
# log2_result = 3.00000
계승#
factorial 정수 x의 팩토리얼을 반환합니다. 이는 x 까지의 모든 양의 정수의 곱입니다.
Usage:
math.factorial(x)
매개변수 |
설명 |
|---|---|
|
음수가 아닌 정수. |
# Calculate 5 factorial (5!)
factorial_result = math.factorial(5)
controller.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)
controller.screen.print(expm1_result)
# expm1_result = 1.71828
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)
controller.screen.print(fractional_part)
controller.screen.next_row()
controller.screen.print(integer_part)
# fractional_part = 0.14159
# integer_part = 3.00000
프렉스#
frexp 숫자를 가수와 지수로 분해하고 가수가 부동 소수점이고 지수가 정수인 튜플 (mantissa, exponent)을 반환합니다.
Usage:
math.frexp(x)
매개변수 |
설명 |
|---|---|
|
분해할 부동 소수점 또는 정수입니다. |
# Decompose 16 into its mantissa and exponent
mantissa, exponent = math.frexp(16)
controller.screen.print(mantissa)
controller.screen.next_row()
controller.screen.print(exponent)
# mantissa = 0.50000
# 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)
controller.screen.print(fmod_result)
# fmod_result = 1.00000
저작권 표시#
copysign y 의 부호를 가진 x를 반환합니다.
Usage:
math.copysign(x, y)
매개변수 |
설명 |
|---|---|
|
수정할 값입니다. |
|
부호가 복사될 값입니다. |
# Return -10 with the sign of 3 (positive)
copysign_result = math.copysign(-10, 3)
controller.screen.print(copysign_result)
# copysign_result = 10.00000
ldexp#
ldexp x * (2 ** exp)계산하는데, 이는 x * 2exp 과 같습니다.
Usage:
math.ldexp(x, exp)
매개변수 |
설명 |
|---|---|
|
기본값. |
|
지수. |
# Compute 3 * (2 ** 4)
ldexp_result = math.ldexp(3, 4)
controller.screen.print(ldexp_result)
# ldexp_result = 48.00000
Comparison & Approximation#
무한하다#
isfinite 숫자가 유한한지 확인합니다. 이 메서드는 부울 값을 반환합니다.
True- 숫자는 유한합니다.False- 숫자는 무한합니다.
Usage:
math.isfinite(x)
매개변수 |
설명 |
|---|---|
|
확인할 부동 소수점 또는 정수입니다. |
# Check if 42 is a finite number (returns True)
is_finite_true = math.isfinite(42)
controller.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)
controller.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)
controller.screen.print(is_inf_true)
# is_inf_true = True
# Check if 42 is an infinite number (returns False)
is_inf_false = math.isinf(42)
controller.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)
controller.screen.print(is_nan_true)
# is_nan_true = True
# Check if 42 is NaN (returns False)
is_nan_false = math.isnan(42)
controller.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)
controller.screen.print(gamma_result)
# gamma_result = 24.00000
이감마#
lgamma gamma 함수의 자연로그를 계산합니다.
Usage:
math.lgamma(x)
매개변수 |
설명 |
|---|---|
|
양의 부동 소수점 또는 정수. |
# Calculate the natural logarithm of the
# gamma function of 5
lgamma_result = math.lgamma(5)
controller.screen.print(lgamma_result)
# lgamma_result = 3.17805
erf#
erf x 의 오차 함수를 계산합니다.
Usage:
math.erf(x)
매개변수 |
설명 |
|---|---|
|
입력값을 나타내는 부동 소수점 또는 정수입니다. |
# Calculate the error function of 1
erf_result = math.erf(1)
controller.screen.print(erf_result)
# erf_result = 0.84270
erfc#
erfc 1 - erf(x) 로 정의되는 x의 보완 오차 함수를 계산합니다.
Usage:
math.erfc(x)
매개변수 |
설명 |
|---|---|
|
입력값을 나타내는 부동 소수점 또는 정수입니다. |
# Calculate the complementary error function of 1
erfc_result = math.erfc(1)
controller.screen.print(erfc_result)
# erfc_result = 0.15730