> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/python/cpython/llms.txt
> Use this file to discover all available pages before exploring further.

# Floating Point Objects

> Working with Python float type

## Overview

Python floats are implemented as C `double` precision floating-point numbers.

## Type Object

```c theme={null}
PyTypeObject PyFloat_Type
```

## Type Checking

```c theme={null}
int PyFloat_Check(PyObject *p)
int PyFloat_CheckExact(PyObject *p)
```

## Creating Floats

```c theme={null}
PyObject* PyFloat_FromDouble(double v)
PyObject* PyFloat_FromString(PyObject *str)
```

**Example:**

```c theme={null}
PyObject *pi = PyFloat_FromDouble(3.14159);
return pi;
```

## Converting to C double

```c theme={null}
double PyFloat_AsDouble(PyObject *pyfloat)
```

**Example:**

```c theme={null}
double value = PyFloat_AsDouble(obj);
if (value == -1.0 && PyErr_Occurred())
    return NULL;
```

## Special Values

```c theme={null}
Py_RETURN_NAN  // Return NaN
Py_RETURN_INF(sign)  // Return infinity
```

**Example:**

```c theme={null}
if (is_invalid(x))
    Py_RETURN_NAN;
```

## See Also

* [Integer Objects](/c-api/long)
* [Object Protocol](/c-api/object)
