org.pycforge.math · Author: PyCForge
License: GPL-3.0-only · Created: 2026-10-28
Runtime conversion · Direct declared calls
Using this import · Functions · Conversion contract · Worked examples
acos · acosh · asin · asinh · atan · atan2 · atanh · cbrt · ceil · comb · copysign · cos · cosh · degrees · dist · erf · erfc · exp · exp2 · expm1 · fabs · factorial · floor · fmod · fsum · gcd · hypot · isclose · isfinite · isinf · isnan · isqrt · lcm · log · log10 · log1p · log2 · nextafter · perm · pow · radians · remainder · sin · sinh · sqrt · sumprod · tan · tanh · trunc · ulp
Fifty mathematical functions and five binary64 constants. Use integer math for exact counts and factors, and floating-point math for measurements.
Select Runtime. Declare *import math as m at the top of the module, then use direct calls such as m.sin(0.0) or constants such as m.pi. Trigonometric input angles are radians. Use m.log(8, 2) for base-two logarithms and m.isclose(a=1.0, b=1.0000000001, rel_tol=1e-9) for tolerance comparisons. See each signature below.
This package covers only the listed exports and call shapes. log takes one or two positional arguments. isclose accepts named a/b and keyword-only rel_tol/abs_tol; nextafter accepts keyword-only steps on Python 3.12+; other exports remain positional-only. sumprod, fsum and dist accept lists, tuples and ranges of bool, int64 and float64. Iterators, unpacked calls and NumPy arrays are outside this sequence profile. Exact integer functions accept int64 and Boolean operands. A float raises TypeError, a negative counting argument raises ValueError, and a final integer outside signed int64 raises OverflowError. floor, ceil and trunc also return bounded int64. Native libm results depend on the compiler and platform; cross-platform bit identity and NaN payload identity are not promised. Runtime remains a preview target.
0.8.0 adds isqrt, gcd, lcm, comb, perm and factorial. For a selection of three from twelve, comb(12, 3) gives 220 possible groups and perm(12, 3) gives 1320 possible finishing orders.
Use *import math in the module preamble. Each signature states accepted positions, names and defaults. A slash marks positional-only parameters; a star marks keyword-only parameters. Argument expansion, function values and Typed conversion are unsupported.
Sequence operations accept a list, tuple or range of bool, signed int64 and float64 values. Each function below identifies its accepted inputs.
Inputs: bool, signed int64 or float64. The exact integer kernels use integer arithmetic. Floating-point kernels use binary64 C double. Wrong runtime value types raise TypeError; runtime exceptions remain catchable. C11 math.h, default rounding, no fast-math; POSIX linking uses -lm. No arrays or arbitrary-precision results.
Inverse cosine; input from -1 through 1
Argument labels indicate positions; they are not accepted keyword names.
Input domain: First operand outside [-1, 1] raises ValueError; NaN passes.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Inverse cosine; input from -1 through 1. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Cosine value in the closed interval [-1, 1].
Returns: Principal inverse cosine in radians.
Inverse hyperbolic cosine; input at least 1
Argument labels indicate positions; they are not accepted keyword names.
Input domain: First operand below 1 raises ValueError; NaN passes.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Inverse hyperbolic cosine; input at least 1. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Hyperbolic cosine value at least one.
Returns: Nonnegative inverse hyperbolic cosine.
Inverse sine; input from -1 through 1
Argument labels indicate positions; they are not accepted keyword names.
Input domain: First operand outside [-1, 1] raises ValueError; NaN passes.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Inverse sine; input from -1 through 1. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Sine value in the closed interval [-1, 1].
Returns: Principal inverse sine in radians.
Inverse hyperbolic sine
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Inverse hyperbolic sine. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Hyperbolic sine value.
Returns: Inverse hyperbolic sine.
Inverse tangent
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Inverse tangent. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Tangent value.
Returns: Principal inverse tangent in radians.
Angle of the vector (second input, first input)
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Angle of the vector (second input, first input). The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Vertical coordinate y.
Argument 2: Horizontal coordinate x.
Returns: Angle in radians with the quadrant determined by both coordinates.
Inverse hyperbolic tangent; input strictly between -1 and 1
Argument labels indicate positions; they are not accepted keyword names.
Input domain: First operand outside (-1, 1) raises ValueError; NaN passes.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Inverse hyperbolic tangent; input strictly between -1 and 1. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Hyperbolic tangent value strictly between -1 and 1.
Returns: Inverse hyperbolic tangent.
Real cube root
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Real cube root. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Number whose real cube root is requested.
Returns: Real cube root, with negative roots for negative inputs.
Smallest integer no less than input; result must fit int64
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Result must fit signed int64; nonfinite or out-of-range results raise an exception.
Existing bool/int64 operands retain their exact integer value.
Smallest integer no less than input; result must fit int64. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Number to round upward.
Returns: Smallest integer no less than the input, within signed int64.
Number of unordered selections without repetition
n: positional-only; required
k: positional-only; required
Count unordered selections of k from n distinct items. Counts must be nonnegative. Return zero when k exceeds n.
Accepts signed int64 and Boolean operands. Float operands raise TypeError. An exact result above 9223372036854775807 raises OverflowError.
Number of unordered selections without repetition. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Number of distinct items, a nonnegative integer.
Argument 2: Number chosen without repetition, a nonnegative integer.
Returns: Number of unordered selections. Choosing zero gives 1. Choosing more than n gives 0.
Magnitude of the first input with the sign of the second
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: direct native result after the declared input guards.
Magnitude of the first input with the sign of the second. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Number supplying the magnitude.
Argument 2: Number supplying the sign, including the sign of zero.
Returns: Magnitude of the first argument with the sign of the second.
Cosine in radians
Argument labels indicate positions; they are not accepted keyword names.
Input domain: Either infinity in the first operand raises ValueError; NaN passes.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Cosine in radians. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Angle in radians.
Returns: Cosine of the angle.
Hyperbolic cosine with overflow checking
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Hyperbolic cosine with overflow checking. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Hyperbolic angle.
Returns: Hyperbolic cosine.
Convert radians to degrees
x: positional-only; required
Multiply by binary64 180/pi. Overflow yields signed infinity; signed zero is preserved.
Convert radians to degrees. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Angle in radians.
Returns: Angle in degrees, preserving signed zero. A magnitude beyond binary64 range becomes infinity.
Euclidean distance between two equal-dimensional points
p: positional-only; required
q: positional-only; required
Euclidean distance between two equally long lists, tuples or ranges of real coordinates. Unequal lengths raise ValueError. Infinite differences take precedence over NaN after checking all coordinates.
Euclidean distance between two equal-dimensional points. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: First point as a numeric list, tuple or range.
Argument 2: Second point with the same number of coordinates.
Returns: Scaled Euclidean distance. Two empty points give +0.0. Unequal dimensions raise ValueError. Each coordinate must be numeric.
Error function
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Error function. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Real argument to the error function.
Returns: Value of the native error function.
Complementary error function
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Complementary error function. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Real argument to the complementary error function.
Returns: Complementary error-function value, computed directly by the native operation.
Exponential with overflow checking
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Exponential with overflow checking. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Exponent for base e.
Returns: e raised to the supplied exponent.
Base-two exponential with overflow checking
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Base-two exponential with overflow checking. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Exponent for base two.
Returns: Two raised to the supplied exponent.
Exponential minus one, accurate near zero
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Exponential minus one, accurate near zero. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Exponent for base e.
Returns: exp(x) minus one, using the native operation intended for accuracy near zero.
Floating-point absolute value
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: direct native result after the declared input guards.
Floating-point absolute value. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Number whose magnitude is requested.
Returns: Absolute value as float64.
Number of arrangements of all n items
n: positional-only; required
Product of the integers from one through n. Require n to be nonnegative. Zero factorial is one.
Accepts signed int64 and Boolean operands. Float operands raise TypeError. An exact result above 9223372036854775807 raises OverflowError.
Number of arrangements of all n items. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Number of distinct items, a nonnegative integer.
Returns: Number of ways to order all n items. Zero factorial is 1. The largest factorial that fits is 20!.
View example: native-factorial
Largest integer no greater than input; result must fit int64
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Result must fit signed int64; nonfinite or out-of-range results raise an exception.
Existing bool/int64 operands retain their exact integer value.
Largest integer no greater than input; result must fit int64. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Number to round downward.
Returns: Largest integer no greater than the input, within signed int64.
Floating remainder with the sign of the first input
Argument labels indicate positions; they are not accepted keyword names.
Input domain: Exactly two operands. Unless either is NaN, reject an infinite first operand or zero second operand.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Floating remainder with the sign of the first input. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Dividend.
Argument 2: Divisor.
Returns: Floating remainder with the dividend's sign, following the native fmod operation.
Accurate sum of a numeric sequence
seq: positional-only; required
Accumulate numeric items in a list, tuple or range using nonoverlapping partial sums. Empty input returns +0.0. Intermediate finite overflow raises OverflowError and opposite infinities raise ValueError.
Accurate sum of a numeric sequence. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Numeric list, tuple or range.
Returns: Binary64 sum that retains small contributions through cancellation. Empty input gives +0.0. Finite intermediate overflow raises OverflowError. Opposite infinities raise ValueError.
Greatest common divisor
integers: positional-only; required
Greatest common divisor of zero to 64 positional integers. An empty call returns zero.
Accepts signed int64 and Boolean operands. Float operands raise TypeError. An exact result above 9223372036854775807 raises OverflowError.
Greatest common divisor. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Zero to 64 directly supplied integers. Signs are ignored.
Returns: Nonnegative greatest common divisor. No inputs or all zeros return 0.
Euclidean length of zero or more positional coordinates
Supply coordinates individually in positional order. An empty call returns 0.0.
Zero or more positional real coordinates. A scaled and compensated Euclidean norm returns positive zero for empty or all-zero input. Infinity takes precedence over NaN after all arguments have been checked.
Euclidean length of zero or more positional coordinates. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Zero to 64 directly supplied real coordinates, each in the same unit.
Returns: Nonnegative Euclidean length in that unit. An empty call returns positive zero. Infinity takes precedence over NaN, and a nonnumeric coordinate raises TypeError.
Symmetric relative or absolute closeness with optional keyword-only tolerances
a: positional-or-keyword; required
b: positional-or-keyword; required
rel_tol: keyword-only; default 1e-09
abs_tol: keyword-only; default 0.0
Four slots: left, right, relative tolerance, absolute tolerance. Convert all to binary64; negative tolerances raise ValueError before equality. Equal values, including matching infinities, return True. Other infinite operands return False. Otherwise compare abs(right-left) to abs(relative*right), abs(relative*left), or absolute. NaN operands are never close; NaN tolerances participate in ordinary comparisons. Tolerances greater than or equal to 1 and positive infinity are accepted, matching CPython 3.12 behavior.
Symmetric relative or absolute closeness with optional keyword-only tolerances. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: First value a, positional or named.
Argument 2: Second value b, positional or named.
Argument 3: Keyword-only relative tolerance; defaults to 1e-9. Negative values raise ValueError.
Argument 4: Keyword-only absolute tolerance; defaults to 0.0. Negative values raise ValueError.
Returns: True for equal values or a difference within either symmetric relative bound or the absolute bound. NaN operands are never close; infinities are close only to themselves.
Test whether an input is finite
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: direct native result after the declared input guards.
Test whether an input is finite. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Number to classify.
Returns: True for finite numbers; False for infinities and NaN.
Test whether an input is an infinity
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: direct native result after the declared input guards.
Test whether an input is an infinity. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Number to classify.
Returns: True for either positive or negative infinity.
Test whether an input is NaN
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: direct native result after the declared input guards.
Test whether an input is NaN. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Number to classify.
Returns: True for NaN.
Integer square root rounded down
n: positional-only; required
Largest integer r with r squared at most n. Require n to be a nonnegative integer.
Accepts signed int64 and Boolean operands. Float operands raise TypeError. An exact result above 9223372036854775807 raises OverflowError.
Integer square root rounded down. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Nonnegative integer n.
Returns: Largest integer r for which r squared is at most n. The calculation stays integral, even above the precision of binary64.
Least common multiple
integers: positional-only; required
Least common multiple of zero to 64 positional integers. An empty call returns one. Any zero gives zero after all inputs are validated.
Accepts signed int64 and Boolean operands. Float operands raise TypeError. An exact result above 9223372036854775807 raises OverflowError.
Least common multiple. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Zero to 64 directly supplied integers. Signs are ignored.
Returns: Nonnegative least common multiple. No inputs return 1. Any zero gives 0 after all operands have been checked.
Natural logarithm or logarithm to an optional positional base
x: positional-only; required
base: positional-only; default omitted
Two slots: value and optional base with omitted default. Check and log the first value before checking the base. Nonpositive values raise ValueError; explicit None raises TypeError. Omission returns log(value); otherwise return log(value)/log(base). Base 1 raises ZeroDivisionError, including a NaN numerator. NaN and infinities propagate through the quotient; signed zero and underflow follow binary64. No arbitrary-precision integer logarithms.
Natural logarithm or logarithm to an optional positional base. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Strictly positive value; NaN propagates.
Argument 2: Optional positional base. Omit for the natural logarithm; nonpositive bases raise ValueError, base 1 raises ZeroDivisionError, and explicit None raises TypeError.
Returns: Natural logarithm when base is omitted, otherwise log(value)/log(base).
Base-ten logarithm; positive input
Argument labels indicate positions; they are not accepted keyword names.
Input domain: First operand at or below zero raises ValueError; NaN passes.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Base-ten logarithm; positive input. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Strictly positive number.
Returns: Base-ten logarithm.
Natural logarithm of one plus input; input greater than -1
Argument labels indicate positions; they are not accepted keyword names.
Input domain: First operand at or below -1 raises ValueError; NaN passes.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Natural logarithm of one plus input; input greater than -1. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Number strictly greater than -1.
Returns: Natural logarithm of one plus the supplied number.
Base-two logarithm; positive input
Argument labels indicate positions; they are not accepted keyword names.
Input domain: First operand at or below zero raises ValueError; NaN passes.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Base-two logarithm; positive input. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Strictly positive number.
Returns: Base-two logarithm.
Adjacent float toward a target, with an optional step count on Python 3.12+
x: positional-only; required
y: positional-only; required
steps: keyword-only; default omitted
Two positional real numbers and an optional keyword-only count on Python 3.12+. None or omission selects a single native step. A nonnegative int64 count advances toward the target in constant time.
Adjacent float toward a target, with an optional step count on Python 3.12+. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Starting real value.
Argument 2: Destination real value.
Argument 3: Optional keyword-only steps with a Python 3.12+ converter. Pass a nonnegative int64, Boolean or None.
Returns: Omission or None takes one native step. A zero count preserves the starting value including its zero sign. A positive integer count stops at the destination once reached. A single native step landing on zero preserves the sign of approach.
View example: native-nextafter
Number of ordered selections without repetition
n: positional-only; required
k: positional-only; default omitted
Count ordered selections of k from n distinct items. Omitted k or None selects all items. Counts must be nonnegative.
Accepts signed int64 and Boolean operands. Float operands raise TypeError. An exact result above 9223372036854775807 raises OverflowError.
Number of ordered selections without repetition. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Number of distinct items, a nonnegative integer.
Argument 2: Optional nonnegative selection count. Omit it or pass None to arrange all items.
Returns: Number of ordered selections without repetition. Choosing zero gives 1. Choosing more than n gives 0.
Floating-point power with domain and overflow checking
Argument labels indicate positions; they are not accepted keyword names.
Input domain: Exactly two operands. For finite operands, reject zero to a negative power and a negative base to a nonintegral power. Nonfinite cases follow the native operation.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Floating-point power with domain and overflow checking. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Base.
Argument 2: Exponent.
Returns: Floating-point power subject to the real-power domain guard.
Convert degrees to radians
x: positional-only; required
Multiply by binary64 pi/180. Signed zero and nonfinite values follow binary64 arithmetic.
Convert degrees to radians. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Angle in degrees.
Returns: Angle in radians, preserving signed zero.
IEEE remainder using the nearest even quotient
Argument labels indicate positions; they are not accepted keyword names.
Input domain: Exactly two operands. Unless either is NaN, reject an infinite first operand or zero second operand.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
IEEE remainder using the nearest even quotient. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Dividend.
Argument 2: Divisor.
Returns: IEEE remainder computed using the nearest integer quotient, with ties to even.
View example: native-remainder
Sine in radians
Argument labels indicate positions; they are not accepted keyword names.
Input domain: Either infinity in the first operand raises ValueError; NaN passes.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Sine in radians. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Angle in radians.
Returns: Sine of the angle.
Hyperbolic sine with overflow checking
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Hyperbolic sine with overflow checking. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Hyperbolic angle.
Returns: Hyperbolic sine.
Square root; negative inputs raise ValueError
Argument labels indicate positions; they are not accepted keyword names.
Input domain: First operand below zero raises ValueError; negative zero and NaN pass.
Native error policy: direct native result after the declared input guards.
Square root; negative inputs raise ValueError. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Nonnegative number; negative zero is accepted.
Returns: Square root as float64.
Sum corresponding weighted products with exact integer intermediates
p: positional-only; required
q: positional-only; required
Pair weights and values from two numeric lists, tuples or ranges. An integer result must fit int64 after cancellation. Floating products and sums use extended precision for the initial floating run.
Integer and Boolean pairs produce int64. Only the final exact integer is bounded. Floating inputs produce float64.
Sum corresponding weighted products with exact integer intermediates. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Numeric weights as a list, tuple or range.
Argument 2: Values in the same order, with one value per weight.
Returns: Returns an int64 for integer or Boolean inputs, including 0 for empty inputs. Integer products and partial sums may exceed int64 and cancel. An out-of-range final integer raises OverflowError. A floating pair selects a float64 result. Unequal lengths raise ValueError at the first unpaired item.
Tangent in radians
Argument labels indicate positions; they are not accepted keyword names.
Input domain: Either infinity in the first operand raises ValueError; NaN passes.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Tangent in radians. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Angle in radians.
Returns: Tangent of the angle.
Hyperbolic tangent
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Hyperbolic tangent. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Hyperbolic angle.
Returns: Hyperbolic tangent.
Integer part toward zero; result must fit int64
Argument labels indicate positions; they are not accepted keyword names.
Input domain: No additional input-domain restriction after numeric type checks.
Native error policy: checked domain/range errors; overflow raises OverflowError and underflow is permitted.
Result must fit signed int64; nonfinite or out-of-range results raise an exception.
Existing bool/int64 operands retain their exact integer value.
Integer part toward zero; result must fit int64. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Number to truncate toward zero.
Returns: Integer part toward zero, within signed int64.
Spacing at the magnitude of a binary64 value
x: positional-only; required
One positional real number. Return its positive binary64 spacing, infinity for either infinity, and NaN for NaN.
Spacing at the magnitude of a binary64 value. The example exercises representative values and exception cases; the generated contract below states the supported domain and result limits.
Argument 1: Real number.
Returns: Positive spacing at the magnitude of x. Either zero gives the smallest positive subnormal. The largest finite magnitude uses the lower neighbor. Infinity gives positive infinity and NaN propagates.
Compare your run with the expected output below. The SDK checks conversion when authoring a package. Opening Help and registering a package do not execute the examples.
*import math as m
def checked(x):
try:
value = m.acos(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
1.5707963267948966 1.0 0.0 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 3.141592653589793 1.0 0.0 1.0 ValueError ValueError 2.0943951023931957 1.0 1.0471975511965979 1.0 ValueError 3.141592638688632 1.0 1.4901161193847656e-08 1.0 ValueError 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.acosh(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
ValueError 0.0 1.0 ValueError ValueError ValueError 0.0 1.0 ValueError 1.3169578969248166 1.0 ValueError ValueError ValueError ValueError ValueError 2.1073424255447017e-08 1.0 ValueError ValueError ValueError ValueError ValueError 7.600902209541989 1.0 ValueError 691.4686750787736 1.0 44.3614195558365 1.0 ValueError inf 1.0 ValueError nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.asin(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 1.5707963267948966 1.0 -0.0 -1.0 0.0 1.0 -1.5707963267948966 -1.0 1.5707963267948966 1.0 ValueError ValueError -0.5235987755982989 -1.0 0.5235987755982989 1.0 ValueError -1.5707963118937354 -1.0 1.5707963118937354 1.0 ValueError -5e-324 -1.0 5e-324 1.0 -1e-300 -1.0 1e-300 1.0 ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.asinh(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 0.881373587019543 1.0 -0.0 -1.0 0.0 1.0 -0.881373587019543 -1.0 0.881373587019543 1.0 -1.4436354751788103 -1.0 1.4436354751788103 1.0 -0.48121182505960347 -1.0 0.48121182505960347 1.0 -0.8813735870195432 -1.0 -0.8813735870195429 -1.0 0.8813735870195429 1.0 0.8813735870195432 1.0 -5e-324 -1.0 5e-324 1.0 -1e-300 -1.0 1e-300 1.0 -7.600902709541988 -1.0 7.600902709541988 1.0 -691.4686750787736 -1.0 691.4686750787736 1.0 44.3614195558365 1.0 -44.3614195558365 -1.0 inf 1.0 -inf -1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.atan(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 0.7853981633974483 1.0 -0.0 -1.0 0.0 1.0 -0.7853981633974483 -1.0 0.7853981633974483 1.0 -1.1071487177940904 -1.0 1.1071487177940904 1.0 -0.4636476090008061 -1.0 0.4636476090008061 1.0 -0.7853981633974484 -1.0 -0.7853981633974483 -1.0 0.7853981633974483 1.0 0.7853981633974484 1.0 -5e-324 -1.0 5e-324 1.0 -1e-300 -1.0 1e-300 1.0 -1.5697963271282298 -1.0 1.5697963271282298 1.0 -1.5707963267948966 -1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 -1.5707963267948966 -1.0 1.5707963267948966 1.0 -1.5707963267948966 -1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x, y):
try:
value = m.atan2(x, y)
if m.fabs(x) == 5e-324 and y == 2.0:
print(m.fabs(value) <= 5e-324)
else:
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -9, -2, -1, -0.0, 0.0, 0.5, 1.0, 2.0, 3.0, -1e300, 1e300, -5e-324, 5e-324, m.inf, -m.inf, m.nan]:
for y in [False, True, -9, -2, -1, -0.0, 0.0, 0.5, 1.0, 2.0, 3.0, -1e300, 1e300, -5e-324, 5e-324, m.inf, -m.inf, m.nan]:
checked(x, y)
checked("bad", 1)
checked(1, "bad")
checked(None, 1)
checked(1, None)
return 0
Expected standard output:
0.0 1.0 0.0 1.0 3.141592653589793 1.0 3.141592653589793 1.0 3.141592653589793 1.0 3.141592653589793 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 3.141592653589793 1.0 0.0 1.0 3.141592653589793 1.0 0.0 1.0 0.0 1.0 3.141592653589793 1.0 nan 1.5707963267948966 1.0 0.7853981633974483 1.0 3.0309354324158977 1.0 2.677945044588987 1.0 2.356194490192345 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.1071487177940904 1.0 0.7853981633974483 1.0 0.4636476090008061 1.0 0.3217505543966422 1.0 3.141592653589793 1.0 1e-300 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 0.0 1.0 3.141592653589793 1.0 nan -1.5707963267948966 -1.0 -1.460139105621001 -1.0 -2.356194490192345 -1.0 -1.7894652726688385 -1.0 -1.6814535479687922 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5152978215491797 -1.0 -1.460139105621001 -1.0 -1.3521273809209546 -1.0 -1.2490457723982544 -1.0 -3.141592653589793 -1.0 -9e-300 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -0.0 -1.0 -3.141592653589793 -1.0 nan -1.5707963267948966 -1.0 -1.1071487177940904 -1.0 -2.922923707715851 -1.0 -2.356194490192345 -1.0 -2.0344439357957027 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.3258176636680326 -1.0 -1.1071487177940904 -1.0 -0.7853981633974483 -1.0 -0.5880026035475675 -1.0 -3.141592653589793 -1.0 -2e-300 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -0.0 -1.0 -3.141592653589793 -1.0 nan -1.5707963267948966 -1.0 -0.7853981633974483 -1.0 -3.0309354324158977 -1.0 -2.677945044588987 -1.0 -2.356194490192345 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.1071487177940904 -1.0 -0.7853981633974483 -1.0 -0.4636476090008061 -1.0 -0.3217505543966422 -1.0 -3.141592653589793 -1.0 -1e-300 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -0.0 -1.0 -3.141592653589793 -1.0 nan -0.0 -1.0 -0.0 -1.0 -3.141592653589793 -1.0 -3.141592653589793 -1.0 -3.141592653589793 -1.0 -3.141592653589793 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -3.141592653589793 -1.0 -0.0 -1.0 -3.141592653589793 -1.0 -0.0 -1.0 -0.0 -1.0 -3.141592653589793 -1.0 nan 0.0 1.0 0.0 1.0 3.141592653589793 1.0 3.141592653589793 1.0 3.141592653589793 1.0 3.141592653589793 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 3.141592653589793 1.0 0.0 1.0 3.141592653589793 1.0 0.0 1.0 0.0 1.0 3.141592653589793 1.0 nan 1.5707963267948966 1.0 0.4636476090008061 1.0 3.0860941483440762 1.0 2.896613990462929 1.0 2.677945044588987 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 0.7853981633974483 1.0 0.4636476090008061 1.0 0.24497866312686414 1.0 0.16514867741462683 1.0 3.141592653589793 1.0 5e-301 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 0.0 1.0 3.141592653589793 1.0 nan 1.5707963267948966 1.0 0.7853981633974483 1.0 3.0309354324158977 1.0 2.677945044588987 1.0 2.356194490192345 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.1071487177940904 1.0 0.7853981633974483 1.0 0.4636476090008061 1.0 0.3217505543966422 1.0 3.141592653589793 1.0 1e-300 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 0.0 1.0 3.141592653589793 1.0 nan 1.5707963267948966 1.0 1.1071487177940904 1.0 2.922923707715851 1.0 2.356194490192345 1.0 2.0344439357957027 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.3258176636680326 1.0 1.1071487177940904 1.0 0.7853981633974483 1.0 0.5880026035475675 1.0 3.141592653589793 1.0 2e-300 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 0.0 1.0 3.141592653589793 1.0 nan 1.5707963267948966 1.0 1.2490457723982544 1.0 2.819842099193151 1.0 2.158798930342464 1.0 1.892546881191539 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.4056476493802699 1.0 1.2490457723982544 1.0 0.982793723247329 1.0 0.7853981633974483 1.0 3.141592653589793 1.0 2.9999999999999996e-300 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 0.0 1.0 3.141592653589793 1.0 nan -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -2.356194490192345 -1.0 -0.7853981633974483 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -0.0 -1.0 -3.141592653589793 -1.0 nan 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 2.356194490192345 1.0 0.7853981633974483 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 0.0 1.0 3.141592653589793 1.0 nan -1.5707963267948966 -1.0 -5e-324 -1.0 -3.141592653589793 -1.0 -3.141592653589793 -1.0 -3.141592653589793 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1e-323 -1.0 -5e-324 -1.0 True -1.0 -0.0 -1.0 -3.141592653589793 -1.0 -0.0 -1.0 -2.356194490192345 -1.0 -0.7853981633974483 -1.0 -0.0 -1.0 -3.141592653589793 -1.0 nan 1.5707963267948966 1.0 5e-324 1.0 3.141592653589793 1.0 3.141592653589793 1.0 3.141592653589793 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1e-323 1.0 5e-324 1.0 True 1.0 0.0 1.0 3.141592653589793 1.0 0.0 1.0 2.356194490192345 1.0 0.7853981633974483 1.0 0.0 1.0 3.141592653589793 1.0 nan 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 1.5707963267948966 1.0 0.7853981633974483 1.0 2.356194490192345 1.0 nan -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -1.5707963267948966 -1.0 -0.7853981633974483 -1.0 -2.356194490192345 -1.0 nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.atanh(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 ValueError -0.0 -1.0 0.0 1.0 ValueError ValueError ValueError ValueError -0.5493061443340548 -1.0 0.5493061443340548 1.0 ValueError -18.714973875118524 -1.0 18.714973875118524 1.0 ValueError -5e-324 -1.0 5e-324 1.0 -1e-300 -1.0 1e-300 1.0 ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.cbrt(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 1.0 1.0 -0.0 -1.0 0.0 1.0 -1.0 -1.0 1.0 1.0 -1.2599210498948734 -1.0 1.2599210498948734 1.0 -0.7937005259840998 -1.0 0.7937005259840998 1.0 -1.0 -1.0 -1.0 -1.0 1.0 1.0 1.0 1.0 -1.7031839360032601e-108 -1.0 1.7031839360032601e-108 1.0 -1e-100 -1.0 1e-100 1.0 -10.0 -1.0 10.0 1.0 -1e+100 -1.0 1e+100 1.0 2097152.0 1.0 -2097152.0 -1.0 inf 1.0 -inf -1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.ceil(x)
print(value)
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1.5, 1.5, -0.1, 0.1, -5e-324, 5e-324, 9007199254740993, -9007199254740993, 9223372036854775807, -9223372036854775808, 9223372036854774784.0, -9223372036854775808.0, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0 1 0 0 -1 2 0 1 0 1 9007199254740993 -9007199254740993 9223372036854775807 -9223372036854775808 9223372036854774784 -9223372036854775808 OverflowError OverflowError ValueError TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def main():
print(m.comb(12, 3), m.comb(12, 13))
print(m.comb(66, 33))
return 0
Expected standard output:
220 0 7219428434016265740
Expected exit code: 0
*import math as m
def checked(x, y):
try:
value = m.copysign(x, y)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -9, -2, -1, -0.0, 0.0, 0.5, 1.0, 2.0, 3.0, -1e300, 1e300, -5e-324, 5e-324, m.inf, -m.inf, m.nan]:
for y in [False, True, -9, -2, -1, -0.0, 0.0, 0.5, 1.0, 2.0, 3.0, -1e300, 1e300, -5e-324, 5e-324, m.inf, -m.inf, m.nan]:
checked(x, y)
checked("bad", 1)
checked(1, "bad")
checked(None, 1)
checked(1, None)
return 0
Expected standard output:
0.0 1.0 0.0 1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 -0.0 -1.0 0.0 1.0 -0.0 -1.0 0.0 1.0 0.0 1.0 -0.0 -1.0 0.0 1.0 1.0 1.0 1.0 1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 9.0 1.0 9.0 1.0 -9.0 -1.0 -9.0 -1.0 -9.0 -1.0 -9.0 -1.0 9.0 1.0 9.0 1.0 9.0 1.0 9.0 1.0 9.0 1.0 -9.0 -1.0 9.0 1.0 -9.0 -1.0 9.0 1.0 9.0 1.0 -9.0 -1.0 9.0 1.0 2.0 1.0 2.0 1.0 -2.0 -1.0 -2.0 -1.0 -2.0 -1.0 -2.0 -1.0 2.0 1.0 2.0 1.0 2.0 1.0 2.0 1.0 2.0 1.0 -2.0 -1.0 2.0 1.0 -2.0 -1.0 2.0 1.0 2.0 1.0 -2.0 -1.0 2.0 1.0 1.0 1.0 1.0 1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 0.0 1.0 0.0 1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 -0.0 -1.0 0.0 1.0 -0.0 -1.0 0.0 1.0 0.0 1.0 -0.0 -1.0 0.0 1.0 0.0 1.0 0.0 1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 -0.0 -1.0 0.0 1.0 -0.0 -1.0 0.0 1.0 0.0 1.0 -0.0 -1.0 0.0 1.0 0.5 1.0 0.5 1.0 -0.5 -1.0 -0.5 -1.0 -0.5 -1.0 -0.5 -1.0 0.5 1.0 0.5 1.0 0.5 1.0 0.5 1.0 0.5 1.0 -0.5 -1.0 0.5 1.0 -0.5 -1.0 0.5 1.0 0.5 1.0 -0.5 -1.0 0.5 1.0 1.0 1.0 1.0 1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 2.0 1.0 2.0 1.0 -2.0 -1.0 -2.0 -1.0 -2.0 -1.0 -2.0 -1.0 2.0 1.0 2.0 1.0 2.0 1.0 2.0 1.0 2.0 1.0 -2.0 -1.0 2.0 1.0 -2.0 -1.0 2.0 1.0 2.0 1.0 -2.0 -1.0 2.0 1.0 3.0 1.0 3.0 1.0 -3.0 -1.0 -3.0 -1.0 -3.0 -1.0 -3.0 -1.0 3.0 1.0 3.0 1.0 3.0 1.0 3.0 1.0 3.0 1.0 -3.0 -1.0 3.0 1.0 -3.0 -1.0 3.0 1.0 3.0 1.0 -3.0 -1.0 3.0 1.0 1e+300 1.0 1e+300 1.0 -1e+300 -1.0 -1e+300 -1.0 -1e+300 -1.0 -1e+300 -1.0 1e+300 1.0 1e+300 1.0 1e+300 1.0 1e+300 1.0 1e+300 1.0 -1e+300 -1.0 1e+300 1.0 -1e+300 -1.0 1e+300 1.0 1e+300 1.0 -1e+300 -1.0 1e+300 1.0 1e+300 1.0 1e+300 1.0 -1e+300 -1.0 -1e+300 -1.0 -1e+300 -1.0 -1e+300 -1.0 1e+300 1.0 1e+300 1.0 1e+300 1.0 1e+300 1.0 1e+300 1.0 -1e+300 -1.0 1e+300 1.0 -1e+300 -1.0 1e+300 1.0 1e+300 1.0 -1e+300 -1.0 1e+300 1.0 5e-324 1.0 5e-324 1.0 -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 -5e-324 -1.0 5e-324 1.0 -5e-324 -1.0 5e-324 1.0 5e-324 1.0 -5e-324 -1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 -5e-324 -1.0 5e-324 1.0 -5e-324 -1.0 5e-324 1.0 5e-324 1.0 -5e-324 -1.0 5e-324 1.0 inf 1.0 inf 1.0 -inf -1.0 -inf -1.0 -inf -1.0 -inf -1.0 inf 1.0 inf 1.0 inf 1.0 inf 1.0 inf 1.0 -inf -1.0 inf 1.0 -inf -1.0 inf 1.0 inf 1.0 -inf -1.0 inf 1.0 inf 1.0 inf 1.0 -inf -1.0 -inf -1.0 -inf -1.0 -inf -1.0 inf 1.0 inf 1.0 inf 1.0 inf 1.0 inf 1.0 -inf -1.0 inf 1.0 -inf -1.0 inf 1.0 inf 1.0 -inf -1.0 inf 1.0 nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.cos(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
1.0 1.0 0.5403023058681398 1.0 1.0 1.0 1.0 1.0 0.5403023058681398 1.0 0.5403023058681398 1.0 -0.4161468365471424 -1.0 -0.4161468365471424 -1.0 0.8775825618903728 1.0 0.8775825618903728 1.0 0.5403023058681395 1.0 0.5403023058681398 1.0 0.5403023058681398 1.0 0.5403023058681395 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.5623790762907029 1.0 0.5623790762907029 1.0 -0.5753861119575491 -1.0 -0.5753861119575491 -1.0 0.011800076512800236 1.0 0.011800076512800236 1.0 ValueError ValueError nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.cosh(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
1.0 1.0 1.5430806348152437 1.0 1.0 1.0 1.0 1.0 1.5430806348152437 1.0 1.5430806348152437 1.0 3.7621956910836314 1.0 3.7621956910836314 1.0 1.1276259652063807 1.0 1.1276259652063807 1.0 1.5430806348152442 1.0 1.5430806348152437 1.0 1.5430806348152437 1.0 1.5430806348152442 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 OverflowError OverflowError OverflowError OverflowError OverflowError OverflowError inf 1.0 inf 1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.degrees(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 57.29577951308232 1.0 -0.0 -1.0 0.0 1.0 -57.29577951308232 -1.0 57.29577951308232 1.0 -114.59155902616465 -1.0 114.59155902616465 1.0 -28.64788975654116 -1.0 28.64788975654116 1.0 -57.29577951308234 -1.0 -57.295779513082316 -1.0 57.295779513082316 1.0 57.29577951308234 1.0 -2.8e-322 -1.0 2.8e-322 1.0 -5.729577951308232e-299 -1.0 5.729577951308232e-299 1.0 -57295.77951308232 -1.0 57295.77951308232 1.0 -5.729577951308233e+301 -1.0 5.729577951308233e+301 1.0 5.2846029059076024e+20 1.0 -5.2846029059076024e+20 -1.0 inf 1.0 -inf -1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def main():
print(m.dist((0.0, 0.0), [3, 4]), m.dist(range(3), (0, 1, 2)))
print(m.dist((), []), m.copysign(1, m.dist([-0.0], [0.0])))
print(m.isclose(m.dist([3e300, 4e300], (0, 0)), 5e300), m.dist([3e-320, 4e-320], [0, 0]))
print(m.dist([m.inf, m.nan], [0, 0]), m.isnan(m.dist([m.inf], [m.inf])))
try:
m.dist(["bad"], [0, 0])
except ValueError:
print("different dimensions")
try:
m.dist([m.inf, "bad"], [0, 0])
except TypeError:
print("nonnumeric coordinate")
return 0
Expected standard output:
5.0 0.0 0.0 1.0 True 5e-320 inf True different dimensions nonnumeric coordinate
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.erf(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 0.8427007929497149 1.0 -0.0 -1.0 0.0 1.0 -0.8427007929497149 -1.0 0.8427007929497149 1.0 -0.9953222650189527 -1.0 0.9953222650189527 1.0 -0.5204998778130465 -1.0 0.5204998778130465 1.0 -0.842700792949715 -1.0 -0.8427007929497148 -1.0 0.8427007929497148 1.0 0.842700792949715 1.0 -5e-324 -1.0 5e-324 1.0 -1.1283791670955126e-300 -1.0 1.1283791670955126e-300 1.0 -1.0 -1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 -1.0 -1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.erfc(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
1.0 1.0 0.15729920705028513 1.0 1.0 1.0 1.0 1.0 1.842700792949715 1.0 0.15729920705028513 1.0 1.9953222650189528 1.0 0.004677734981047265 1.0 1.5204998778130465 1.0 0.4795001221869535 1.0 1.842700792949715 1.0 1.8427007929497148 1.0 0.1572992070502852 1.0 0.15729920705028505 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 0.0 1.0 2.0 1.0 0.0 1.0 0.0 1.0 2.0 1.0 0.0 1.0 2.0 1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.exp(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
1.0 1.0 2.718281828459045 1.0 1.0 1.0 1.0 1.0 0.36787944117144233 1.0 2.718281828459045 1.0 0.1353352832366127 1.0 7.38905609893065 1.0 0.6065306597126334 1.0 1.6487212707001282 1.0 0.3678794411714422 1.0 0.3678794411714424 1.0 2.718281828459045 1.0 2.718281828459046 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 OverflowError 0.0 1.0 OverflowError OverflowError 0.0 1.0 inf 1.0 0.0 1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.exp2(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
1.0 1.0 2.0 1.0 1.0 1.0 1.0 1.0 0.5 1.0 2.0 1.0 0.25 1.0 4.0 1.0 0.7071067811865476 1.0 1.4142135623730951 1.0 0.49999999999999994 1.0 0.5 1.0 1.9999999999999998 1.0 2.0000000000000004 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 9.332636185032189e-302 1.0 1.0715086071862673e+301 1.0 0.0 1.0 OverflowError OverflowError 0.0 1.0 inf 1.0 0.0 1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.expm1(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 1.718281828459045 1.0 -0.0 -1.0 0.0 1.0 -0.6321205588285577 -1.0 1.718281828459045 1.0 -0.8646647167633873 -1.0 6.38905609893065 1.0 -0.3934693402873666 -1.0 0.6487212707001282 1.0 -0.6321205588285578 -1.0 -0.6321205588285577 -1.0 1.7182818284590449 1.0 1.718281828459046 1.0 -5e-324 -1.0 5e-324 1.0 -1e-300 -1.0 1e-300 1.0 -1.0 -1.0 OverflowError -1.0 -1.0 OverflowError OverflowError -1.0 -1.0 inf 1.0 -1.0 -1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.fabs(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 1.0 1.0 0.0 1.0 0.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 2.0 1.0 0.5 1.0 0.5 1.0 1.0000000000000002 1.0 0.9999999999999999 1.0 0.9999999999999999 1.0 1.0000000000000002 1.0 5e-324 1.0 5e-324 1.0 1e-300 1.0 1e-300 1.0 1000.0 1.0 1000.0 1.0 1e+300 1.0 1e+300 1.0 9.223372036854776e+18 1.0 9.223372036854776e+18 1.0 inf 1.0 inf 1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def main():
print(m.factorial(0), m.factorial(6), m.factorial(20))
return 0
Expected standard output:
1 720 2432902008176640000
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.floor(x)
print(value)
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1.5, 1.5, -0.1, 0.1, -5e-324, 5e-324, 9007199254740993, -9007199254740993, 9223372036854775807, -9223372036854775808, 9223372036854774784.0, -9223372036854775808.0, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0 1 0 0 -2 1 -1 0 -1 0 9007199254740993 -9007199254740993 9223372036854775807 -9223372036854775808 9223372036854774784 -9223372036854775808 OverflowError OverflowError ValueError TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x, y):
try:
value = m.fmod(x, y)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -9, -2, -1, -0.0, 0.0, 0.5, 1.0, 2.0, 3.0, -1e300, 1e300, -5e-324, 5e-324, m.inf, -m.inf, m.nan]:
for y in [False, True, -9, -2, -1, -0.0, 0.0, 0.5, 1.0, 2.0, 3.0, -1e300, 1e300, -5e-324, 5e-324, m.inf, -m.inf, m.nan]:
checked(x, y)
checked("bad", 1)
checked(1, "bad")
checked(None, 1)
checked(1, None)
return 0
Expected standard output:
ValueError 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 ValueError ValueError 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 nan ValueError 0.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 ValueError ValueError 0.0 1.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 0.0 1.0 1.0 1.0 1.0 1.0 nan ValueError -0.0 -1.0 -0.0 -1.0 -1.0 -1.0 -0.0 -1.0 ValueError ValueError -0.0 -1.0 -0.0 -1.0 -1.0 -1.0 -0.0 -1.0 -9.0 -1.0 -9.0 -1.0 -0.0 -1.0 -0.0 -1.0 -9.0 -1.0 -9.0 -1.0 nan ValueError -0.0 -1.0 -2.0 -1.0 -0.0 -1.0 -0.0 -1.0 ValueError ValueError -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -2.0 -1.0 -2.0 -1.0 -2.0 -1.0 -0.0 -1.0 -0.0 -1.0 -2.0 -1.0 -2.0 -1.0 nan ValueError -0.0 -1.0 -1.0 -1.0 -1.0 -1.0 -0.0 -1.0 ValueError ValueError -0.0 -1.0 -0.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -0.0 -1.0 -0.0 -1.0 -1.0 -1.0 -1.0 -1.0 nan ValueError -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 ValueError ValueError -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 nan ValueError 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 ValueError ValueError 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 nan ValueError 0.5 1.0 0.5 1.0 0.5 1.0 0.5 1.0 ValueError ValueError 0.0 1.0 0.5 1.0 0.5 1.0 0.5 1.0 0.5 1.0 0.5 1.0 0.0 1.0 0.0 1.0 0.5 1.0 0.5 1.0 nan ValueError 0.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 ValueError ValueError 0.0 1.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 0.0 1.0 1.0 1.0 1.0 1.0 nan ValueError 0.0 1.0 2.0 1.0 0.0 1.0 0.0 1.0 ValueError ValueError 0.0 1.0 0.0 1.0 0.0 1.0 2.0 1.0 2.0 1.0 2.0 1.0 0.0 1.0 0.0 1.0 2.0 1.0 2.0 1.0 nan ValueError 0.0 1.0 3.0 1.0 1.0 1.0 0.0 1.0 ValueError ValueError 0.0 1.0 0.0 1.0 1.0 1.0 0.0 1.0 3.0 1.0 3.0 1.0 0.0 1.0 0.0 1.0 3.0 1.0 3.0 1.0 nan ValueError -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 ValueError ValueError -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -1e+300 -1.0 -1e+300 -1.0 nan ValueError 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 ValueError ValueError 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 1e+300 1.0 1e+300 1.0 nan ValueError -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 ValueError ValueError -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 -0.0 -1.0 -0.0 -1.0 -5e-324 -1.0 -5e-324 -1.0 nan ValueError 5e-324 1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 ValueError ValueError 5e-324 1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 0.0 1.0 0.0 1.0 5e-324 1.0 5e-324 1.0 nan ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError nan ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def main():
print(m.fsum([1e16, 1.0, -1e16]), m.fsum(range(5)), m.fsum((True, 2.5)))
print(m.fsum([]), m.copysign(1, m.fsum([-0.0])), m.fsum([5e-324, 5e-324]))
print(m.fsum([1.0, 2**-53, 2**-54]), m.fsum([1.0, 2**-53]))
print(m.isnan(m.fsum([m.nan, m.inf])), m.fsum([-m.inf, 2]))
try:
m.fsum([1e308, 1e308, -1e308])
except OverflowError:
print("intermediate overflow")
try:
m.fsum([m.inf, m.nan, -m.inf])
except ValueError:
print("opposite infinities")
try:
m.fsum([m.inf, "bad"])
except TypeError:
print("nonnumeric element")
return 0
Expected standard output:
1.0 10.0 3.5 0.0 1.0 1e-323 1.0000000000000002 1.0 True -inf intermediate overflow opposite infinities nonnumeric element
Expected exit code: 0
*import math as m
def main():
width, height = 1920, 1080
unit = m.gcd(width, height)
print(width // unit, height // unit)
print(m.gcd(), m.gcd(-30, 45, 75))
return 0
Expected standard output:
16 9 0 15
Expected exit code: 0
*import math as m
def main():
print(m.hypot(), m.hypot(-3), m.hypot(3, 4), m.hypot(2, 3, 6))
print(m.hypot(1, 2, 2, 4, 4))
print(m.isclose(m.hypot(3e300, 4e300), 5e300, rel_tol=1e-15))
print(m.hypot(3e-320, 4e-320), m.hypot(5e-324, 5e-324))
print(m.hypot(m.nan, -m.inf), m.isnan(m.hypot(m.nan)), m.copysign(1, m.hypot(-0.0)))
try:
m.hypot(m.inf, "not a coordinate")
except TypeError:
print("coordinates must be numbers")
return 0
Expected standard output:
0.0 3.0 5.0 7.0 6.4031242374328485 True 5e-320 5e-324 inf True 1.0 coordinates must be numbers
Expected exit code: 0
*import math as m
def checked(x, y):
try:
value = m.isclose(x, y)
print(value)
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -9, -2, -1, -0.0, 0.0, 0.5, 1.0, 2.0, 3.0, -1e300, 1e300, -5e-324, 5e-324, m.inf, -m.inf, m.nan]:
for y in [False, True, -9, -2, -1, -0.0, 0.0, 0.5, 1.0, 2.0, 3.0, -1e300, 1e300, -5e-324, 5e-324, m.inf, -m.inf, m.nan]:
checked(x, y)
checked("bad", 1)
checked(1, "bad")
checked(None, 1)
checked(1, None)
return 0
Expected standard output:
True False False False False True True False False False False False False False False False False False False True False False False False False False True False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False True False False False False True True False False False False False False False False False False False True False False False False True True False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False True False False False False False False True False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False False TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.isfinite(x)
print(value)
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
True True True True True True True True True True True True True True True True True True True True True True True True False False False TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.isinf(x)
print(value)
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
False False False False False False False False False False False False False False False False False False False False False False False False True True False TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.isnan(x)
print(value)
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
False False False False False False False False False False False False False False False False False False False False False False False False False False True TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def main():
tiles = 2**54 - 1
print(m.isqrt(tiles), m.isqrt(tiles + 1))
return 0
Expected standard output:
134217727 134217728
Expected exit code: 0
*import math as m
def main():
print(m.lcm(12, 18, 30))
print(m.lcm(), m.lcm(-4, 6), m.lcm(4, 0))
return 0
Expected standard output:
180 1 12 0
Expected exit code: 0
*import math as m
def checked(x, y):
try:
value = m.log(x, y)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -9, -2, -1, -0.0, 0.0, 0.5, 1.0, 2.0, 3.0, -1e300, 1e300, -5e-324, 5e-324, m.inf, -m.inf, m.nan]:
for y in [False, True, -9, -2, -1, -0.0, 0.0, 0.5, 1.0, 2.0, 3.0, -1e300, 1e300, -5e-324, 5e-324, m.inf, -m.inf, m.nan]:
checked(x, y)
checked("bad", 1)
checked(1, "bad")
checked(None, 1)
checked(1, None)
print(m.log(1), m.log(m.e), m.log(m.inf))
return 0
Expected standard output:
ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ZeroDivisionError ValueError ValueError ValueError ValueError ValueError -0.0 -1.0 ZeroDivisionError 0.0 1.0 0.0 1.0 ValueError 0.0 1.0 ValueError -0.0 -1.0 0.0 1.0 ValueError nan ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ZeroDivisionError ValueError ValueError ValueError ValueError ValueError 1.0 1.0 ZeroDivisionError -1.0 -1.0 -0.6309297535714574 -1.0 ValueError -0.0010034333188799374 -1.0 ValueError 0.000931098696461825 1.0 -0.0 -1.0 ValueError nan ValueError ZeroDivisionError ValueError ValueError ValueError ValueError ValueError -0.0 -1.0 ZeroDivisionError 0.0 1.0 0.0 1.0 ValueError 0.0 1.0 ValueError -0.0 -1.0 0.0 1.0 ValueError nan ValueError ZeroDivisionError ValueError ValueError ValueError ValueError ValueError -1.0 -1.0 ZeroDivisionError 1.0 1.0 0.6309297535714574 1.0 ValueError 0.0010034333188799374 1.0 ValueError -0.000931098696461825 -1.0 0.0 1.0 ValueError nan ValueError ZeroDivisionError ValueError ValueError ValueError ValueError ValueError -1.5849625007211563 -1.0 ZeroDivisionError 1.5849625007211563 1.0 1.0 1.0 ValueError 0.001590404182398875 1.0 ValueError -0.001475756518362343 -1.0 0.0 1.0 ValueError nan ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ZeroDivisionError ValueError ValueError ValueError ValueError ValueError -996.5784284662087 -1.0 ZeroDivisionError 996.5784284662087 1.0 628.7709822868153 1.0 ValueError 1.0 1.0 ValueError -0.927912875666861 -1.0 0.0 1.0 ValueError nan ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ZeroDivisionError ValueError ValueError ValueError ValueError ValueError 1074.0 1.0 ZeroDivisionError -1074.0 -1.0 -677.6185553357452 -1.0 ValueError -1.0776873844770527 -1.0 ValueError 1.0 1.0 -0.0 -1.0 ValueError nan ValueError ZeroDivisionError ValueError ValueError ValueError ValueError ValueError -inf -1.0 ZeroDivisionError inf 1.0 inf 1.0 ValueError inf 1.0 ValueError -inf -1.0 nan ValueError nan ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ZeroDivisionError ValueError ValueError ValueError ValueError ValueError nan ZeroDivisionError nan nan ValueError nan ValueError nan nan ValueError nan TypeError TypeError TypeError TypeError 0.0 1.0 inf
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.log10(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
ValueError 0.0 1.0 ValueError ValueError ValueError 0.0 1.0 ValueError 0.3010299956639812 1.0 ValueError -0.3010299956639812 -1.0 ValueError ValueError -4.8216373327664354e-17 -1.0 9.64327466553287e-17 1.0 ValueError -323.3062153431158 -1.0 ValueError -300.0 -1.0 ValueError 3.0 1.0 ValueError 300.0 1.0 18.964889726830815 1.0 ValueError inf 1.0 ValueError nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.log1p(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 0.6931471805599453 1.0 -0.0 -1.0 0.0 1.0 ValueError 0.6931471805599453 1.0 ValueError 1.0986122886681096 1.0 -0.6931471805599453 -1.0 0.4054651081081644 1.0 ValueError -36.7368005696771 -1.0 0.6931471805599453 1.0 0.6931471805599454 1.0 -5e-324 -1.0 5e-324 1.0 -1e-300 -1.0 1e-300 1.0 ValueError 6.90875477931522 1.0 ValueError 690.7755278982137 1.0 43.66827237527655 1.0 ValueError inf 1.0 ValueError nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.log2(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
ValueError 0.0 1.0 ValueError ValueError ValueError 0.0 1.0 ValueError 1.0 1.0 ValueError -1.0 -1.0 ValueError ValueError -1.6017132519074588e-16 -1.0 3.203426503814917e-16 1.0 ValueError -1074.0 -1.0 ValueError -996.5784284662087 -1.0 ValueError 9.965784284662087 1.0 ValueError 996.5784284662087 1.0 63.0 1.0 ValueError inf 1.0 ValueError nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def main():
tiny = 5e-324
print(m.nextafter(0.0, 1.0) == tiny, m.nextafter(0.0, -1.0) == -tiny)
print(m.copysign(1.0, m.nextafter(-tiny, 0.0)), m.nextafter(-0.0, 0.0))
print(m.nextafter(1.0, 2.0) == 1.0000000000000002)
print(m.isfinite(m.nextafter(m.inf, 0.0)), m.isnan(m.nextafter(m.nan, 0.0)))
return 0
Expected standard output:
True True -1.0 0.0 True True True
Expected exit code: 0
*import math as m
def main():
print(m.perm(12, 3), m.perm(3), m.perm(3, None))
return 0
Expected standard output:
1320 6 6
Expected exit code: 0
*import math as m
def checked(x, y):
try:
value = m.pow(x, y)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -9, -2, -1, -0.0, 0.0, 0.5, 1.0, 2.0, 3.0, -1e300, 1e300, -5e-324, 5e-324, m.inf, -m.inf, m.nan]:
for y in [False, True, -9, -2, -1, -0.0, 0.0, 0.5, 1.0, 2.0, 3.0, -1e300, 1e300, -5e-324, 5e-324, m.inf, -m.inf, m.nan]:
checked(x, y)
checked("bad", 1)
checked(1, "bad")
checked(None, 1)
checked(1, None)
return 0
Expected standard output:
1.0 1.0 0.0 1.0 ValueError ValueError ValueError 1.0 1.0 1.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 ValueError 0.0 1.0 ValueError 0.0 1.0 0.0 1.0 inf 1.0 nan 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 -9.0 -1.0 -2.581174791713197e-09 -1.0 0.012345679012345678 1.0 -0.1111111111111111 -1.0 1.0 1.0 1.0 1.0 ValueError -9.0 -1.0 81.0 1.0 -729.0 -1.0 0.0 1.0 OverflowError ValueError ValueError inf 1.0 0.0 1.0 nan 1.0 1.0 -2.0 -1.0 -0.001953125 -1.0 0.25 1.0 -0.5 -1.0 1.0 1.0 1.0 1.0 ValueError -2.0 -1.0 4.0 1.0 -8.0 -1.0 0.0 1.0 OverflowError ValueError ValueError inf 1.0 0.0 1.0 nan 1.0 1.0 -1.0 -1.0 -1.0 -1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 1.0 1.0 ValueError -1.0 -1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 1.0 1.0 ValueError ValueError 1.0 1.0 1.0 1.0 nan 1.0 1.0 -0.0 -1.0 ValueError ValueError ValueError 1.0 1.0 1.0 1.0 0.0 1.0 -0.0 -1.0 0.0 1.0 -0.0 -1.0 ValueError 0.0 1.0 ValueError 0.0 1.0 0.0 1.0 inf 1.0 nan 1.0 1.0 0.0 1.0 ValueError ValueError ValueError 1.0 1.0 1.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 ValueError 0.0 1.0 ValueError 0.0 1.0 0.0 1.0 inf 1.0 nan 1.0 1.0 0.5 1.0 512.0 1.0 4.0 1.0 2.0 1.0 1.0 1.0 1.0 1.0 0.7071067811865476 1.0 0.5 1.0 0.25 1.0 0.125 1.0 OverflowError 0.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 inf 1.0 nan 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 0.001953125 1.0 0.25 1.0 0.5 1.0 1.0 1.0 1.0 1.0 1.4142135623730951 1.0 2.0 1.0 4.0 1.0 8.0 1.0 0.0 1.0 OverflowError 1.0 1.0 1.0 1.0 inf 1.0 0.0 1.0 nan 1.0 1.0 3.0 1.0 5.080526342529086e-05 1.0 0.1111111111111111 1.0 0.3333333333333333 1.0 1.0 1.0 1.0 1.0 1.7320508075688772 1.0 3.0 1.0 9.0 1.0 27.0 1.0 0.0 1.0 OverflowError 1.0 1.0 1.0 1.0 inf 1.0 0.0 1.0 nan 1.0 1.0 -1e+300 -1.0 -0.0 -1.0 0.0 1.0 -1e-300 -1.0 1.0 1.0 1.0 1.0 ValueError -1e+300 -1.0 OverflowError OverflowError 0.0 1.0 OverflowError ValueError ValueError inf 1.0 0.0 1.0 nan 1.0 1.0 1e+300 1.0 0.0 1.0 0.0 1.0 1e-300 1.0 1.0 1.0 1.0 1.0 1e+150 1.0 1e+300 1.0 OverflowError OverflowError 0.0 1.0 OverflowError 1.0 1.0 1.0 1.0 inf 1.0 0.0 1.0 nan 1.0 1.0 -5e-324 -1.0 OverflowError OverflowError OverflowError 1.0 1.0 1.0 1.0 ValueError -5e-324 -1.0 0.0 1.0 -0.0 -1.0 OverflowError 0.0 1.0 ValueError ValueError 0.0 1.0 inf 1.0 nan 1.0 1.0 5e-324 1.0 OverflowError OverflowError OverflowError 1.0 1.0 1.0 1.0 2.2227587494850775e-162 1.0 5e-324 1.0 0.0 1.0 0.0 1.0 OverflowError 0.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 inf 1.0 nan 1.0 1.0 inf 1.0 0.0 1.0 0.0 1.0 0.0 1.0 1.0 1.0 1.0 1.0 inf 1.0 inf 1.0 inf 1.0 inf 1.0 0.0 1.0 inf 1.0 0.0 1.0 inf 1.0 inf 1.0 0.0 1.0 nan 1.0 1.0 -inf -1.0 -0.0 -1.0 0.0 1.0 -0.0 -1.0 1.0 1.0 1.0 1.0 inf 1.0 -inf -1.0 inf 1.0 -inf -1.0 0.0 1.0 inf 1.0 0.0 1.0 inf 1.0 inf 1.0 0.0 1.0 nan 1.0 1.0 nan nan nan nan 1.0 1.0 1.0 1.0 nan nan nan nan nan nan nan nan nan nan nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.radians(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 0.017453292519943295 1.0 -0.0 -1.0 0.0 1.0 -0.017453292519943295 -1.0 0.017453292519943295 1.0 -0.03490658503988659 -1.0 0.03490658503988659 1.0 -0.008726646259971648 -1.0 0.008726646259971648 1.0 -0.0174532925199433 -1.0 -0.017453292519943292 -1.0 0.017453292519943292 1.0 0.0174532925199433 1.0 -0.0 -1.0 0.0 1.0 -1.7453292519943295e-302 -1.0 1.7453292519943295e-302 1.0 -17.453292519943297 -1.0 17.453292519943297 1.0 -1.7453292519943297e+298 -1.0 1.7453292519943297e+298 1.0 1.6097821017949162e+17 1.0 -1.6097821017949162e+17 -1.0 inf 1.0 -inf -1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x, y):
try:
value = m.remainder(x, y)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -9, -2, -1, -0.0, 0.0, 0.5, 1.0, 2.0, 3.0, -1e300, 1e300, -5e-324, 5e-324, m.inf, -m.inf, m.nan]:
for y in [False, True, -9, -2, -1, -0.0, 0.0, 0.5, 1.0, 2.0, 3.0, -1e300, 1e300, -5e-324, 5e-324, m.inf, -m.inf, m.nan]:
checked(x, y)
checked("bad", 1)
checked(1, "bad")
checked(None, 1)
checked(1, None)
return 0
Expected standard output:
ValueError 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 ValueError ValueError 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 nan ValueError 0.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 ValueError ValueError 0.0 1.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 0.0 1.0 1.0 1.0 1.0 1.0 nan ValueError -0.0 -1.0 -0.0 -1.0 -1.0 -1.0 -0.0 -1.0 ValueError ValueError -0.0 -1.0 -0.0 -1.0 -1.0 -1.0 -0.0 -1.0 -9.0 -1.0 -9.0 -1.0 -0.0 -1.0 -0.0 -1.0 -9.0 -1.0 -9.0 -1.0 nan ValueError -0.0 -1.0 -2.0 -1.0 -0.0 -1.0 -0.0 -1.0 ValueError ValueError -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 1.0 1.0 -2.0 -1.0 -2.0 -1.0 -0.0 -1.0 -0.0 -1.0 -2.0 -1.0 -2.0 -1.0 nan ValueError -0.0 -1.0 -1.0 -1.0 -1.0 -1.0 -0.0 -1.0 ValueError ValueError -0.0 -1.0 -0.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -0.0 -1.0 -0.0 -1.0 -1.0 -1.0 -1.0 -1.0 nan ValueError -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 ValueError ValueError -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 nan ValueError 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 ValueError ValueError 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 nan ValueError 0.5 1.0 0.5 1.0 0.5 1.0 0.5 1.0 ValueError ValueError 0.0 1.0 0.5 1.0 0.5 1.0 0.5 1.0 0.5 1.0 0.5 1.0 0.0 1.0 0.0 1.0 0.5 1.0 0.5 1.0 nan ValueError 0.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 ValueError ValueError 0.0 1.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 0.0 1.0 1.0 1.0 1.0 1.0 nan ValueError 0.0 1.0 2.0 1.0 0.0 1.0 0.0 1.0 ValueError ValueError 0.0 1.0 0.0 1.0 0.0 1.0 -1.0 -1.0 2.0 1.0 2.0 1.0 0.0 1.0 0.0 1.0 2.0 1.0 2.0 1.0 nan ValueError 0.0 1.0 3.0 1.0 -1.0 -1.0 0.0 1.0 ValueError ValueError 0.0 1.0 0.0 1.0 -1.0 -1.0 0.0 1.0 3.0 1.0 3.0 1.0 0.0 1.0 0.0 1.0 3.0 1.0 3.0 1.0 nan ValueError -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 ValueError ValueError -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -0.0 -1.0 -1e+300 -1.0 -1e+300 -1.0 nan ValueError 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 ValueError ValueError 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 1e+300 1.0 1e+300 1.0 nan ValueError -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 ValueError ValueError -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 -5e-324 -1.0 -0.0 -1.0 -0.0 -1.0 -5e-324 -1.0 -5e-324 -1.0 nan ValueError 5e-324 1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 ValueError ValueError 5e-324 1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 5e-324 1.0 0.0 1.0 0.0 1.0 5e-324 1.0 5e-324 1.0 nan ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError nan ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError ValueError nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.sin(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 0.8414709848078965 1.0 -0.0 -1.0 0.0 1.0 -0.8414709848078965 -1.0 0.8414709848078965 1.0 -0.9092974268256817 -1.0 0.9092974268256817 1.0 -0.479425538604203 -1.0 0.479425538604203 1.0 -0.8414709848078966 -1.0 -0.8414709848078964 -1.0 0.8414709848078964 1.0 0.8414709848078966 1.0 -5e-324 -1.0 5e-324 1.0 -1e-300 -1.0 1e-300 1.0 -0.8268795405320025 -1.0 0.8268795405320025 1.0 0.8178819121159085 1.0 -0.8178819121159085 -1.0 0.9999303766734422 1.0 -0.9999303766734422 -1.0 ValueError ValueError nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.sinh(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 1.1752011936438014 1.0 -0.0 -1.0 0.0 1.0 -1.1752011936438014 -1.0 1.1752011936438014 1.0 -3.626860407847019 -1.0 3.626860407847019 1.0 -0.5210953054937474 -1.0 0.5210953054937474 1.0 -1.1752011936438018 -1.0 -1.1752011936438014 -1.0 1.1752011936438014 1.0 1.1752011936438018 1.0 -5e-324 -1.0 5e-324 1.0 -1e-300 -1.0 1e-300 1.0 OverflowError OverflowError OverflowError OverflowError OverflowError OverflowError inf 1.0 -inf -1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.sqrt(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 1.0 1.0 -0.0 -1.0 0.0 1.0 ValueError 1.0 1.0 ValueError 1.4142135623730951 1.0 ValueError 0.7071067811865476 1.0 ValueError ValueError 0.9999999999999999 1.0 1.0 1.0 ValueError 2.2227587494850775e-162 1.0 ValueError 1e-150 1.0 ValueError 31.622776601683793 1.0 ValueError 1e+150 1.0 3037000499.97605 1.0 ValueError inf 1.0 ValueError nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def main():
print(m.sumprod([3, -2, 4], (10, 5, 2)), m.sumprod([], ()))
print(m.sumprod(range(4), (True, False, True, True)))
k = 9223372036854775807
print(m.sumprod([k, k, 7], [k, -k, 1]))
low = -9223372036854775808
print(m.sumprod([low, low, low], [low, k, 2]))
delta = 2.0**-27
print(m.sumprod((1.0 + delta, -1.0), (1.0 - delta, 1.0)) == -(delta * delta))
print(m.sumprod([1e16, 1.0, -1e16], [1, 1, 1]))
print(m.sumprod([0.25, 0.5, 0.25], [80, 90, 100]))
print(m.sumprod([-0.0], [1]), m.sumprod([m.inf], [2.0]), m.isnan(m.sumprod([m.inf], [0])))
try:
m.sumprod([1], [2, 3])
except ValueError:
print("length")
try:
m.sumprod([None, 1], [3])
except TypeError:
print("element")
return 0
Expected standard output:
28 0 5 7 -9223372036854775808 True 1.0 90.0 0.0 inf True length element
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.tan(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 1.5574077246549023 1.0 -0.0 -1.0 0.0 1.0 -1.5574077246549023 -1.0 1.5574077246549023 1.0 2.185039863261519 1.0 -2.185039863261519 -1.0 -0.5463024898437905 -1.0 0.5463024898437905 1.0 -1.557407724654903 -1.0 -1.5574077246549018 -1.0 1.5574077246549018 1.0 1.557407724654903 1.0 -5e-324 -1.0 5e-324 1.0 -1e-300 -1.0 1e-300 1.0 -1.4703241557027185 -1.0 1.4703241557027185 1.0 -1.4214488238747245 -1.0 1.4214488238747245 1.0 84.73931296875567 1.0 -84.73931296875567 -1.0 ValueError ValueError nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.tanh(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0.0 1.0 0.7615941559557649 1.0 -0.0 -1.0 0.0 1.0 -0.7615941559557649 -1.0 0.7615941559557649 1.0 -0.9640275800758169 -1.0 0.9640275800758169 1.0 -0.46211715726000974 -1.0 0.46211715726000974 1.0 -0.761594155955765 -1.0 -0.7615941559557649 -1.0 0.7615941559557649 1.0 0.761594155955765 1.0 -5e-324 -1.0 5e-324 1.0 -1e-300 -1.0 1e-300 1.0 -1.0 -1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 1.0 1.0 -1.0 -1.0 1.0 1.0 -1.0 -1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.trunc(x)
print(value)
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1.5, 1.5, -0.1, 0.1, -5e-324, 5e-324, 9007199254740993, -9007199254740993, 9223372036854775807, -9223372036854775808, 9223372036854774784.0, -9223372036854775808.0, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
0 1 0 0 -1 1 0 0 0 0 9007199254740993 -9007199254740993 9223372036854775807 -9223372036854775808 9223372036854774784 -9223372036854775808 OverflowError OverflowError ValueError TypeError TypeError TypeError TypeError
Expected exit code: 0
*import math as m
def checked(x):
try:
value = m.ulp(x)
print(value)
if not m.isnan(value):
print(m.copysign(1, value))
except ValueError:
print("ValueError")
except OverflowError:
print("OverflowError")
except TypeError:
print("TypeError")
except ZeroDivisionError:
print("ZeroDivisionError")
def main():
for x in [False, True, -0.0, 0.0, -1, 1, -2, 2, -0.5, 0.5, -1.0000000000000002, -0.9999999999999999, 0.9999999999999999, 1.0000000000000002, -5e-324, 5e-324, -1e-300, 1e-300, -1000.0, 1000.0, -1e300, 1e300, 9223372036854775807, -9223372036854775808, m.inf, -m.inf, m.nan, "bad", None, [], {}]:
checked(x)
return 0
Expected standard output:
5e-324 1.0 2.220446049250313e-16 1.0 5e-324 1.0 5e-324 1.0 2.220446049250313e-16 1.0 2.220446049250313e-16 1.0 4.440892098500626e-16 1.0 4.440892098500626e-16 1.0 1.1102230246251565e-16 1.0 1.1102230246251565e-16 1.0 2.220446049250313e-16 1.0 1.1102230246251565e-16 1.0 1.1102230246251565e-16 1.0 2.220446049250313e-16 1.0 5e-324 1.0 5e-324 1.0 1.6578092e-316 1.0 1.6578092e-316 1.0 1.1368683772161603e-13 1.0 1.1368683772161603e-13 1.0 1.487016908477783e+284 1.0 1.487016908477783e+284 1.0 2048.0 1.0 2048.0 1.0 inf 1.0 inf 1.0 nan TypeError TypeError TypeError TypeError
Expected exit code: 0
e = 0x1.5bf0a8b145769p+1
Binary64 approximation of the base of natural logarithms.
inf = inf
Positive infinity; negate it to express negative infinity.
nan = nan
A quiet NaN value; classify it using isnan, not equality.
pi = 0x1.921fb54442d18p+1
Binary64 approximation of the circle constant pi.
tau = 0x1.921fb54442d18p+2
Binary64 approximation of two times pi.