Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
5620f68
[mypyc] Use an unboxed representation for floats
JukkaL Dec 28, 2021
0ea696d
Fix after rebase
JukkaL Dec 31, 2022
3d5f397
Support undefined floats in locals
JukkaL Aug 27, 2022
8954cc9
Support float default args
JukkaL Aug 27, 2022
62abec1
WIP mixed operations test case
JukkaL Aug 31, 2022
c8214d0
Support mixed float/int arithmetic
JukkaL Sep 10, 2022
f222c1f
Add run tests
JukkaL Sep 10, 2022
80ebe04
Add primitive for true divide of int by int (resulting in a float)
JukkaL Sep 10, 2022
8ae9c98
Make float(f) a no-op for float arguments
JukkaL Sep 10, 2022
9d874ce
Fix overflow handling when converting to int
JukkaL Sep 10, 2022
916cda9
WIP float divide by zero test case
JukkaL Sep 10, 2022
3bbc76a
Add some irchecking of int and float ops
JukkaL Sep 11, 2022
c208066
Implement float division and modulus
JukkaL Sep 11, 2022
218def2
Add and improve some math primitives
JukkaL Sep 11, 2022
de5dd64
Improve run tests
JukkaL Sep 11, 2022
c1cdda1
Make +x a no-op for floats
JukkaL Sep 14, 2022
47acc06
Fix float negation
JukkaL Sep 14, 2022
8dbd05a
More tests
JukkaL Sep 24, 2022
fc5cd16
Fix float abs
JukkaL Sep 24, 2022
0b2a642
Add more test cases
JukkaL Sep 24, 2022
1cb15ca
Add primitive for math.exp
JukkaL Sep 24, 2022
987d93e
Add primitive for math.floor
JukkaL Sep 24, 2022
1054d4a
Add primitive for math.ceil
JukkaL Sep 24, 2022
f54e618
Add primitive for math.fabs
JukkaL Sep 24, 2022
d7e044e
Add primitive for math.log
JukkaL Sep 24, 2022
2d3b7a3
Add primitive for math.tan and math primiive run tests
JukkaL Sep 24, 2022
289bc29
Add more float values to test
JukkaL Sep 24, 2022
2de8e0b
Black
JukkaL Sep 24, 2022
2141f4d
Add primitive for float floor division
JukkaL Sep 24, 2022
c98c043
Refactor test cases
JukkaL Sep 24, 2022
40e991a
Add primitive for math.pow
JukkaL Sep 24, 2022
fd117e6
Refactor test case
JukkaL Sep 24, 2022
d721828
Add docstrings
JukkaL Sep 24, 2022
6205767
Fix test cases
JukkaL Dec 31, 2022
9a4db2d
Fix math.pow on Python 3.11
JukkaL Dec 31, 2022
4c89337
Update float to native int conversion tests
JukkaL Jan 27, 2023
71d8568
Update i64 test case
JukkaL Jan 27, 2023
1462b9f
Update test case on Python 3.11 (not sure why this changed)
JukkaL Jan 27, 2023
0d710b1
isort and lint
JukkaL Jan 27, 2023
4b4b7a1
Test coercing from bool to float
JukkaL Jan 28, 2023
72db9fc
Test floats in properties, glue methods and traits
JukkaL Jan 28, 2023
4a4376c
Update test case
JukkaL Mar 4, 2023
bdca8ab
Disallow narrowing a float value to int
JukkaL Mar 11, 2023
cc2aedf
Fix type check
JukkaL Mar 11, 2023
937df67
Add test case
JukkaL Mar 11, 2023
e8e694f
Fix test case
JukkaL Mar 11, 2023
00fd468
Add test case
JukkaL Mar 11, 2023
01f670b
Fix test cases to not assign ints to float variables
JukkaL Mar 11, 2023
6cd75b8
Update test case
JukkaL Mar 11, 2023
6384c03
Add i64 to float conversion test case
JukkaL Mar 11, 2023
a177197
Fix tests on 32-bit architecture
JukkaL Mar 11, 2023
3c5931d
Add missing error check to property getter wrappers
JukkaL Mar 11, 2023
8ab5e25
Work around mypyc bug
JukkaL Mar 11, 2023
e85f057
Work around another issue
JukkaL Mar 11, 2023
e45dba5
Fix test on 3.11
JukkaL Mar 12, 2023
c9d7147
Add subnormal values
JukkaL Mar 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add primitive for math.tan and math primiive run tests
  • Loading branch information
