MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _write_float

Function _write_float

tools/python-3.11.9-amd64/Lib/aifc.py:225–256  ·  view source on GitHub ↗
(f, x)

Source from the content-addressed store, hash-verified

223 f.write(b'\x00')
224
225def _write_float(f, x):
226 import math
227 if x < 0:
228 sign = 0x8000
229 x = x * -1
230 else:
231 sign = 0
232 if x == 0:
233 expon = 0
234 himant = 0
235 lomant = 0
236 else:
237 fmant, expon = math.frexp(x)
238 if expon > 16384 or fmant >= 1 or fmant != fmant: # Infinity or NaN
239 expon = sign|0x7FFF
240 himant = 0
241 lomant = 0
242 else: # Finite
243 expon = expon + 16382
244 if expon < 0: # denormalized
245 fmant = math.ldexp(fmant, expon)
246 expon = 0
247 expon = expon | sign
248 fmant = math.ldexp(fmant, 32)
249 fsmant = math.floor(fmant)
250 himant = int(fsmant)
251 fmant = math.ldexp(fmant - fsmant, 32)
252 fsmant = math.floor(fmant)
253 lomant = int(fsmant)
254 _write_ushort(f, expon)
255 _write_ulong(f, himant)
256 _write_ulong(f, lomant)
257
258with warnings.catch_warnings():
259 warnings.simplefilter("ignore", DeprecationWarning)

Callers 1

_write_headerMethod · 0.85

Calls 2

_write_ushortFunction · 0.85
_write_ulongFunction · 0.85

Tested by

no test coverage detected