Floating point format conversions

Hi All,
I have a binary file that has 8 byte floats in it written in VAX D floating point format. It also has 4 byte integers in it. I have to read this file on a Sun Sparc. To get the correct value of the integers I just swap the bytes around and write out the int value, so bytes 0123 get rearranged to be 3210 and then I use that as my int. I tried that with the doubles, reorder bytes 01234567 to 76543210 and then write out the double value but I don't get the value that was stored.
I read 8 bytes from the file, I'm supposed to get 512.0 but I get garbage.
The hex dump of the file shows: 0045 0000 0000 0000
I can't come up with a way to turn that into 512.0
Another one is 360448.0 with hex dump: b049 0000 0000 0000
Can anyone show me how to manipulate these bits/bytes to get the correct values?
Thanks

Hi Legosa,
Thanks for looking for a solution for me. The linkhttp://nicmos2.as.arizona.edu/thompson/kfocas/vax2sun.c
has a C implementation of exactly what I need and has saved me a lot of time and work. Translation to Java will have to use bit shifting I think, the C unions make for a nice implementation.
I also have to read PC and Cray generated files on my Sun.
I have found that, like the Vax, Intel x86 including pentium are all little endian and use IEEE so I'm guessing that I just have to do the byte swapping to translate from PC to Sun.
Crays are Big endian so I don't need byte swapping but I do need to do some manipulation of the exponent and the mantissa.
Do you know where I might find code that others have done for PC to Sun and Cray to Sun conversions of integers, floats and doubles?
BTW, for those who may read this later, the solution in vax2sun.c isn't quite right, the author forgot to use the least significant 32 bits and lost 3 bits in the middle but it is very close. To make it closer you have to change the vax2sun.c code a little.
Replace mantissa and lomant with
In union ieeebuf
int mantissa1:20
int mantissa2:3
int mantissa3:29
In union vaxbuf
int mantissa1:20
int mantissa2:3
int mantissa3:29
int lost_bits:3
In the code replace d.mantissa = v.mantissa/8 with:
d.mantissa1 = v.mantissa1
d.mantissa2 = v.mantissa2
d.mantissa3 = v.mantissa3
My few tests showed this gave very good results. The lost_bits are lost because ieee needs 3 more bits for its exponent so it doesn't have room for all of the vax mantissa bits. A little bigger range means a little less precision.

