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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions mypyc/primitives/float_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@
return_type=float_rprimitive,
c_function_name='PyFloat_FromString',
error_kind=ERR_MAGIC)

# abs(float)
c_function_op(
name='builtins.abs',
arg_types=[float_rprimitive],
return_type=float_rprimitive,
c_function_name='PyNumber_Absolute',
error_kind=ERR_MAGIC)
2 changes: 2 additions & 0 deletions mypyc/test-data/fixtures/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def __add__(self, n: float) -> float: pass
def __sub__(self, n: float) -> float: pass
def __mul__(self, n: float) -> float: pass
def __truediv__(self, n: float) -> float: pass
def __neg__(self) -> float: pass

class complex:
def __init__(self, x: object, y: object = None) -> None: pass
Expand Down Expand Up @@ -251,6 +252,7 @@ def zip(x: Iterable[T], y: Iterable[S]) -> Iterator[Tuple[T, S]]: ...
@overload
def zip(x: Iterable[T], y: Iterable[S], z: Iterable[V]) -> Iterator[Tuple[T, S, V]]: ...
def eval(e: str) -> Any: ...
def abs(x: float) -> float: ...

# Dummy definitions.
class classmethod: pass
Expand Down
8 changes: 8 additions & 0 deletions mypyc/test-data/run-floats.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ assert str_to_float("1.234567") == 1.234567
assert str_to_float("44324") == 44324.0
assert str_to_float("23.4") == 23.4
assert str_to_float("-43.44e-4") == -43.44e-4

[case testFloatAbs]
def test_abs() -> None:
assert abs(0.0) == 0.0
assert abs(-1.234567) == 1.234567
assert abs(44324.732) == 44324.732
assert abs(-23.4) == 23.4
assert abs(-43.44e-4) == 43.44e-4