Nuitka
The Python compiler
Loading...
Searching...
No Matches
complex.h
1// Copyright 2025, Kay Hayen, mailto:kay.hayen@gmail.com find license text at end of file
2
3#ifndef __NUITKA_HELPER_COMPLEX_H__
4#define __NUITKA_HELPER_COMPLEX_H__
5
6NUITKA_MAY_BE_UNUSED static PyObject *BUILTIN_COMPLEX1(PyThreadState *tstate, PyObject *real) {
7 CHECK_OBJECT(real);
8
9 // TODO: Very lazy here, we should create the values ourselves, surely a
10 // a lot of optimization can be had that way. At least use PyComplex_RealAsDouble
11 // where possible.
12 return CALL_FUNCTION_WITH_SINGLE_ARG(tstate, (PyObject *)&PyComplex_Type, real);
13}
14
15NUITKA_MAY_BE_UNUSED static PyObject *BUILTIN_COMPLEX2(PyThreadState *tstate, PyObject *real, PyObject *imag) {
16 if (real == NULL) {
17 assert(imag != NULL);
18
19 real = const_int_0;
20 }
21
22 CHECK_OBJECT(real);
23 CHECK_OBJECT(imag);
24
25 // TODO: Very lazy here, we should create the values ourselves, surely a
26 // a lot of optimization can be had that way. At least use PyComplex_FromDoubles
27 PyObject *args[] = {real, imag};
28 return CALL_FUNCTION_WITH_ARGS2(tstate, (PyObject *)&PyComplex_Type, args);
29}
30
31#endif
32
33// Part of "Nuitka", an optimizing Python compiler that is compatible and
34// integrates with CPython, but also works on its own.
35//
36// Licensed under the Apache License, Version 2.0 (the "License");
37// you may not use this file except in compliance with the License.
38// You may obtain a copy of the License at
39//
40// http://www.apache.org/licenses/LICENSE-2.0
41//
42// Unless required by applicable law or agreed to in writing, software
43// distributed under the License is distributed on an "AS IS" BASIS,
44// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45// See the License for the specific language governing permissions and
46// limitations under the License.