Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardizing IBM-Float as a Julia minipackage: any interest? #4

Open
jpjones76 opened this issue Feb 25, 2020 · 2 comments
Open

Standardizing IBM-Float as a Julia minipackage: any interest? #4

jpjones76 opened this issue Feb 25, 2020 · 2 comments

Comments

@jpjones76
Copy link

Hi everyone,

I'm the creator/maintainer of the "other" SeisIO package, and I'm trying to standardize IBM-Float in Julia (same reason you use it, really -- we all need full SEG Y support). Are you interested in turning IBMFloat support into a separate package with me? Should be short, not much work required.

At issue: the solution you use, from JuliaSeis.jl (radix shift + reinterpret), yields wrong answers outside the range 1.0f-45 ≤ abs(x) ≤ 3.4028235e38; the range of single-precision IBM-Float is 5.39761e-79 ≤ abs(x) ≤ 7.23701e75. So it works for most seismic data, but it can fail.

Proposed solution: convert IBMFloat32 ==> Float64 and IBMFloat64 ==> BigFloat to support their full ranges.

Below is a trial function that correctly parses all test bit representations in https://en.wikipedia.org/wiki/IBM_hexadecimal_floating_point. However, it's a factor of four slower than JuliaSeis.jl because of the last step. (slower as presented here the function below doesn't define a new primitive Type)

I haven't worked out the radix shifts, etc., to convert IBMFloat32 ==> Float64, but I think that could be done by modifying your code.

Is this of any interest?

function ibmfloat(x::UInt32)
  local fra = ntoh(x)
  local sgn = UInt8((fra & 0x80000000)>>31)
  fra <<= 1
  local exp = Int16(fra >> 25) - Int16(64)
  fra <<= 7
  y = (sgn == 0x00 ? 1.0 : -1.0) * 16.0^exp * signed(fra >> 8)/16777216
  return y
end
@henryk-modzelewski
Copy link
Member

Josh,

I will have a look and get back to you.

Henryk

@henryk-modzelewski
Copy link
Member

Josh,

Did you have a chance to see https://pypi.org/project/ibm2ieee/ (https://github.com/enthought/ibm2ieee)?

It would not be a high priority project for me, but let's do it.

Do you want to create repo for it, or is it OK with you if I do it.

Henryk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants