mirror of
https://github.com/wassname/segpy.git
synced 2026-08-04 13:14:04 +08:00
Read IBM floats into the new IBMFloat type rather than converting directly to IEEE floats. This allows bit-perfect round-tripping.
This commit is contained in:
+3
-3
@@ -15,7 +15,7 @@ from segpy.catalog import CatalogBuilder
|
||||
from segpy.datatypes import CTYPES, size_in_bytes
|
||||
from segpy.encoding import guess_encoding, is_supported_encoding, UnsupportedEncodingError
|
||||
from segpy.binary_reel_header_definition import HEADER_DEF
|
||||
from segpy.ibm_float import ibm2ieee, ieee2ibm, IBMFloat
|
||||
from segpy.ibm_float import IBMFloat
|
||||
from segpy.revisions import canonicalize_revision
|
||||
from segpy.trace_header_definition import TRACE_HEADER_DEF
|
||||
from segpy.util import file_length, batched, pad, complementary_intervals, NATIVE_ENDIANNESS
|
||||
@@ -461,7 +461,7 @@ def unpack_ibm_floats(data, count):
|
||||
Returns:
|
||||
A sequence of floats.
|
||||
"""
|
||||
return array('d', (IBMFloat.from_bytes(data[i: i+4]) for i in range(0, count * 4, 4)))
|
||||
return [IBMFloat.from_bytes(data[i: i+4]) for i in range(0, count * 4, 4)]
|
||||
|
||||
|
||||
def unpack_values(buf, count, fmt, endian='>'):
|
||||
@@ -817,7 +817,7 @@ def pack_ibm_floats(values):
|
||||
A sequence of bytes. (Python 2 - a str object, Python 3 - a bytes
|
||||
object)
|
||||
"""
|
||||
return EMPTY_BYTE_STRING.join(ieee2ibm(value) for value in values)
|
||||
return EMPTY_BYTE_STRING.join(bytes(IBMFloat.from_real(value)) for value in values)
|
||||
|
||||
|
||||
def pack_values(values, fmt, endian='>'):
|
||||
|
||||
Reference in New Issue
Block a user