JukkaL committed Mar 11, 2023
commit 2d3b7a3be87fd39e08d68b15205a352a86fcdbef
1 change: 1 addition & 0 deletions mypyc/lib-rt/CPy.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ static inline bool CPyTagged_IsLe(CPyTagged left, CPyTagged right) {

double CPyFloat_Sin(double x);
double CPyFloat_Cos(double x);
double CPyFloat_Tan(double x);
double CPyFloat_Sqrt(double x);
double CPyFloat_Exp(double x);
double CPyFloat_Log(double x);
Expand Down
7 changes: 7 additions & 0 deletions mypyc/lib-rt/float_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ double CPyFloat_Cos(double x) {
return v;
}

double CPyFloat_Tan(double x) {
if (unlikely(isinf(x))) {
return CPy_DomainError();
}
return tan(x);
}

double CPyFloat_Sqrt(double x) {
if (x < 0.0) {
return CPy_DomainError();
Expand Down
9 changes: 9 additions & 0 deletions mypyc/primitives/float_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
error_kind=ERR_MAGIC_OVERLAPPING,
)

# math.tan(float)
function_op(
name="math.tan",
arg_types=[float_rprimitive],
return_type=float_rprimitive,
c_function_name="CPyFloat_Tan",
error_kind=ERR_MAGIC_OVERLAPPING,
)

# math.sqrt(float)
function_op(
name="math.sqrt",
Expand Down
3 changes: 2 additions & 1 deletion mypyc/test-data/fixtures/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
float(n) * 0.25 for n in range(-10, 10)
] + [
-0.0, 1.0/3.0, math.sqrt(2.0), 1.23e200, -2.34e200, 5.43e-100, -6.532e-200,
float('inf'), -float('inf'), float('nan'), FLOAT_MAGIC
float('inf'), -float('inf'), float('nan'), FLOAT_MAGIC, math.pi, 2.0 * math.pi, math.pi / 2.0,
-math.pi / 2.0
]

@contextmanager
Expand Down
102 changes: 102 additions & 0 deletions mypyc/test-data/run-math.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Test cases for the math module (compile and run)

[case testMathOps]
from typing import Any
from typing_extensions import Final
import math
from testutil import assertRaises, float_vals, assertDomainError, assertMathRangeError

pymath: Any = math

def test_sqrt() -> None:
for x in float_vals:
if x >= 0 or math.isnan(x):
assert repr(math.sqrt(x)) == repr(pymath.sqrt(x))
elif x < 0:
with assertDomainError():
math.sqrt(x)
with assertDomainError():
pymath.sqrt(x)

def test_sin() -> None:
for x in float_vals:
if not math.isinf(x):
assert repr(math.sin(x)) == repr(pymath.sin(x))
else:
with assertDomainError():
math.sin(x)
with assertDomainError():
pymath.sin(x)

def test_cos() -> None:
for x in float_vals:
if not math.isinf(x):
assert repr(math.cos(x)) == repr(pymath.cos(x))
else:
with assertDomainError():
math.cos(x)
with assertDomainError():
pymath.cos(x)

def test_tan() -> None:
for x in float_vals:
if math.isinf(x):
with assertDomainError():
math.tan(x)
else:
assert repr(math.tan(x)) == repr(pymath.tan(x))

def test_exp() -> None:
for x in float_vals:
if math.isfinite(x) and x > 1e100:
with assertMathRangeError():
math.exp(x)
else:
assert repr(math.exp(x)) == repr(pymath.exp(x))

def test_log() -> None:
for x in float_vals:
if x <= 0.0:
with assertDomainError():
math.log(x)
else:
assert repr(math.log(x)) == repr(pymath.log(x))

def test_floor() -> None:
for x in float_vals:
if math.isinf(x):
with assertRaises(OverflowError, "cannot convert float infinity to integer"):
math.floor(x)
elif math.isnan(x):
with assertRaises(ValueError, "cannot convert float NaN to integer"):
math.floor(x)
else:
assert repr(math.floor(x)) == repr(pymath.floor(x))

def test_ceil() -> None:
for x in float_vals:
if math.isinf(x):
with assertRaises(OverflowError, "cannot convert float infinity to integer"):
math.ceil(x)
elif math.isnan(x):
with assertRaises(ValueError, "cannot convert float NaN to integer"):
math.ceil(x)
else:
assert repr(math.ceil(x)) == repr(pymath.ceil(x))

def test_fabs() -> None:
for x in float_vals:
assert repr(math.fabs(x)) == repr(pymath.fabs(x))

def test_copysign() -> None:
for x in float_vals:
for y in float_vals:
assert repr(math.copysign(x, y)) == repr(pymath.copysign(x, y))

def test_isinf() -> None:
for x in float_vals:
assert repr(math.isinf(x)) == repr(pymath.isinf(x))

def test_isnan() -> None:
for x in float_vals:
assert repr(math.isnan(x)) == repr(pymath.isnan(x))
2 changes: 2 additions & 0 deletions test-data/unit/lib-stub/math.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pi: float
def sqrt(__x: float) -> float: ...
def sin(__x: float) -> float: ...
def cos(__x: float) -> float: ...
def tan(__x: float) -> float: ...
def exp(__x: float) -> float: ...
def log(__x: float) -> float: ...
def floor(__x: float) -> int: ...
Expand Down