Similar Messages

  • Export to .exr / .hdr / floating point format from ACR?

    Hi!
    Context is that I'm doing HDRI images for rendering so dynamic range is the most important aspect.
    I searched hard but didn't found a way to export from ACR into a floating point format which is very very very annoying because if you export as 16bit tiff it will obviously clip whatever values you have in your raw file. I can load the raw / dng files directly into Photomatix / Oloneo but then I'm losing any kind of Camera Profile / Distortion profile embedded with them.
    Oh and I don't want to use Photoshop to Merge the HDRI files because I want to have control over the deghosting and various other alignement related stuff. I'm really searching for a .dng / .raw to .exr conversion.
    Any ideas?
    KS

    I would benefit from first class raw demosaicing, noise reduction, undistortion, optional color profiling, etc... before sending that to merging in whatever software that is not the specialty to do what ACR does perfectly
    Getting linear data out would be the step after all the ones I described and I wouldn't change any exposure, recovery, black level, tone curve, etc ... related options so that the HDRI merge is predictable. That's where the problem resides.
    Lets say you have a photo with a bright sky, you load it in ACR, with everything to zero. Your sky is white and burnt ( But you actually have data from the raw file because you have checked it by changing the exposure compensation to -5 ) If you export the image as is without the exposure compensation, the sky data is clipped once casted to integer.
    If you export it with the exposure compensation, the HDRI merge will be very very bad because the software will have an image with the data where the exposure has been shifted but still exhibit the exif data from the original file.
    Of course you can merge with the tiff without the compensation and rely on a faster exposure to fill the missing data, it works but when you hit your latest fast exposure and you see that you would be able to pump even more dynamic range from it but that ACR clipped the data it's very frustrating.
    I now hope it's crystal clear and why I would like to get a linear exr output I can also upload a raw file somewhere for people having trouble understanding the issue.
    In the best case scenario Adobe will provide a solution, but if it happens it will not be before a while, in the worst case there won't be any solutions at all. With that in mind I wrote a Python script that generates for me the tail exposures for my bracketing sequences and modify accordingly the exif data.
    My workflow is the following for now:
    - Dump raw images from camera.
    - Apply neutral preset, noise reduction on all the raw files.
    - Praise Adobe for ACR.
    - Launch the Python script that:
         - Generates a subfolder where all the raw and xmp files are copied.
         - Images are renamed reordered by their exposure time.
         - The tail exposure is duplicated 3 times.
         - The xmp files are updated with exposure compensation ( -1, -3, -5 ). Now I get the dynamic range.
         - The raw files exif data is altered to reflect the exposure compensation.
    - Load the new raw files from the subfolder and convert them to tif.
    - Rant against Adobe
    - Merge to HDRI with my proper dynamic range.
    KS

  • Floating point formats: Java/C/C++, PPC and Intel platforms

    Hi everyone
    Where can I find out about the various bit formats used for 32 bit floating numbers in Java and C/C++ for both Mac hardware platforms?
    I'm developing a Java audio application which needs to convert vast quantities of variable width integer audio samples to canonical float audio format. I've discovered that a floating point divide by the maximum integer value gives the correct answer but takes too much processor time, so I'm trying out bit-twiddling in C via JNI to carve out my own floating point bit patterns. This is very fast, however, I need to take into account the various float formats used on the different platforms so my app can be universal. Can anyone point me to the information?
    Thanks in advance.
    Bob

    I am not sure that Rosetta floating point works the same as PPC floating point. I was using RealBasic (a PPC basic compiler) and moved one of the my compiled applications to a MacBook Pro and floating point comparisons that had been exact on the PPC stopped working under Rosetta. I changed the code to do an approximate comparison (i.e. abs(a -b) < tolerance) and this fixed things.
    I reported the problem to the RealBasic people and thought nothing more of it until I fired up Adobe's InDesign and not being used to working with picas, changed the units of measurement to inches. The default letter paper size was suddenly 8.5000500050005 inches instead of the more usual 8.5! This was not a big problem, but it appears that all of InDesign's page math is running into some kind of rounding errors.
    The floating point format is almost certainly IEEE, and I cannot imagine Rosetta doing anything other than using native hardware Intel floating point. On the other hand, there is a subtle difference in behavior.
    I am posting this here as a follow up, but I am also going to post this as a proper question in the forum. If you have to delete one or the other of these duplicate posts, please zap the reply, not the question.

  • IEEE Floating point format converstion to ForteDouble

    Question:
    Given that I have 4 bytes of binary data which represents a number in
    IEEE floating point format,
    and I wish to convert it to a Forte DoubleData, will the following code
    give me the correct answer
    in Value?
    (Assume that file is correctly set up, etc...)
    Value : DoubleData = new;
    FPoint : point to float;
    F : float;
    LineText : BinaryData = new;
    File.ReadBinary(LineText,4);
    Fpoint = (pointer to Float)(LineText.Value);
    F = *Fpoint;
    Value.SetValue(F);
    Thanks
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Mark,
    you might try testing whether forte floats are IEEE in the following
    way using the following:
    pflt : pointer to float = (pointer to float) (res.value);
    flt = *pFlt;
    however, I believe you will have to wrapper a C function to do this.
    The C function takes a void * first argument and has a float
    void ConvIEEE(void * buffer, float * return)
    return = (float) (buffer);
    or
    void ConvIEEE(void buffer, float return)
    ieeefloat ie;
    ie = (ieeefloat) (*buffer);
    *return = IEEELibraryConvertToFloat(ie);
    depending upon whether C floats are IEEE or not on your
    platform/compiler. I think you'll have to investigate this yourself,
    or try the first approach and see if it works.
    Good luck!
    assuming, of course, that your C compiler's float is also IEEE format.
    Your forte wrapper would look like
    class floatWrapper inherits from framework.object
    has public method ConvIEEE(input buffer : pointer,
    output return : float)
    end class;
    with your binarydata you would
    res : binarydata = (get from somewhere)
    flt : float;
    fw : FloatWrapper = new;
    fw.ConvIEEE(res.value,flt);
    Mark Sundsten wrote:
    >
    Question:
    Given that I have 4 bytes of binary data which represents a number in
    IEEE floating point format,
    and I wish to convert it to a Forte DoubleData, will the following code
    give me the correct answer
    in Value?
    (Assume that file is correctly set up, etc...)
    Value : DoubleData = new;
    FPoint : point to float;
    F : float;
    LineText : BinaryData = new;
    File.ReadBinary(LineText,4);
    Fpoint = (pointer to Float)(LineText.Value);
    F = *Fpoint;
    Value.SetValue(F);
    Thanks
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>--
    John Jamison [email protected]
    Vice President and Chief Technology Officer
    Sage IT Partners, Inc.
    Voice: 415 392-7243 x 306
    Fax: 415 391-3899
    Internet Enabled Business Change
    http://www.sageit.com
    -----------------------------------------------------

  • Floating Point arithmetic conversion

    Hi Everyone,
    Can you tell me how to convert a floating point arithmetic field value to a currency field value.
    thanks,
    chan

    Hi,
    I hope simple move statement should work.
    MOVE l_float TO l_curr.
    Make sure that curr field has enough length.
    Thanks,
    Vinod.

  • Float point format function --- "Beginner"

    Hii every body
    1-I want to format any float number to be with only two decimal digits
    examble :
    95.3213 converted to be 95.32
    is there any function that can do this ???
    2- I want to remove any spaces from any given string
    examble:
    mystring = "Hi my friend " coverted to be mystring = "Himyfriend"
    thank you ...

    1 Check out the API for java.text.DecimalFormat
    double d = 95.3213;
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);
    System.out.println(nf.format(d);2 If you have java1.4 you can use the replaceAll method in string:
    String myString  = "Hi my friend ";
    myString = myString.replaceAll("\\s", "");The regular expression "\s" matches all whitespace - spaces, tabs etc etc

  • Floating point format in report

    I am using TestStand 3.1 and LabVIEW 7.1. I set the default report format for HTML report to _whatever_, %#5.13f, append trailing zeros etc, and this format is present for report entries such as limits. It is not present for the actual measured value, and this seems subject to some display format rounding. For instance, my limit test will be GELE and the lower limit will be 3.0000000000000. The measurement will be 2.956785434 and the test will fail, but in the report the measurement is formatted as 3.0. What has gone wrong?

    Hi Odd_Modem,
    Sorry for the crazy email. I accidentally replied when I was not ready.  
    Anyway, the third option was the Tree View. Once inside the tree, browse to Main >> Numeric Limit Test >> Result >> Numeric.  Right-click on the numeric field (in the right window) and select properties. Then select Numeric Format and change the significant digits.  This should fix your issue since this property is the highest precedence. The order of precedence is (Numeric in Tree View -> Limits -> Report options).
    Hope this helps!
    Best Regards,
    Jonathan N.
    National Instruments

  • Re-FLOATING POINT VALUE CONVERSION.

    Hi,
    I have value lile this : 1.000000000000000E03,   or  1.090000000000000E02  , is there
    any function module to convert it into actual value like 1,00.00 or 1,099.00 etc.
    Thanks in advance.
    Shyam.

    hi
    call fm CONVERT_WITH_OVERFLOW_CHECK.
    data lv_num type f .
    data: p10_4(10)     type p decimals 4.
    lv_num  = 27.
    CALL FUNCTION 'CONVERT_WITH_OVERFLOW_CHECK'
      EXPORTING
        i_value                     =             lv_num
       I_UNIT                      =             ' '
       I_KRUND                  =            ' '
    IMPORTING
       E_VALUE                 =            p10_4
    EXCEPTIONS
       UNIT_CONVERSION_ERROR       = 1
       WRONG_E_VALUE_TYPE           = 2
       OTHERS                                     = 3
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    the variable p10_4 will be having your result. its format will be driven by the type you have taken.
    regards
    Vishal Kapoor

  • Invalid Floating Point Error

    I have one Captivate 3 project published as a Stand Alone
    project with Flash 8 selected. There are 36 slides, no audio, no
    eLearning, SWF size and quality are high.
    One person who runs this gets an "Invalid Floating Point"
    error when he tries to run it the first time. He is running Windows
    XP SP2, Firefox 3.0.4. and Flash Player 10.0.12.36. Other Captivate
    projects I've created run fine for him. This one sometimes runs
    after the first Error message.
    Any thoughts on the cause and fix?
    Thanks,
    Janet

    iMediaTouch probably doesn't support Floating Point formats - it certainly doesn't mention them in the advertising. Try saving your files as 24-bit PCMs, and they should import fine.

  • F suffix for floating point.

    Okay, I'm a proficient c++ programmer and have been learning Java for only a few weeks now.
    I have a question about the f suffix for floating point varibles such as float f = 3.14f;
    The f suffix casts this as float right? which is the same as float f = (float) 3.14; Correct?
    Why do we have to add the f suffix in the first place? Doesn't the compiler know that we want a float and not a double? (single-precision 32-bit instead of double precision 64 bit) I really do not understand the concept here or why they need the f suffix.
    Can someone explain?

    ThePHPGuy wrote:
    The f suffix denotes that the literal is of a floating-point type.Yes. The d suffix does the same.
    Java has two different types of floating-point numbers.Right.
    The type double is the default type.Right.
    The float type can have a double and a float literal. Is this true or false?No. At least not in any way I understand it.
    I think you're confusing two things:
    "floating point number" is any number in the IEEE floating point format.
    "float" is a datatype holding a 32bit floating point number.
    "double" is a datatype holding a 64bit floating point number.
    floating point number literals can be either double literals (without suffix or if the "d" suffix is used) or float literals (when the "f" suffix is used).

  • Convert Floating Point Decimal to Hex

    In my application I make some calculations using floating point format DBL,and need to write these values to a file in IEEE 754 Floating Point Hex format. Is there any way to do this using LabVIEW?

    Mike,
    Good news. LabVIEW has a function that does exactly what you want. It is well hidden though...
    In the Advanced/Data manipulation palette there is a function called Flatten to String. If you feed this funtion with your DBL precision digital value you get the IEEE-754 hexadecimal floating point representation (64 bit) at the data string terminal (as a text string).
    I attached a simple example that shows how it works.
    Hope this helps. /Mikael Garcia
    Attachments:
    ieee754converter.vi ‏10 KB

  • 16 bit integer vs 32 bit floating point

    What is the difference between these two settings?
    My question stems from the problem I have importing files from different networked servers. I put FCP files (NTSC DV - self contained movies) into the server with 16 bit settings, but when I pull the same file off the server and import it into my FCP, this setting is set to 32 bit floating point, forcing me to have to render the audio.
    This format difference causes stuttering during playback in the viewer, and is an inconvenience when dealing with tight deadlines (something that needs to be done in 5 minutes).
    Any thoughts would be helpful.

    It's not quite that simple.
    32 bit floating point numbers have essentially an 8 bit exponent and 24 bit mantissa.  You could imagine that the exponent isn't particularly significant in values that generally range from 0.0 to 1.0, so you have 24 bits of precision (color information) essentially.
    At 16-bit float, I'm throwing out half the color information, but I'd still have vastly more color information than 16-bit integer?
    Not really.  But it's not a trivial comparison.
    I don't know the layout of the 24 bit format you mentioned, but a 16 bit half-float value has 11 bits of precision.  Photoshop's 16 bits/color mode has 15 bits of precision.
    The way integers are manipulated vs. floating point differs during image editing, with consistent retention of precision being a plus of the floating point format when manipulating colors of any brightness.  Essentially this means very little chance of introducing posterization from extreme operations in the workflow.  If your images are substantially dark, you might actually have more precision in a half-float, and if your images are light you might have more precision in 16 bits/channel integers.
    I'd be concerned over what is meant by "lossy" compression.  Can you see the compression artifacts?
    -Noel

  • Precision loss - conversions between exact values and floating point values

    Hi!
    I read this in your SQL Reference manual, but I don't quite get it.
    Conversions between exact numeric values (TT_TINYINT, TT_SMALLINT, TT_INTEGER, TT_BIGINT, NUMBER) and floating-point values (BINARY_FLOAT, BINARY_DOUBLE) can be inexact because the exact numeric values use decimal precision whereas the floating-point numbers use binary precision.
    Could you please give two examples: one where a TT_TINYINT is converted to a BINARY_DOUBLE and one when a TT_BIGINT is converted into a DOUBLE, both cases give examples on lost precision? This would be very helpful.
    Thanks!
    Sune

    chokpa wrote:
    Public Example (float... values){}
    new Example (1, 1e2, 3.0, 4.754);It accepts it if I just use 1,2,3,4 as the values being passed in, but doesn't like it if I use actual float values.Those are double literals, try
    new Example (1f, 1e2f, 3.0f, 4.754f);

  • SignalExpress 2010 - Chart time axis format will not change to floating point or anything else

    I just downloaded and installed the new and shiny SignalExpress 2010 to replace the old version. And immediately run into major problems:
    The x-axis time format refuses to change to floating point or scientific even if I choose them from chart properties. The format is always absolute, e.g. 12:23:54.743. This makes the usage of the chart and the whole application impossible! Is this a known issue and is it going to be fixed soon? And where can I get the old version of the SignalExpress (2009) so I can install it again?

    Here is a screenshot of the problem:

  • Sequence audio format stuck on 32-bit Floating Point

    Hi,
    The audio format for all my sequences is set to 32-bit Floating Point when I check them in the browser's Aud Format field. When I manually change the format in the sequence settings nothing changes in the browser and choosing a new sequence set up doesn't seem to help. What I don't understand is that there isn't even an option for 32-bit Floating Point in Audio Settings. Anyone else experience this?
    I am using v6.0.6 on osx 10.5.8
    Thanks,
    Tom

    16 bits per channel equals 32 bits stereo. Floating point means that you can, but don't have to, have a non-integer value for your audio.

Maybe you are looking for