คณิตศาสตร์#
การแนะนำ#
ส่วนของคณิตศาสตร์นั้นประกอบด้วยฟังก์ชันในตัวของ Python และโมดูล math แบบเต็มรูปแบบ ซึ่งมีให้ใช้งานโดยอัตโนมัติใน VEXcode GO เครื่องมือเหล่านี้ช่วยให้คุณสามารถดำเนินการได้ทุกอย่าง ตั้งแต่การคำนวณเลขคณิตพื้นฐานไปจนถึงตรีโกณมิติขั้นสูง การปัดเศษ และการดำเนินการทางลอการิทึม
ใช้ฟังก์ชันและค่าคงที่เหล่านี้ในการคำนวณตำแหน่ง มุม ระยะทาง และค่าตัวเลขอื่นๆ สำหรับหุ่นยนต์ของคุณ นอกจากนี้ คุณยังสามารถแปลงระหว่างองศาและเรเดียน ประเมินนิพจน์ และทำงานกับค่าพิเศษ เช่น อนันต์และ NaN ได้อีกด้วย
ด้านล่างนี้คือรายการฟังก์ชันทางคณิตศาสตร์ ค่าคงที่ และเครื่องมืออำนวยความสะดวกที่มีให้ใช้งาน:
ฟังก์ชันในตัว – เครื่องมือทางคณิตศาสตร์พื้นฐานที่มีให้ใช้งานใน Python
abs– ส่งคืนค่าสัมบูรณ์ของตัวเลขround– ปัดเศษตัวเลขให้เหลือจำนวนทศนิยมตามที่กำหนดmin– ส่งคืนค่าที่น้อยที่สุดของค่าอินพุตmax– ส่งคืนค่าที่มากที่สุดของค่าที่ป้อนเข้ามาsum– บวกค่าทั้งหมดใน iterabledivmod– คืนค่าผลหารและเศษเหลือเป็นทูเปิลpow– ยกกำลังจำนวนหนึ่ง โดยอาจมีค่าสัมบูรณ์ด้วยint– แปลงค่าเป็นจำนวนเต็มfloat– แปลงค่าเป็นเลขทศนิยม
ค่าคงที่ – ค่าที่กำหนดไว้ล่วงหน้าจากโมดูล math
math.pi– ค่าคงที่ π (พาย)math.tau– ค่าคงที่เทา (2π)math.e– จำนวนของออยเลอร์ ฐานของลอการิทึมธรรมชาติ
ตรีโกณมิติ – การคำนวณมุมและความสัมพันธ์ระหว่างด้านต่างๆ
math.sin– ค่าไซน์ของมุมในหน่วยเรเดียนmath.cos– โคไซน์ของมุมในหน่วยเรเดียนmath.tan– ค่าแทนเจนต์ของมุมในหน่วยเรเดียนmath.atan– อาร์คแทงเจนต์ของค่าในหน่วยเรเดียนmath.atan2– อาร์คแทงเจนต์ของ y/x ในหน่วยเรเดียน โดยพิจารณาควอดแรนต์math.asin– ค่าอาร์คไซน์ของค่าในหน่วยเรเดียนmath.acos– อาร์คโคไซน์ของค่าในหน่วยเรเดียนmath.degrees– แปลงเรเดียนเป็นองศาmath.radians– แปลงองศาเป็นเรเดียน
การปัดเศษและค่าสัมบูรณ์ – ปรับความแม่นยำหรือทิศทาง
math.ceil– ปัดเศษขึ้นเป็นจำนวนเต็มที่ใกล้ที่สุดmath.floor– ปัดเศษลงเป็นจำนวนเต็มที่ใกล้ที่สุดmath.trunc– ลบส่วนทศนิยมออกmath.fabs– ส่งคืนค่าสัมบูรณ์เป็น float
เลขยกกำลังและลอการิทึม – การยกกำลัง ราก และการคำนวณลอการิทึม
math.pow– ยกกำลังจำนวนหนึ่งmath.sqrt– ส่งคืนค่ารากที่สองmath.exp– คำนวณ e ยกกำลัง xmath.log– คำนวณลอการิทึมของ xmath.log10– คำนวณลอการิทึมฐาน 10 ของ x
การคำนวณเลขทศนิยม – ตรวจสอบหรือแยกส่วนค่าเลขทศนิยม
math.modf– คืนค่าส่วนที่เป็นเศษส่วนและส่วนจำนวนเต็มของ floatmath.frexp– แยกตัวเลขออกเป็นส่วนแมนทิสซาและเลขชี้กำลังmath.fmod– เศษเหลือที่มีเครื่องหมายของตัวตั้งหารmath.copysign– ส่งคืนค่าที่มีเครื่องหมายของค่าอื่นmath.ldexp– คำนวณx * (2 ** exp).
ฟังก์ชันในตัว#
Python มีฟังก์ชันในตัวหลายฟังก์ชันที่ช่วยให้คุณสามารถดำเนินการทางคณิตศาสตร์ภายในโปรเจ็กต์ของคุณได้
abs#
abs ส่งคืนค่าสัมบูรณ์ของตัวเลข โดยตัดเครื่องหมายลบออก
Usage:
abs(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
จำนวนเต็มหรือจำนวนทศนิยม |
def main():
# Get the absolute value of -10
abs_result = abs(-10)
console.print(abs_result)
# abs_result = 10
# Start threads — Do not delete
start_thread(main)
round#
round ปัดเศษตัวเลขให้เหลือจำนวนทศนิยมตามที่กำหนด
Usage:
round(x, ndigits)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
จำนวนเต็มหรือจำนวนทศนิยม |
|
ตัวเลือกเสริม จำนวนทศนิยมที่จะปัดเศษ ค่าเริ่มต้นคือ 0 |
def main():
# Round 5.7 to the nearest integer
round_int_result = round(5.7)
console.print(round_int_result)
# round_int_result = 6
# Start threads — Do not delete
start_thread(main)
def main():
# Round 3.14159 to 2 decimal places
round_result = round(3.14159, 2)
console.print(round_result, precision=2)
# round_result = 3.14
# Start threads — Do not delete
start_thread(main)
min#
min ส่งคืนค่าที่เล็กที่สุดจากอาร์กิวเมนต์หลายตัวหรือออบเจ็กต์ที่สามารถวนซ้ำได้
Usage:
min(arg1, arg2, …) or min(sequence)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขสำหรับเปรียบเทียบ |
|
รายการ, ทูเปิล หรือลำดับอื่นๆ ที่ประกอบด้วยตัวเลข |
def main():
# Get the smallest number from 3, 7, and 1
min_result = min(3, 7, 1)
console.print(min_result)
# min_result = 1
# Start threads — Do not delete
start_thread(main)
def main():
# Get the smallest value from a list
min_list_result = min([10, 4, 25, 1])
console.print(min_list_result)
# min_list_result = 1
# Start threads — Do not delete
start_thread(main)
max#
max ส่งคืนค่าที่มากที่สุดจากอาร์กิวเมนต์หลายตัวหรือออบเจ็กต์ที่สามารถวนซ้ำได้
Usage:
max(arg1, arg2, …) or max(sequence)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขสำหรับเปรียบเทียบ |
|
รายการ, ทูเปิล หรือลำดับอื่นๆ ที่ประกอบด้วยตัวเลข |
def main():
# Get the largest number from 3, 7, and 1
max_result = max(3, 7, 1)
console.print(max_result)
# max_result = 7
# Start threads — Do not delete
start_thread(main)
def main():
# Get the largest value from a list
max_list_result = max([10, 4, 25, 1])
console.print(max_list_result)
# max_list_result = 25
# Start threads — Do not delete
start_thread(main)
sum#
sum จะบวกค่าทั้งหมดใน iterable เข้าด้วยกัน โดยสามารถกำหนดค่าเริ่มต้นได้ (ไม่บังคับ)
Usage:
sum(sequence, start)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
รายการ, ทูเปิล หรือลำดับอื่นๆ ที่ประกอบด้วยตัวเลข |
|
ไม่บังคับ ระบุค่าที่จะเพิ่มเข้าไปในผลรวม ค่าเริ่มต้นคือ 0 |
def main():
# Calculate the sum of a list of numbers
sum_result = sum([1, 2, 3, 4, 5])
console.print(sum_result)
# sum_result = 15
# Start threads — Do not delete
start_thread(main)
def main():
# Calculate the sum of a list with a starting value of 10
sum_with_start = sum([1, 2, 3], 10)
console.print(sum_with_start)
# sum_with_start = 16
# Start threads — Do not delete
start_thread(main)
divmod#
divmod ส่งคืนค่าทูเปิลที่มีผลหารและเศษเหลือจากการหาร
Usage:
divmod(a, b)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
เงินปันผล |
|
ตัวหาร |
def main():
# Perform integer division and remainder of 10 / 3
divmod_result = divmod(10, 3)
console.print(divmod_result)
# divmod_result = (3, 1)
# Start threads — Do not delete
start_thread(main)
pow#
pow ยกกำลังตัวเลข และอาจทำการหารเอาเศษด้วยตัวเศษ (modulus) ด้วย
Usage:
pow(x, y, mod)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
เลขฐาน |
|
เลขชี้กำลัง |
|
ไม่บังคับ ค่าโมดูลัส หากระบุ จะคืนค่า |
def main():
# Calculate 2 raised to the power of 3
pow_result = pow(2, 3)
console.print(pow_result)
# pow_result = 8
# Start threads — Do not delete
start_thread(main)
int#
int แปลงตัวเลขหรือสตริงเป็นจำนวนเต็ม นอกจากนี้ยังรองรับการแปลงฐานเมื่อแปลงจากสตริงด้วย
Usage:
int(x, base)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลข สตริง หรือวัตถุอื่นๆ ที่ต้องการแปลง |
|
ตัวเลือกเสริม: ฐานตัวเลขที่จะใช้ในการแปลง ค่าเริ่มต้นคือ 10 |
def main():
# Convert a float to an integer to get rid of decimals
price = 19.99
price_int = int(price)
console.print("{} coins".format(price_int))
# Output: 19 coins
# Start threads — Do not delete
start_thread(main)
def main():
# Convert a string into an integer to use in calculations
user_input = "55"
user_number = int(user_input)
console.print(user_number * 2)
# Output: 110
# Start threads — Do not delete
start_thread(main)
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
โมดูลคณิตศาสตร์#
โมดูล math ใน MicroPython มีเมธอดเพิ่มเติมสำหรับการคำนวณทางคณิตศาสตร์ทั่วไป เมธอดเหล่านี้รวมถึงการคำนวณตรีโกณมิติ ลอการิทึม และการดำเนินการทางตัวเลขอื่นๆ
โมดูล math ถูกนำเข้าโดยค่าเริ่มต้นใน VEXcode
Constants#
ค่าคงที่คือค่าที่กำหนดไว้ล่วงหน้าซึ่งจะคงที่ตลอดโครงการ สามารถนำไปใช้ในการคำนวณได้โดยไม่ต้องกำหนดหรือกำหนดค่าใดๆ เพิ่มเติม
พาย#
pi ให้ค่าคงที่ทางคณิตศาสตร์ π ซึ่งเป็นอัตราส่วนของเส้นรอบวงของวงกลมต่อเส้นผ่านศูนย์กลาง
Usage:
math.pi
def main():
# Calculate the area of a circle with radius 5 using pi
circle_area = math.pi * 5 * 5
console.print(circle_area, precision=2)
# circle_area = 78.54
# Start threads — Do not delete
start_thread(main)
เทา#
tau ให้ค่าเท่ากับ 2π
Usage:
math.tau
def main():
# Calculate the circumference of a circle with radius
circumference = math.tau * 5
console.print(circumference, precision=2)
# circumference = 31.42
# Start threads — Do not delete
start_thread(main)
อี#
e คือฐานของลอการิทึมธรรมชาติ
Usage:
math.e
def main():
# Calculate e raised to the power of 2
e_power = math.pow(math.e, 2)
console.print(e_power, precision=2)
# e_power = 7.39
# Start threads — Do not delete
start_thread(main)
Trigonometry#
บาป#
sin คำนวณค่าไซน์ของมุมในหน่วยเรเดียนและส่งคืนค่าทศนิยม
Usage:
math.sin(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ค่าทศนิยมหรือจำนวนเต็มที่แสดงมุมในหน่วยเรเดียน |
def main():
# Calculate the sine of
# 30 degrees in radians
result = math.sin(math.radians(30))
console.print(result, precision=2)
# result = 0.50
# Start threads — Do not delete
start_thread(main)
คอส#
cos คำนวณค่าโคไซน์ของมุมในหน่วยเรเดียนและส่งคืนค่าทศนิยม
Usage:
math.cos(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ค่าทศนิยมหรือจำนวนเต็มที่แสดงมุมในหน่วยเรเดียน |
def main():
# Calculate the cosine of
# 60 degrees in radians
result = math.cos(math.radians(60))
console.print(result, precision=2)
# result = 0.50
# Start threads — Do not delete
start_thread(main)
แทน#
tan คำนวณค่าแทนเจนต์ของมุมในหน่วยเรเดียนและส่งคืนค่าจำนวนเต็ม
Usage:
math.tan(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ค่าทศนิยมหรือจำนวนเต็มที่แสดงมุมในหน่วยเรเดียน |
def main():
# Calculate the tangent of
# 45 degrees in radians
result = math.tan(math.radians(45))
console.print(result)
# result = 1
# Start threads — Do not delete
start_thread(main)
อาสิน#
asin คำนวณค่าผกผันของไซน์ (arc sine) ของตัวเลข และส่งคืนค่าจำนวนเต็มที่แสดงมุมในหน่วยเรเดียน
Usage:
math.asin(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขทศนิยมหรือจำนวนเต็มระหว่าง -1 ถึง 1 |
def main():
# Calculate the arc sine
# of 0.5 in degrees
result = math.degrees(math.asin(0.5))
console.print(result)
# result = 30
# Start threads — Do not delete
start_thread(main)
อะคอส#
acos คำนวณค่าโคไซน์ผกผัน (อาร์คโคไซน์) ของตัวเลข และส่งคืนค่าจำนวนเต็มที่แสดงมุมในหน่วยเรเดียน
Usage:
math.acos(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขทศนิยมหรือจำนวนเต็มระหว่าง -1 ถึง 1 |
def main():
# Calculate the arc cosine
# of 0.5 in degrees
result = math.degrees(math.acos(0.5))
console.print(result)
# result = 60
# Start threads — Do not delete
start_thread(main)
อาตัน#
atan คำนวณค่าแทนเจนต์ผกผัน (อาร์คแทนเจนต์) ของตัวเลข และส่งคืนค่าจำนวนเต็มที่แสดงมุมในหน่วยเรเดียน
Usage:
math.atan(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขทศนิยมหรือจำนวนเต็ม |
def main():
# Calculate the arc tangent
# of 1 in degrees
arc_tan = math.atan(1.0)
result = math.degrees(arc_tan)
console.print(result)
# result = 45
# Start threads — Do not delete
start_thread(main)
อะตัน2#
atan2 คำนวณค่าหลักของแทนเจนต์ผกผันของ y/x และส่งคืนค่าทศนิยมที่แสดงมุมในหน่วยเรเดียน
Usage:
math.atan2(y, x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ค่าทศนิยมหรือจำนวนเต็มที่แสดงค่าพิกัดแกน y |
|
ค่าทศนิยมหรือจำนวนเต็มที่แสดงพิกัด x |
def main():
# Calculate the inverse tangent
# of 1/1 in degrees
atan2 = math.atan2(1.0, 1.0)
result = math.degrees(atan2)
console.print(result)
# result = 45
# Start threads — Do not delete
start_thread(main)
ปริญญา#
degrees แปลงมุมจากเรเดียนเป็นองศาและส่งคืนค่าจำนวนเต็ม
Usage:
math.degrees(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ค่าทศนิยมหรือจำนวนเต็มที่แสดงมุมในหน่วยเรเดียน |
def main():
# Convert pi radians to degrees
degrees_result = math.degrees(math.pi)
console.print(degrees_result)
# degrees_result = 180
# Start threads — Do not delete
start_thread(main)
เรเดียน#
radians แปลงมุมจากองศาเป็นเรเดียน
Usage:
math.radians(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขทศนิยมหรือจำนวนเต็มที่แสดงค่ามุมในหน่วยองศา |
def main():
# Convert 180 degrees to radians
radians_result = math.radians(180)
console.print(radians_result, precision=2)
# radians_result = 3.14
# Start threads — Do not delete
start_thread(main)
Rounding & Absolute Values#
เพดาน#
ceil จะปัดเศษตัวเลขขึ้นเป็นจำนวนเต็มที่ใกล้ที่สุด
Usage:
math.ceil(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขทศนิยมหรือจำนวนเต็มที่จะปัดขึ้น |
def main():
# Round 3.7 up to the nearest integer
ceil_result = math.ceil(3.7)
console.print(ceil_result)
# ceil_result = 4
# Start threads — Do not delete
start_thread(main)
พื้น#
floor จะปัดเศษตัวเลขลงให้เป็นจำนวนเต็มที่ใกล้ที่สุด
Usage:
math.floor(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขทศนิยมหรือจำนวนเต็มที่จะปัดลง |
def main():
# Round 3.7 down to the nearest integer
floor_result = math.floor(3.7)
console.print(floor_result)
# floor_result = 3
# Start threads — Do not delete
start_thread(main)
ลำต้น#
trunc จะลบส่วนทศนิยมของตัวเลขโดยไม่ปัดเศษ
Usage:
math.trunc(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ค่าทศนิยมที่จะถูกตัดทิ้ง |
def main():
# Remove the decimal part of 3.7
trunc_result = math.trunc(3.7)
console.print(trunc_result)
# trunc_result = 3
# Start threads — Do not delete
start_thread(main)
แฟบส์#
fabs ส่งคืนค่าสัมบูรณ์ของตัวเลขในรูปแบบทศนิยม
Usage:
math.fabs(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขทศนิยมหรือจำนวนเต็ม |
def main():
# Get the absolute value of -3.7
fabs_result = math.fabs(-3.7)
console.print(fabs_result, precision=1)
# fabs_result = 3.7
# Start threads — Do not delete
start_thread(main)
Exponents & Logarithms#
บันทึก#
log คำนวณค่าลอการิทึมของตัวเลขและส่งคืนค่าทศนิยม
Usage:
math.log(x, base)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขทศนิยมหรือจำนวนเต็มบวก |
|
ตัวเลือกเสริม: ฐานของลอการิทึมที่จะใช้ โดยค่าเริ่มต้นคือลอการิทึมธรรมชาติ |
def main():
# Calculate the natural logarithm
# (base e) of 7.389056
log_result = math.log(7.389056)
console.print(log_result)
# log_result = 2
# Start threads — Do not delete
start_thread(main)
def main():
# Calculate the log base 2 of 8
log_result = math.log(8, 2)
console.print(log_result)
# log_result = 3
# Start threads — Do not delete
start_thread(main)
ล็อก10#
log10 คำนวณลอการิทึมฐาน 10 ของตัวเลขและส่งคืนค่าทศนิยม
Usage:
math.log10(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขทศนิยมหรือจำนวนเต็มบวก |
def main():
# Calculate the base-10 logarithm of 100
log10_result = math.log10(100)
console.print(log10_result)
# log10_result = 2
# Start threads — Do not delete
start_thread(main)
พลัง#
pow ยกกำลัง x ด้วย y และส่งคืนค่าทศนิยม แม้ว่าอินพุตทั้งสองจะเป็นจำนวนเต็มก็ตาม
Usage:
math.pow(x, y)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ฐานเป็นจำนวนทศนิยมหรือจำนวนเต็ม |
|
เลขชี้กำลังแบบทศนิยมหรือจำนวนเต็ม |
def main():
# Calculate 2 raised to the power of 3
power_result = math.pow(2, 3)
console.print(power_result)
# power_result = 8
# Start threads — Do not delete
start_thread(main)
รากที่สอง#
sqrt คำนวณรากที่สองของจำนวนและส่งคืนค่าทศนิยม แม้กระทั่งสำหรับกำลังสองสมบูรณ์
Usage:
math.sqrt(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขทศนิยมหรือจำนวนเต็มที่ไม่ติดลบ |
def main():
# Calculate 2 raised to the power of 3
power_result = math.pow(2, 3)
console.print(power_result)
# power_result = 8
# Start threads — Do not delete
start_thread(main)
เอ็กซ์#
exp คำนวณค่าเลขยกกำลังของตัวเลขและส่งคืนค่าทศนิยม
Usage:
math.exp(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขทศนิยมหรือจำนวนเต็ม |
def main():
# Calculate e raised to the power of 1
exp_result = math.exp(1)
console.print(exp_result, precision=2)
# exp_result = 2.72
# Start threads — Do not delete
start_thread(main)
Floating Point Operations#
ม็อดเอฟ#
modf แยกตัวเลขออกเป็นส่วนทศนิยมและส่วนจำนวนเต็ม และส่งคืนทูเปิล (fractional part, integer part)โดยทั้งสองส่วนเป็นค่าทศนิยม
Usage:
math.modf(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขทศนิยมหรือจำนวนเต็มที่จะใช้ในการแยกวิเคราะห์ |
def main():
# Decompose 3.14159 into fractional and integer parts
fractional_part, integer_part = math.modf(3.14159)
console.print(fractional_part, precision=2)
console.new_line()
console.print(integer_part)
# fractional_part = 0.14
# integer_part = 3
# Start threads — Do not delete
start_thread(main)
เฟร็กซ์#
frexp แยกตัวเลขออกเป็นส่วนแมนทิสซาและเลขชี้กำลัง แล้วส่งคืนทูเปิล (mantissa, exponent)โดยที่แมนทิสซาเป็นเลขทศนิยม และเลขชี้กำลังเป็นจำนวนเต็ม
Usage:
math.frexp(x)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ตัวเลขทศนิยมหรือจำนวนเต็มที่จะใช้ในการแยกวิเคราะห์ |
def main():
# Decompose 16 into its mantissa and exponent
mantissa, exponent = math.frexp(16)
console.print(mantissa, precision=2)
console.new_line()
console.print(exponent)
# mantissa = 0.50
# exponent = 5
# Start threads — Do not delete
start_thread(main)
เอฟมอด#
fmod จะคืนค่าเศษเหลือจากการหารโดยคงเครื่องหมายของตัวตั้งหารไว้ (x)
Usage:
math.fmod(x, y)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
เงินปันผล |
|
ตัวหาร |
def main():
# Calculate remainder of 10 / 3
# that preserves the sign of 10
fmod_result = math.fmod(10, 3)
console.print(fmod_result)
# fmod_result = 1
# Start threads — Do not delete
start_thread(main)
ลายเซ็นสำเนา#
copysign ส่งคืน x ด้วยเครื่องหมายของ y.
Usage:
math.copysign(x, y)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ค่าที่ต้องการแก้ไข |
|
ค่าที่เครื่องหมายจะถูกคัดลอก |
def main():
# Return -10 with the sign of 3 (positive)
copysign_result = math.copysign(-10, 3)
console.print(copysign_result)
# copysign_result = 10
# Start threads — Do not delete
start_thread(main)
ldexp#
ldexp คำนวณ x * (2 ** exp)ซึ่งเทียบเท่ากับ x * 2exp
Usage:
math.ldexp(x, exp)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
ค่าพื้นฐาน |
|
เลขชี้กำลัง |
def main():
# Compute 3 * (2 ** 4)
ldexp_result = math.ldexp(3, 4)
console.print(ldexp_result)
# ldexp_result = 48
# Start threads — Do not delete
start_thread(main)