-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfloat.go
73 lines (63 loc) · 2.54 KB
/
float.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package cpy
/*
#include "Python.h"
#include "macro.h"
*/
import "C"
import "unsafe"
// Float is an instance of PyTypeObject represents the Python floating point type. This is the same object as float in
// the Python layer.
//
// Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_Type
var Float = togo((*C.PyObject)(unsafe.Pointer(&C.PyFloat_Type)))
// PyFloat_Check returns true if its argument is a PyFloatObject or a subtype of PyFloatObject. This function always
// succeeds.
//
// Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_Check
func PyFloat_Check(p *PyObject) bool {
return C._go_PyFloat_Check(toc(p)) != 0
}
// PyFloat_CheckExact returns true if its argument is a PyFloatObject, but not a subtype of PyFloatObject. This
// function always succeeds.
//
// Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_CheckExact
func PyFloat_CheckExact(p *PyObject) bool {
return C._go_PyFloat_CheckExact(toc(p)) != 0
}
// PyFloat_FromDouble creates a PyFloatObject object from v, or NULL on failure.
//
// Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_FromDouble
func PyFloat_FromDouble(v float64) *PyObject {
return togo(C.PyFloat_FromDouble(C.double(v)))
}
// PyFloat_FromString creates a PyFloatObject object based on the string value in str, or NULL on failure.
//
// Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_FromString
func PyFloat_FromString(str *PyObject) *PyObject {
return togo(C.PyFloat_FromString(toc(str)))
}
// PyFloat_AsDouble creates a PyFloatObject object based on the string value in str, or NULL on failure.
//
// Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_AsDouble
func PyFloat_AsDouble(obj *PyObject) float64 {
return float64(C.PyFloat_AsDouble(toc(obj)))
}
// PyFloat_GetInfo returns a structseq instance which contains information about the precision, minimum and maximum
// values of a float. It's a thin wrapper around the header file float.h.
//
// Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_GetInfo
func PyFloat_GetInfo() *PyObject {
return togo(C.PyFloat_GetInfo())
}
// PyFloat_GetMax returns the maximum representable finite float DBL_MAX as C double.
//
// Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_GetMax
func PyFloat_GetMax() float64 {
return float64(C.PyFloat_GetMax())
}
// PyFloat_GetMin returns the minimum normalized positive float DBL_MIN as C double.
//
// Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_GetMin
func PyFloat_GetMin() float64 {
return float64(C.PyFloat_GetMin())
}