Μαθηματικά#
Εισαγωγή#
Math includes both built-in Python functions and the full math module, which is automatically available in VEXcode AIM. These tools allow you to perform everything from basic arithmetic to advanced trigonometry, rounding, and logarithmic operations.
Χρησιμοποιήστε αυτές τις συναρτήσεις και τις σταθερές για να υπολογίσετε θέσεις, γωνίες, αποστάσεις και άλλες αριθμητικές τιμές για το ρομπότ σας. Μπορείτε επίσης να μετατρέψετε μεταξύ μοιρών και ακτινίων, να αξιολογήσετε εκφράσεις και να εργαστείτε με ειδικές τιμές όπως το άπειρο και το NaN.
Παρακάτω είναι μια λίστα με τις διαθέσιμες μαθηματικές συναρτήσεις, σταθερές και βοηθητικά προγράμματα:
Ενσωματωμένες συναρτήσεις – Κοινά μαθηματικά εργαλεία που περιλαμβάνονται στην Python.
abs– Returns the absolute value of a number.round– Rounds a number to a specified number of decimal places.min– Returns the smallest of the input values.max– Returns the largest of the input values.sum– Adds up all values in an iterable.divmod– Returns the quotient and remainder as a tuple.pow– Raises a number to a power, optionally with a modulus.int– Converts a value to an integer.float– Converts a value to a floating-point number.
Constants – Predefined values from the math module.
math.pi– The constant π (pi).math.tau– The constant tau (2π).math.e– Euler’s number, base of the natural log.math.inf– Positive infinity.math.nan– Not a Number (NaN).
Τριγωνομετρία – Υπολογισμός γωνιών και σχέσεων μεταξύ πλευρών.
math.sin– Sine of an angle in radians.math.cos– Cosine of an angle in radians.math.tan– Tangent of an angle in radians.math.atan– Arctangent of a value in radians.math.atan2– Arctangent of y/x in radians, considering the quadrant.math.asin– Arcsine of a value in radians.math.acos– Arccosine of a value in radians.math.degrees– Converts radians to degrees.math.radians– Converts degrees to radians.
Υπερβολικές – Προηγμένες τριγωνομετρικές συναρτήσεις.
math.sinh– Hyperbolic sine of a value.math.cosh– Hyperbolic cosine of a value.math.tanh– Hyperbolic tangent of a value.math.asinh– Inverse hyperbolic sine.math.acosh– Inverse hyperbolic cosine.math.atanh– Inverse hyperbolic tangent.
Στρογγυλοποίηση & Απόλυτη Τιμή – Προσαρμογή ακρίβειας ή κατεύθυνσης.
math.ceil– Rounds up to the nearest integer.math.floor– Rounds down to the nearest integer.math.trunc– Removes the decimal portion.math.fabs– Returns the absolute value as a float.
Εκθέτες & Λογάριθμοι – Υπολογισμοί δύναμης, ρίζας και λογαρίθμου.
math.pow– Raises a number to a power.math.sqrt– Returns the square root.math.exp– Calculates e to the power of x.math.log– Natural logarithm (base e).math.log10– Base-10 logarithm.math.log2– Base-2 logarithm.math.factorial– Factorial of an integer.math.expm1– More accurate result fore^x - 1.
Πράξεις κινητής υποδιαστολής – Έλεγχος ή ανάλυση τιμών κινητής υποδιαστολής.
math.modf– Returns the fractional and integer parts of a float.math.frexp– Decomposes a number into mantissa and exponent.math.fmod– Remainder with sign of the dividend.math.copysign– Returns a value with the sign of another.math.ldexp– Computesx * (2 ** exp).
Σύγκριση & Προσέγγιση – Έλεγχος τιμών με ανοχές ή κατηγορίες.
math.isclose– Tests if two values are approximately equal.math.isfinite– Checks if a number is finite.math.isinf– Checks if a number is infinite.math.isnan– Checks if a value is NaN.
Σφάλμα & Γάμμα – Ειδικές μαθηματικές συναρτήσεις.
math.gamma– Gamma function (generalized factorial).math.lgamma– Logarithmic gamma.math.erf– Error function.math.erfc– Complementary error function.
Ενσωματωμένες λειτουργίες#
Η Python παρέχει αρκετές ενσωματωμένες συναρτήσεις που σας επιτρέπουν να εκτελείτε μαθηματικές πράξεις μέσα στο έργο σας.
abs#
abs returns the absolute value of a number, removing any negative sign.
Usage:
abs(x)
Παράμετρος |
Περιγραφή |
|---|---|
|
Ένας ακέραιος αριθμός ή ένας αριθμός με κινητή βάση. |
# Get the absolute value of -10
abs_result = abs(-10)
robot.screen.print(abs_result)
# abs_result = 10
round#
round rounds a number to a specified number of decimal places.
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 returns the smallest value from multiple arguments or an iterable.
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 returns the largest value from multiple arguments or an iterable.
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 adds up all values in an iterable, with an optional starting value.
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 returns a tuple containing the quotient and remainder of a division operation.
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 raises a number to a power and optionally performs a modulus operation.
Usage:
pow(x, y, mod)
Παράμετρος |
Περιγραφή |
|---|---|
|
Ο βασικός αριθμός. |
|
Ο εκθέτης. |
|
Optional. A modulus value. If provided, returns |
# 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 converts a number or string into an integer. It also supports base conversion when converting from a string.
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 converts a number or string into a floating-point number.
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
Μαθηματικά Ενότητα#
The math module in MicroPython provides additional methods for performing common mathematical calculations. These methods include trigonometric, logarithmic, and other numerical operations.
The math module is imported by default in VEXcode.
Constants#
Οι σταθερές είναι προκαθορισμένες τιμές που παραμένουν σταθερές κατά τη διάρκεια ενός έργου. Μπορούν να χρησιμοποιηθούν σε υπολογισμούς χωρίς να απαιτείται ορισμός ή ανάθεση.
πι#
pi gives the mathematical constant π, the ratio of a circle’s circumference to its diameter.
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 gives the value of 2π.
Usage:
math.tau
# Calculate the circumference of a circle with radius
circumference = math.tau * 5
robot.screen.print(circumference)
# circumference = 31.42
μι#
e gives the base of the natural logarithm.
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 gives positive infinity as a float.
Usage:
math.inf
# Check if infinity is infinite
inf_value = math.inf
if math.isinf(inf_value):
robot.screen.print("Infinity")
# Prints "Infinity"
γιαγιά#
nan represents a special float for “Not a Number” (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 calculates the sine of an angle in radians and returns a float.
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 calculates the cosine of an angle in radians and returns a float.
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 calculates the tangent of an angle in radians and returns a float.
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 calculates the inverse tangent (arc tangent) of a number and returns a float representing the angle in radians.
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
atan2#
atan2 calculates the principal value of the inverse tangent of y/x and returns a float representing the angle in radians.
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 calculates the inverse sine (arc sine) of a number and returns a float representing the angle in radians.
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#
acos calculates the inverse cosine (arc cosine) of a number and returns a float representing the angle in radians.
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 converts an angle from radians to 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 converts an angle from degrees to 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 calculates the hyperbolic sine of 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 calculates the hyperbolic cosine of 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 calculates the hyperbolic tangent of 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 calculates the inverse hyperbolic sine of 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 calculates the inverse hyperbolic cosine of 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 calculates the inverse hyperbolic tangent of x.
Usage:
math.atanh(x)
Παράμετρος |
Περιγραφή |
|---|---|
|
Μια κινητή τιμή μεταξύ -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 rounds a number up to the nearest integer.
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 rounds a number down to the nearest integer.
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 removes the decimal part of a number without rounding.
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 returns the absolute value of a number as a float.
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 raises x to the power of y and returns a float, even if both inputs are integers.
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 calculates the square root of a number and returns a float, even for perfect squares.
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 calculates the exponential of a number and returns a float.
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 calculates the natural logarithm of a number and returns a float.
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
log10#
log10 calculates the base-10 logarithm of a number and returns a float.
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 calculates the base-2 logarithm of a number and returns a float, even when x is a power of 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 returns the factorial of an integer x, which is the product of all positive integers up to x.
Usage:
math.factorial(x)
Παράμετρος |
Περιγραφή |
|---|---|
|
Ένας μη αρνητικός ακέραιος αριθμός. |
# Calculate 5 factorial (5!)
factorial_result = math.factorial(5)
robot.screen.print(factorial_result)
# factorial_result = 120
expm1#
expm1 calculates ex - 1, which is more accurate for small 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 decomposes a number into its fractional and integer parts and returns a tuple (fractional part, integer part), both as floats.
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 decomposes a number into its mantissa and exponent and returns a tuple (mantissa, exponent), where the mantissa is a float and the exponent is an integer.
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 returns the remainder of division while keeping the sign of the dividend (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 returns x with the sign of y.
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 computes x * (2 ** exp), which is equivalent to 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 checks if two numbers are approximately equal within a tolerance.
Usage:
math.isclose(a, b, rel_tol, abs_tol)
Παράμετρος |
Περιγραφή |
|---|---|
|
Ο πρώτος αριθμός προς σύγκριση. |
|
Ο δεύτερος αριθμός προς σύγκριση. |
|
Προαιρετικό. Η μέγιστη επιτρεπόμενη διαφορά μεταξύ a και b, σε σχέση με το μέγεθός τους. Η προεπιλογή είναι 1e-09 (πολύ μικρό). |
|
Προαιρετικό. Ένα σταθερό περιθώριο σφάλματος, χρήσιμο κατά τη σύγκριση αριθμών κοντά στο μηδέν. Η προεπιλογή είναι 0,0. |
Note: If both rel_tol and abs_tol are provided, whichever condition is met first determines the result.
# 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 checks if a number is finite. This method returns a Boolean value:
True– The number is finite.False– The number is infinite.
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 checks if a number is infinite. This method returns a Boolean value:
True– The number is infinite.False– The number is finite.
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 checks if a number is NaN (Not a Number). This method returns a Boolean value:
True– The number is NaN.False– The number is a valid number.
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 computes the gamma function of x, which generalizes the factorial function for real and complex numbers. For an integer 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#
lgamma computes the natural logarithm of the gamma function.
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 computes the error function of 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 computes the complementary error function of x, which is defined as 1 - erf(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