-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloat.h
More file actions
53 lines (39 loc) · 880 Bytes
/
Float.h
File metadata and controls
53 lines (39 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include "./PythonCore.h"
#include <concepts>
#include "./Object.h"
#include "./String.h"
namespace xpo {
namespace python {
struct Float : public Object {
Float(PyObject* pyObject)
: Object(PyFloat_Check(pyObject) ? pyObject : nullptr)
{
}
template <std::integral V>
Float(V value)
: Object(PyFloat_FromDouble(static_cast<double>(value)))
{
}
template <std::floating_point V>
Float(V value)
: Object(PyFloat_FromDouble(value))
{
}
Float(char const* str)
: Object(PyFloat_FromString(String(str)))
{
}
template <class T>
requires std::is_integral_v<T>
operator T() {
return static_cast<T>(PyFloat_AsDouble(m_pyObject));
}
template <class T>
requires std::is_floating_point_v<T>
operator T() {
return static_cast<T>(PyFloat_AsDouble(m_pyObject));
}
};
}
}