|
9 | 9 |
|
10 | 10 | from pyccel.ast.basic import ScopedAstNode
|
11 | 11 |
|
12 |
| -from pyccel.ast.builtins import PythonRange, PythonComplex |
| 12 | +from pyccel.ast.builtins import PythonRange, PythonComplex, DtypePrecisionToCastFunction |
13 | 13 | from pyccel.ast.builtins import PythonPrint, PythonType
|
14 | 14 | from pyccel.ast.builtins import PythonList, PythonTuple
|
15 | 15 |
|
@@ -1963,28 +1963,6 @@ def _print_FunctionCall(self, expr):
|
1963 | 1963 | else:
|
1964 | 1964 | return call_code
|
1965 | 1965 |
|
1966 |
| - def _print_Constant(self, expr): |
1967 |
| - """ Convert a Python expression with a math constant call to C |
1968 |
| - function call |
1969 |
| -
|
1970 |
| - Parameters |
1971 |
| - ---------- |
1972 |
| - expr : Pyccel ast node |
1973 |
| - Python expression with a Math constant |
1974 |
| -
|
1975 |
| - Returns |
1976 |
| - ------- |
1977 |
| - string |
1978 |
| - String represent the value of the constant |
1979 |
| -
|
1980 |
| - Example |
1981 |
| - ------- |
1982 |
| - math.pi ==> 3.14159265358979 |
1983 |
| -
|
1984 |
| - """ |
1985 |
| - val = LiteralFloat(expr.value) |
1986 |
| - return self._print(val) |
1987 |
| - |
1988 | 1966 | def _print_Return(self, expr):
|
1989 | 1967 | code = ''
|
1990 | 1968 | args = [ObjectAddress(a) if isinstance(a, Variable) and self.is_c_pointer(a) else a for a in expr.expr]
|
@@ -2329,14 +2307,19 @@ def _print_Constant(self, expr):
|
2329 | 2307 | if expr == math_constants['inf']:
|
2330 | 2308 | self.add_import(c_imports['math'])
|
2331 | 2309 | return 'HUGE_VAL'
|
| 2310 | + elif expr == math_constants['nan']: |
| 2311 | + self.add_import(c_imports['math']) |
| 2312 | + return 'NAN' |
2332 | 2313 | elif expr == math_constants['pi']:
|
2333 | 2314 | self.add_import(c_imports['math'])
|
2334 | 2315 | return 'M_PI'
|
2335 | 2316 | elif expr == math_constants['e']:
|
2336 | 2317 | self.add_import(c_imports['math'])
|
2337 | 2318 | return 'M_E'
|
2338 | 2319 | else:
|
2339 |
| - raise NotImplementedError("Constant not implemented") |
| 2320 | + cast_func = DtypePrecisionToCastFunction[expr.dtype] |
| 2321 | + return self._print(cast_func(expr.value)) |
| 2322 | + |
2340 | 2323 |
|
2341 | 2324 | def _print_Variable(self, expr):
|
2342 | 2325 | if self.is_c_pointer(expr):
|
|
0 commit comments