(f, x)
| 223 | f.write(b'\x00') |
| 224 | |
| 225 | def _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 | |
| 258 | with warnings.catch_warnings(): |
| 259 | warnings.simplefilter("ignore", DeprecationWarning) |
no test coverage detected