diff options
author | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
---|---|---|
committer | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
commit | 4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch) | |
tree | ee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/asyncpg/pgproto/codecs/float.pyx | |
parent | cc961e04ba734dd72309fb548a2f97d67d578813 (diff) | |
download | gn-ai-master.tar.gz |
Diffstat (limited to '.venv/lib/python3.12/site-packages/asyncpg/pgproto/codecs/float.pyx')
-rw-r--r-- | .venv/lib/python3.12/site-packages/asyncpg/pgproto/codecs/float.pyx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/asyncpg/pgproto/codecs/float.pyx b/.venv/lib/python3.12/site-packages/asyncpg/pgproto/codecs/float.pyx new file mode 100644 index 00000000..94eda03a --- /dev/null +++ b/.venv/lib/python3.12/site-packages/asyncpg/pgproto/codecs/float.pyx @@ -0,0 +1,34 @@ +# Copyright (C) 2016-present the asyncpg authors and contributors +# <see AUTHORS file> +# +# This module is part of asyncpg and is released under +# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0 + + +from libc cimport math + + +cdef float4_encode(CodecContext settings, WriteBuffer buf, obj): + cdef double dval = cpython.PyFloat_AsDouble(obj) + cdef float fval = <float>dval + if math.isinf(fval) and not math.isinf(dval): + raise ValueError('value out of float32 range') + + buf.write_int32(4) + buf.write_float(fval) + + +cdef float4_decode(CodecContext settings, FRBuffer *buf): + cdef float f = hton.unpack_float(frb_read(buf, 4)) + return cpython.PyFloat_FromDouble(f) + + +cdef float8_encode(CodecContext settings, WriteBuffer buf, obj): + cdef double dval = cpython.PyFloat_AsDouble(obj) + buf.write_int32(8) + buf.write_double(dval) + + +cdef float8_decode(CodecContext settings, FRBuffer *buf): + cdef double f = hton.unpack_double(frb_read(buf, 8)) + return cpython.PyFloat_FromDouble(f) |