Single precision conversion

Can someone explain why doing a floating point conversion compromises digit of precision accuracy? For example, if I wire the double precision number "16.0001000" to the "to Single Precision Float" vi input, the output is "16.0000991". 
I have an application in which this level of accuracy is critical. I can think of several work arounds, but I still would like a good explanation for why this is the case.
pmac

Just use array to spreadsheet string on the DBL and write as text file (and an analogous operation for reading, converting back to DBL). Alternatively, you could make DBL version of "read/write  spreadheet file" by editing them slightly and saving them under a new name elsewhere. Make sure to change the icon too, e.g. give it a different color.
If precision is that important, you might want to use binary files. The don't have any formatting loss at all.
Of course if this is just measurement data, don't be fooled by fake precision. even SGL has a 22 bit mantissa, so if your DAQ hardware acqures in 16 bits, SGL is plenty.
LabVIEW Champion . Do more with less code and in less time .

Similar Messages

  • Need a single-precision/2-byte conversion tool

    Any one have a utility to convert 4-byte single precision numbers to and from a 2-byte representation?
    I only need 3 digits, with one fractional digit (-14.3, for example).
    Thanks...

    At one time I thought I wanted to do this, but never got around to it.  I did find this information useful, however.
    http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf

  • Single Precision Floating Point Numbers to Bytes

    Ok here is some code that i have written w hile back with some help from the support staff. It is designed to take in precision floating point numbers that are stored as 4 bytes and convert then to a decimal value. It works off of a udp input string and then also reformats the string. I have the ability to look at up to 4000 parameters from this one udp string. But now what i want to do is do the opposite of what i have written, and also perhaps get rid of the matlab i used in it as well. What i would like to be able to do is input a decimal value and then have it converted in to the 4 byte groupings that make up this decimal nd then have it inputed back in to a single long string witht hat grouping of bytes in the right order. A better explanation of what was done can be found on this website
    http://www.jefflewis.net/XPlaneUDP_8.html
    as the original code followed the "Single Precision Floating Point Numbers and Bytes" example on that site but what i want to do is "Going from Single Precision Floating Point Numbers to Bytes". The site also explains the udp string that is being represented. Also attached is the original code that i am trying to simply reverse.
    Attachments:
    x-plane_udp_master.vi ‏34 KB

    Perhaps what you are doing is an exercise in the programming of the math conversion of the bytes.
    But if you are just interested in getting the conversion done, why not use the typecast function?
    If the bytes happen to be in the wrong order for wherever you need to send the string, then you can use string functions to rearrange them.
    Message Edited by Ravens Fan on 10-02-2007 08:50 PM
    Attachments:
    Example_BD.png ‏3 KB

  • Writing to spread sheets with more than single precision

    Hi everyone,
    Im recording data by using the write to spread sheet VI in Labview 8,
    it records single precision which is a problem for me as I require greater 
    precision. 
    Are there ways around this issue?
    Thanks
    Solved!
    Go to Solution.

    What do you mean by this? Is it possible for you to post code which only shows what you are trying to explain?
    Adnan Zafar
    Certified LabVIEW Architect
    Coleman Technologies

  • Storing analog output data in a datatype other than single-precision

    I'm using three PCI-6713 AO cards in a single computer to output 24 channels of data using Labview 6.1. The input terminals of all the analog output VI's are of type single precision (32-bit). The output cards only have 12-bit DAC's, so there is a large amount of information stored that is never used by the cards. Is there a way in Labview to store AO data in another, smaller datatype - such as a 16-bit integer. This would greatly reduce the memory requirements for my application.

    I just figured out the answer to my own question. There isn't an option for binary in the AO Write vi, but if you go down to the AO Buffer Write vi (which is called by AO Write), you can select binary array.
    Thanks for all your help.
    Josh

  • Cast string to single precision

    Hi,
    I try to write a communication between a PC and a DSP which is
    programmed to
    understand some kind of ModBus. I tried to use MBmaster.vi, a freeware
    of AIRtech in the netherlands.
    I was successfull to 90% after a very short time - I get back a string
    from the DSP which makes sense.
    The only problem is to *convert* the 4Byte=8Hex=32Bits(=IEEE754 single
    precision format) into the LabView single precision number it does
    represent .
    In other programming languages like C I think I could do this easily
    on a very low level procedure or with one of these dangerous casts.
    As a newbie to LabView I could not found neither one VI to do this or
    find out which simple combination of VIs could solve the problems.
    Are there any cracks
    here who know *the* easy solution??
    Thanx & Regards
    Urs Bögli

    "Doug (CapeFl)" wrote in message news:<[email protected]>...
    > Did you check the VI functions under Functions>String>Additional
    > String to Number Functions?
    > There are quite a few for converting to/from Hex, etc. I've used them
    > for concatenating 4-bit strings into an 8-bit string (to get an 8-bit
    > byte/word), also converting to/from Hex using some of the VIs I
    > mentioned.
    > Good Luck, Doug
    Dough,
    as a programmer for twenty years I have some problems to understand the way
    labview does work with types and casts - other languages are much clearer about it
    - or have I not found the ultimative help area yet ???
    May I ask you to send me the VI off list?
    thanks
    Urs

  • Single precision constant changes value

    See attached "vi". If I put a double precison numeric on my block diagram, change it to SINGLE precision, then enter the value .001 into it, it adds values to the far right of the decimal. Why is it doing this? I'm using Labview 2011 SP1.
    Solved!
    Go to Solution.
    Attachments:
    precision.vi ‏5 KB

    Posting by phone and just taking a guess.
    The precision is defined in bits and many fractional values don't have an exact decimal translation.
    For example 0.001 cannot be represented exactly in sgl or dbl.
    This is inherent to the floating point representation and not language specific. You simply get the closest possible value. Set it back to DBL and change the format to show 20 decimal digits. Same difference.
    LabVIEW Champion . Do more with less code and in less time .

  • Single precision integer to 8 digit hex string

    I need to convert a single precision integer to a MSB-LSB 8 digit hex string to send to a test machine via RS-232.  So 15 needs to turn into 41700000.  The best I have been able to do is get 15 to turn into 0000000F, which is correct but not in the MSB-LSB format I need.  Any ideas?

    Just typecast the SGL to U32 and format it with %08x.
    Message Edited by altenbach on 05-30-2007 08:49 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    SGL-to-HEXstring.vi ‏8 KB
    SGL-to-HEXstring.png ‏6 KB

  • I am using the dynamic signal analyzer.vi but this vi has the output as single precision. How can I change this to DBL precision?

    I am using the dynamic signal analyzer.vi but this vi has the output as single precision. How can I change this to DBL precision? If I change the representation from single to double in the AI buffer read.vi labview returns ilegal operation and crash. I have labview 5.1 on windows 95 and one AT-MIO16XE50 DAQ board.
    Thanks in advance
    Ricardo.

    Probably by changing the data type that lvdaq.dll expects to write to is causing the crash. I can't test this since I have only 6.1 installed now. In any case, since the daq card is only 16 bits, the single precision is probably adequate for AI Buffer Read. If you do need the greater precision later on, you should be able to change representation in any one of the upper level VIs.

  • Single Precision "3D Cartesian Coordinate Rotation (Direction) (Array)"

    Hi there
    I am using "3D Cartesian Coordinate Rotation (Direction) (Array).vi" but this VI used Double Precision XYZ numbers.
    Is there equivalent in Single Precision?
    My reason is to save memory space and time. I am already using 64-bits LabVIEW  with 16 GB or RAM.
    LabVIEW 2013
    Thank you
     Peter

    No, unfortunately LabVIEW provides very few Single Precision VIs (see my idea here).  You might have success by reimplementing it yourself (it's just a matrix multiplication - look in the Help), and using the Multicore Analysis and Sparse Matrix Toolkit which does provide both SGL and DBL paralellized forms of most of the Linear Algebra VIs, among other things.

  • Data Acquisition form single precision to binary format

    Hi everybody,
    I work in an Astrophysics group and I'm developing an acquisition system of signals generated by X-Ray detectors (Transition Edge Sensor).
    I'm trying to save data acquired by NI-PXI 6132 (DAQ-mx software in LabVIEW 8.0) in binary format.
    To do this, I use the 'Write To Measurement File' procedure.
    I don't know how it is possible to change the precision from the DBL to SGL directly from DAQ-mx, but I solve this point by creating a 'For Loop' inside my VI, after the data is acquired.
    The problem is that I try to save the SGL data with the previous procedure but the 'Convert To Dynamic Data' automatically occurs, and the data are saved in binary format but in doube precision. So, the previous conversion that I made from DBL to SGL does not work.
    How can I solve this problem?
    Thank you for your help!
    Ciao,
    Claudio!

    Hi Alessio,
    thank you for your prompt reply!
    In attach there is the VI you reqeusted me.
    Ciao,
    Claudio
    Attachments:
    Daq_2monitor_BINARY_ASCII_single_float.vi ‏498 KB

  • Single precision to hex string

    Hello, 
    I was wondering how to typecast a SGL Or DBL into a hex string? I tried number to hex, and format into string, etc but can't seem to figure it out. 
    The stirring doesnt need a sgl/dbl and is fine but the heating needs to work at a decimal point. since the device must multiply the heating by 10 (inputting 80 degrees gives out 800 to the device and it sets it to 80 degrees) turning it into a hex string shouldn't be a problem but i can't seem to figure this out. 
    Any help would be appreciated. 
    Thanks
    Attachments:
    single to hex.JPG ‏33 KB

    I meant like this which most closely represents what you did for the U16 conversion at the bottom half of your code.
    Attachments:
    Example_VI.png ‏15 KB

  • Error in Java Mapping for Single XML conversion

    We are working on ABAP Proxy --> SAP PI 7.1 --> SOAP (Synchronous Scenario).
    (ECC -> PI -> Legacy CRM)
    Client has provided a WSDL with Single Node of XML and asking us to pass the whole structure as an single string along with all the nodes of data structure. To perform mapping we are using Java Mapping.
    Message which we are getting after Java Mapping:
    Input
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_SOReject_Sender xmlns:ns0="http://MTSINDIA/TC/SalesOrderReject">
       <ITEM>
          <sSlsOrderCode>1001</sSlsOrderCode>
          <sDlrCode>A250</sDlrCode>
          <sRejectReason>Z2</sRejectReason>
          <nCircleCode>2</nCircleCode>
       </ITEM>
    </ns0:MT_SOReject_Sender>
    Output
    <?xml version="1.0" encoding="UTF-8"?><MT_Trg xmlns:ns="urn:Test_File_to_File"><stringinp>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;ns0:MT_SOReject_Sender xmlns:ns0="http://MTSINDIA/TC/SalesOrderReject"&gt;&lt;ITEM&gt;&lt;sSlsOrderCode&gt;1001&lt;/sSlsOrderCode&gt;&lt;sDlrCode&gt;A250&lt;/sDlrCode&gt;&lt;sRejectReason&gt;Insufficient Stock Balance&lt;/sRejectReason&gt;&lt;nCircleCode&gt;2&lt;/nCircleCode&gt;&lt;/ITEM&gt;&lt;/ns0:MT_SOReject_Sender&gt;</stringinp></MT_Trg>
    Is ther any way from which we can convert &gt; as u201C>u201D and &lt; as u201C<u201D.  Required result is as follows
    Required Output
    <?xml version="1.0" encoding="UTF-8"?><MT_Trg xmlns:ns="urn:Test_File_to_File"><stringinp><?xml version="1.0" encoding="UTF-8"?><ns0:MT_SOReject_Sender xmlns:ns0="http://MTSINDIA/TC/SalesOrderReject"><ITEM><sSlsOrderCode>1001</sSlsOrderCode><sDlrCode>A250</sDlrCode><sRejectReason>Insufficient Stock Balance</sRejectReason><nCircleCode>2</nCircleCode></ITEM></ns0:MT_SOReject_Sender></stringinp></MT_Trg>
    We are using following Java Code for the same.
    import java.io.BufferedReader;
              import java.io.FileInputStream;
              import java.io.FileOutputStream;
              import java.io.InputStream;
              import java.io.InputStreamReader;
              import java.io.OutputStream;
              import java.util.Map;
              import javax.xml.parsers.DocumentBuilder;
              import javax.xml.parsers.DocumentBuilderFactory;
              import javax.xml.transform.Transformer;
              import javax.xml.transform.TransformerFactory;
              import javax.xml.transform.dom.DOMSource;
              import javax.xml.transform.stream.StreamResult;
              import org.w3c.dom.Element;
              import org.w3c.dom.Document;
              import org.w3c.dom.Text;
              import com.sap.aii.mapping.api.*;
              import com.sap.aii.mapping.api.StreamTransformation;
    public class SingleStr implements StreamTransformation{
          * @author user
          * To change the template for this generated type comment go to
          * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
                    public static void main(String args[]) throws Exception {
                FileInputStream inFile =
                 new FileInputStream("C:/Documents and Settings/user.HR0102WILT00033/Desktop/Input.XML");
                FileOutputStream outFile =
                 new FileOutputStream("C:/Documents and Settings/user.HR0102WILT00033/Desktop/Output.XML");
                 SingleStr xml = new SingleStr();
                xml.execute(inFile, outFile);
                System.out.println("Success");
               public void setParameter(Map param) {
                Map map = param;
               public void execute(InputStream in, OutputStream out)
                throws com.sap.aii.mapping.api.StreamTransformationException {
                try {
                 //************************Code To Generate The XML Parsing Objects*****************************//    
                 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                 DocumentBuilder db = dbf.newDocumentBuilder();
                 TransformerFactory tf = TransformerFactory.newInstance();
                 Transformer transform = tf.newTransformer();
                 //Document doc = db.parse(in);
                 Document docout = db.newDocument();
                 Element root = docout.createElement("MT_Trg");
                 root.setAttribute("xmlns:ns","urn:Test_File_to_File");
                 docout.appendChild(root);
                 Element stringinp = docout.createElement("stringinp");
                 root.appendChild(stringinp);
                 BufferedReader inpxml = new BufferedReader(new InputStreamReader(in));
                 StringBuffer buffer = new StringBuffer();
                 String line="";
                 while ((line = inpxml.readLine()) != null)
                 buffer.append(line);
                 String inptxml=buffer.toString();
                 Text srcxml = docout.createTextNode(inptxml);
                 stringinp.appendChild(srcxml);
                 DOMSource domS = new DOMSource(docout);
                 transform.transform((domS), new StreamResult(out));
                 } catch (Exception e) {
                   System.out.print("Problem parsing the file: " + e.getMessage());
                   e.printStackTrace();
    Please help!!

    We are using following Java Code for the same.
    import java.io.BufferedReader;
              import java.io.FileInputStream;
              import java.io.FileOutputStream;
              import java.io.InputStream;
              import java.io.InputStreamReader;
              import java.io.OutputStream;
              import java.util.Map;
              import javax.xml.parsers.DocumentBuilder;
              import javax.xml.parsers.DocumentBuilderFactory;
              import javax.xml.transform.Transformer;
              import javax.xml.transform.TransformerFactory;
              import javax.xml.transform.dom.DOMSource;
              import javax.xml.transform.stream.StreamResult;
              import org.w3c.dom.Element;
              import org.w3c.dom.Document;
              import org.w3c.dom.Text;
              import com.sap.aii.mapping.api.*;
              import com.sap.aii.mapping.api.StreamTransformation;
    public class SingleStr implements StreamTransformation{
               public static void main(String args[]) throws Exception {
                FileInputStream inFile =
                 new FileInputStream("C:/Documents and Settings/user.HR0102WILT00033/Desktop/Input.XML");
                FileOutputStream outFile =
                 new FileOutputStream("C:/Documents and Settings/user.HR0102WILT00033/Desktop/Output.XML");
                 SingleStr xml = new SingleStr();
                xml.execute(inFile, outFile);
                System.out.println("Success");
               public void setParameter(Map param) {
                Map map = param;
               public void execute(InputStream in, OutputStream out)
                throws com.sap.aii.mapping.api.StreamTransformationException {
                try {
                 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                 DocumentBuilder db = dbf.newDocumentBuilder();
                 TransformerFactory tf = TransformerFactory.newInstance();
                 Transformer transform = tf.newTransformer();
                 //Document doc = db.parse(in);
                 Document docout = db.newDocument();
                 Element root = docout.createElement("MT_Trg");
                 root.setAttribute("xmlns:ns","urn:Test_File_to_File");
                 docout.appendChild(root);
                 Element stringinp = docout.createElement("stringinp");
                 root.appendChild(stringinp);
                 BufferedReader inpxml = new BufferedReader(new InputStreamReader(in));
                 StringBuffer buffer = new StringBuffer();
                 String line="";
                 while ((line = inpxml.readLine()) != null)
                 buffer.append(line);
                 String inptxml=buffer.toString();
                 Text srcxml = docout.createTextNode(inptxml);
                 stringinp.appendChild(srcxml);
                 DOMSource domS = new DOMSource(docout);
                 transform.transform((domS), new StreamResult(out));
                 } catch (Exception e) {
                   System.out.print("Problem parsing the file: " + e.getMessage());
                   e.printStackTrace();
    Please help!!

  • Maximum number in a Single precision floating number

    Hi everyone,
    I would like to know which is the maximum positive and negative number I can write in a SGL numeric control. I read the Numeric data types table  in the LabVIEW help and I am not sure if the numbers in the column "approximate range on disk" are the maximun and minimum ones because I wrote in a DBL numeric control the number 6216825840 (which is less than the maximum on the table 3.40e+38) and I displayed it in a SGL numeric indicator, and the number changed. 
    The problem is that I am storing some data in the numeric format and  I choose the SGL format because it uses less space in the disk, however I have the number 6216825840 which changes if it is storaged in this format. I know that I should change to DBL, but I am doing an array with all my data and if I change one by BDL the other ones change to DBL and will use more space in the disk when I store them.
    I attach a picture of this problem.
    Thanks in advance.
    JC
    Attachments:
    DBLtoSGL.JPG ‏28 KB

    In particular, you can create a simple test program that shows you that the highest good integer is 16777216 for SGL, because 16777216+1=16777216.
    For deep reasons, this is the same as 2^24 as mentioned above.
    Here's a quick code that stops the loop once i = i+1, then displays i (the fist integer that fails the test, thus is the largest good integer for SGL.
    Message Edited by altenbach on 06-15-2007 01:33 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    SGL-Limit.png ‏5 KB

  • Convert/Cast Single to double inaccurate.

    Whilst I have read some background on floating opint numbers not being able to accurately store numbers such as 0.1, I am not clear why converting from single to double is so inaccurate.
    Converting a single 0.1 to a double 0.1 yeilds
    0.10000000149011600
    But 0.1 can be represented in a double more accurately, even if not perfectly as
    0.10000000000000000
    This stems from the single representation of 0.1 actually equating to 0.10000000149011600 in binary.
    However, we know that the single has a particular level of precision.
    I would like a conersion function that converts single 0.10000000 to double 0.1000000000000000.
    I can appreciate that the standard conversion functions would need to still exist as real numbers for engineering would suffer less overall inaccuracies with the existing rounding functions.
    One other question:
    Can the convertsion be affected by the OS/framework/hardware or will it be consistent on different machines?  Are there any settings that can change the conversion behaviour?

    There is no reason that we should explicitly convert a single precision number to a double precision number using some function as a simple assignment would do the same. Please review the following code:
    float x = 10.5367f;
    double a = Convert.ToDouble(x);
    double b = (double)x;
    double c = x; //same as conversion or casting
    In the previous example, when x is declared as float, the memory space that is allocated is sufficient to hold the value of x as float along with precision. Now when we assign the value to some double variable (by conversion/casting/direct assignment), all
    what happens is,
    1. the space for the double variable is allocated
    2. the value is copied from single the single variable to double variable.
    Now obviously, the value of the single variable does not span as much memory space as the double variable. So when copied to double the remaining memory space of the double variable is still filled up with garbage data. The actual value of the single variable
    is still preserved upto the range of single precision.
    So frankly speaking, there is no such straightforward way that can be used to fill the garbage digits with 0s.
    I personally recommend that you use "decimal" instead of "double" if any such conversion is required.
    Thanks.

Maybe you are looking for