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
17 changes: 17 additions & 0 deletions mypyc/primitives/float_ops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Primitive float ops."""

from mypyc.ir.ops import ERR_MAGIC
from mypyc.ir.rtypes import (
str_rprimitive, float_rprimitive
)
from mypyc.primitives.registry import (
c_function_op
)

# float(str)
c_function_op(
name='builtins.float',
arg_types=[str_rprimitive],
return_type=float_rprimitive,
c_function_name='PyFloat_FromString',
error_kind=ERR_MAGIC)
1 change: 1 addition & 0 deletions mypyc/primitives/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,4 @@ def load_address_op(name: str,
import mypyc.primitives.dict_ops # noqa
import mypyc.primitives.tuple_ops # noqa
import mypyc.primitives.misc_ops # noqa
import mypyc.primitives.float_ops # noqa
12 changes: 12 additions & 0 deletions mypyc/test-data/run-floats.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[case testStrToFloat]
def str_to_float(x: str) -> float:
return float(x)

[file driver.py]
from native import str_to_float

assert str_to_float("1") == 1.0
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
1 change: 1 addition & 0 deletions mypyc/test/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'run-misc.test',
'run-functions.test',
'run-integers.test',
'run-floats.test',
'run-bools.test',
'run-strings.test',
'run-tuples.test',
Expand Down