MCPcopy Create free account
hub / github.com/numpy/numpy / long_double_representation

Function long_double_representation

numpy/core/setup_common.py:336–392  ·  view source on GitHub ↗

Given a binary dump as given by GNU od -b, look for long double representation.

(lines)

Source from the content-addressed store, hash-verified

334 ['000'] * 8)
335
336def long_double_representation(lines):
337 """Given a binary dump as given by GNU od -b, look for long double
338 representation."""
339
340 # Read contains a list of 32 items, each item is a byte (in octal
341 # representation, as a string). We 'slide' over the output until read is of
342 # the form before_seq + content + after_sequence, where content is the long double
343 # representation:
344 # - content is 12 bytes: 80 bits Intel representation
345 # - content is 16 bytes: 80 bits Intel representation (64 bits) or quad precision
346 # - content is 8 bytes: same as double (not implemented yet)
347 read = [''] * 32
348 saw = None
349 for line in lines:
350 # we skip the first word, as od -b output an index at the beginning of
351 # each line
352 for w in line.split()[1:]:
353 read.pop(0)
354 read.append(w)
355
356 # If the end of read is equal to the after_sequence, read contains
357 # the long double
358 if read[-8:] == _AFTER_SEQ:
359 saw = copy.copy(read)
360 # if the content was 12 bytes, we only have 32 - 8 - 12 = 12
361 # "before" bytes. In other words the first 4 "before" bytes went
362 # past the sliding window.
363 if read[:12] == _BEFORE_SEQ[4:]:
364 if read[12:-8] == _INTEL_EXTENDED_12B:
365 return 'INTEL_EXTENDED_12_BYTES_LE'
366 if read[12:-8] == _MOTOROLA_EXTENDED_12B:
367 return 'MOTOROLA_EXTENDED_12_BYTES_BE'
368 # if the content was 16 bytes, we are left with 32-8-16 = 16
369 # "before" bytes, so 8 went past the sliding window.
370 elif read[:8] == _BEFORE_SEQ[8:]:
371 if read[8:-8] == _INTEL_EXTENDED_16B:
372 return 'INTEL_EXTENDED_16_BYTES_LE'
373 elif read[8:-8] == _IEEE_QUAD_PREC_BE:
374 return 'IEEE_QUAD_BE'
375 elif read[8:-8] == _IEEE_QUAD_PREC_LE:
376 return 'IEEE_QUAD_LE'
377 elif read[8:-8] == _IBM_DOUBLE_DOUBLE_LE:
378 return 'IBM_DOUBLE_DOUBLE_LE'
379 elif read[8:-8] == _IBM_DOUBLE_DOUBLE_BE:
380 return 'IBM_DOUBLE_DOUBLE_BE'
381 # if the content was 8 bytes, left with 32-8-8 = 16 bytes
382 elif read[:16] == _BEFORE_SEQ:
383 if read[16:-8] == _IEEE_DOUBLE_LE:
384 return 'IEEE_DOUBLE_LE'
385 elif read[16:-8] == _IEEE_DOUBLE_BE:
386 return 'IEEE_DOUBLE_BE'
387
388 if saw is not None:
389 raise ValueError("Unrecognized format (%s)" % saw)
390 else:
391 # We never detected the after_sequence
392 raise ValueError("Could not lock sequences (%s)" % saw)
393

Callers 1

Calls 2

splitMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected