[SOLVED] Why Is my Code Changing my Floats??

Here's the code:
#include <stdio.h>
const float COEFF4[2][2] = {
732974.9209,-2614372.431,
-4458973.651,15923460.62
int main(void) {
char stra[20];
memset(stra, 0, 20);
sprintf(stra, "%f", COEFF4[0][0]);
printf(stra);
printf("\n");
return 0;
[karam@kfc5s1 new]$ nano -w test.c
[karam@kfc5s1 new]$ gcc -o test test.c
[karam@kfc5s1 new]$ ./test
732974.937500
Any help is greatly appreciated...
Last edited by tony5429 (2008-09-28 04:51:26)

This is due to the internal representation of the date type, try using double instead.
First a link, then a quick explanation: http://en.wikipedia.org/wiki/IEEE_754
I might be mistaken (it's been a while, so details are blurry), but the saving of the number is done as follows:
1. Normalize the number: 732974.9209 -> 0.7329749209 (done in binary format) -> this defines the expontent
2. Cut of the first 0.1 in binary format, i.e. 0.1000110 would be 000110 -> this is the fraction part
Now the fraction is saved as expontents of 2, i.e 0.1 binary equals to 2^-1 = 0.5, 0.01 to 2^-2 = 0.25, 0.001 to 2^-3 = 0.125,...
This means it is impossible to encode some numbers like 0.2 (you can only achieve an appoxiation using exponents of 2) or 0.
In your case the precision of the fraction is simply not high enough, so a rounding to the value occurs. Using double will give you a higher precision and solve this problem.
Last edited by wuischke (2008-08-01 14:42:57)

Similar Messages

  • Created file in illustrator then opened in photoshop but color code changed?

    I Created file in illustrator and then opened the art in photoshop but the wierd thing is that the color code changed. If you look at the image with you eye the color will look the same to the naked but if you use the eye dripper tool you can see that the color code has changed between illustrator and photoshop.
    Is there a way to make the CMYK color code stay the same?

    In Illustrator the "Edit---> color settings" are set to "North America General Purpose 2" and the that is the same color setting choice in Photoshop.
    For example there is a black color in Illustrator that has this CMYK code "60, 49,47, 100"
    but in photoshop the CMYK code for the same part of the graphic changes to "75, 68, 67, 90"
    This is only one example of many color code changes that are happening and this may look like the same color on the screen but I need them to both have the same code because I am doing specialized printing and need no changes in color codes like this to occur.
    If I have the color setting in both photoshop and illustrator both set exactly the same "Edit---> color settings" then do you know why this color shift would be happening. Please help.

  • Why redeeming a code is so complicated? We need valid reason and explanation to get and satisfied on what we paid for. Make things easy, not messy.

    Why redeeming a code is so complicated? We need valid reason and explanation to get and satisfied on what we paid for. Be user-friendly to make it easy not messy.

    I did that link you refer to me (manually and using camera). But still nothing happens, always prompted "not properly activated" or "invalid code". And i did follow the instructions how to send an issue/problems/case regarding itunes card code query.
    My apology dude.
    I did change country/region, itunes store country, apple id, but still prompting FAILURE "The Gift Certificate or Prepaid Card you entered has not been properly activated." Does it mean it needs to activate by Apple Inc. before i can use it? If that's the case, everytime i buy an itunes card, i need to go Apple Support? Is that so?
    Please help me dude regarding this matter, i know you're well knowledgeable about apple systems.
    Thanks in advance.

  • Why can't I change the transaction isolation level?

    I was trying to change the transaction isolation level from an EJB. My source codes are shown as the follows:
    ======================================================
    /*********************** Database Routines *************************/
    private void makeConnection() {
    try {
    InitialContext ic = new InitialContext();
    DataSource ds = ( DataSource )ic.lookup( dbName );
    con = ds.getConnection();
    DatabaseMetaData dmd = con.getMetaData();
    show_supported_trans_levels( dmd );
    int status = con.getTransactionIsolation();
    System.out.print( "1. " );
    disp_tx_status( status );
    System.out.println( "con.isReadOnly() = " + con.isReadOnly() );
    con.setTransactionIsolation( Connection.TRANSACTION_SERIALIZABLE );
    System.out.print( "2. " );
    disp_tx_status( status );
    } catch( SQLException ex ) {
    System.err.println( "SQLException: " + ex.toString() );
    throw new EJBException("Unable to connect to database. " +
    ex.getMessage());
    } catch( NamingException ex ) {
    System.err.println( "NamingException: " + ex.toString() );
    throw new EJBException("Unable to connect to database. " +
    ex.getMessage());
    private void disp_tx_status( int status )
    System.out.print( "Transaction Status: " );
    switch( status )
    case( Connection.TRANSACTION_READ_UNCOMMITTED ):
    System.out.println( "TRANSACTION_READ_UNCOMMITTED" );
    break;
    case( Connection.TRANSACTION_READ_COMMITTED ):
    System.out.println( "TRANSACTION_READ_COMMITTED" );
    break;
    case( Connection.TRANSACTION_REPEATABLE_READ ):
    System.out.println( "TRANSACTION_REPEATABLE_READ" );
    break;
    case( Connection.TRANSACTION_SERIALIZABLE ):
    System.out.println( "TRANSACTION_SERIALIZABLE" );
    break;
    case( Connection.TRANSACTION_NONE ):
    System.out.println( "TRANSACTION_NONE" );
    break;
    default:
    System.out.println( "UNKNOWN" );
    break;
    private void show_supported_trans_levels( DatabaseMetaData dmd ) throws SQLException
    System.out.println( "List of Supported Transaction Isolation Levels: " );
    if( dmd.supportsTransactionIsolationLevel( Connection.TRANSACTION_READ_UNCOMMITTED ) )
    System.out.println( "TRANSACTION_READ_UNCOMMITTED is supported!" );
    else
    System.out.println( "TRANSACTION_READ_UNCOMMITTED is unsupported!" );
    if( dmd.supportsTransactionIsolationLevel( Connection.TRANSACTION_READ_COMMITTED ) )
    System.out.println( "TRANSACTION_READ_COMMITTED is supported!" );
    else
    System.out.println( "TRANSACTION_READ_COMMITTED is unsupported!" );
    if( dmd.supportsTransactionIsolationLevel( Connection.TRANSACTION_REPEATABLE_READ ) )
    System.out.println( "TRANSACTION_REPEATABLE_READ is supported!" );
    else
    System.out.println( "TRANSACTION_REPEATABLE_READ is unsupported!" );
    if( dmd.supportsTransactionIsolationLevel( Connection.TRANSACTION_SERIALIZABLE ) )
    System.out.println( "TRANSACTION_SERIALIZABLE is supported!" );
    else
    System.out.println( "TRANSACTION_SERIALIZABLE is unsupported!" );
    =========================================================
    However, I encountered the following exception when running at the highlighted statement:
    ======================================================
    SQLException: java.sql.SQLException: Transaction manager errors. statement not allowed in XA Session.
    ======================================================
    To my surprise, the isolation level TRANSACTION_SERIALIZABLE is supported from the database vendor. So why can't I change the transaction isolation level?

    You can change the setting, you may need to click the lock at the bottom of the preference pane. Be careful what you download and install, Gatekeeper is there to help you. OS X: About Gatekeeper - Apple Support

  • Why can't I change my apple id / email address associated with my apple id ?

    My apple id is associated with a gmail address.
    I wan't to change it to something else.
    So I went to: appleid.apple.com ---> Change apple id ---> Typed in new email address (everything shows green) ---> Hit Save.-->Edit box disappears as if everything went ok ----> But the box showing my apple id, still shows the gmail address!
    It still shows my gmail address!! Doesn't send any verification email or anything! No matter what I do, it doesn't let me change it from my gmail address!
    It let me change my password though, and also let me change my rescue email address.
    Why can't I change my apple id ?

    Hi KeanuReeves,
    It sounds like you have already done most of the steps in this article relating to changing the email associated with your Apple ID, but you may want to go through them again -
    Manage your Apple ID primary, rescue, alternate, and notification email addresses
    http://support.apple.com/kb/HT5620
    If you are still having difficulty changing the email address, you may want to contact Apple’s account security team using the contact information in this article -
    Apple ID: Contacting Apple for help with Apple ID account security
    http://support.apple.com/kb/HT5699
    Thanks for using Apple Support Communities.
    Best,
    Brett L

  • Ship to party Jursidiction code change at line item leve in Sales order

    Hell Gurus,
             Here is requirement for enhancement in Sales order. For determining tax following logic is requird to modify jursidiction code of ship-to party at line item level.
    after entering header details and line item, then user exit should be there(which user exit??) and i need to compare countries of Ship-from(Plant i believe) and Ship-to party(customer) if country is same, then jursidiction code of Ship-to party at line item level should be changed with value from Jursidiction code of Ship-from party(plant this value will come from <b>T001W</b>) table. this should happen before save(while entering line items, user may go and check jursidiction code change)
    what i need here is which user exit is triggerd ater line item entry, and how to change jursidiction value( i believe we need XVBAP, XVBPA, might be XADRC(Jursidiction code) . if some one provide user exit and logic with structure details then it would be of great help.
    hoping to get reply
    Thanks in Advance
    Siva

    Can you check in MV45AFZB Include but i am not sure
    FORM USEREXIT_FILL_VBAP_FROM_HVBAP.
    VBAP-zzfield = HVBAP-zzfield2.
    ENDFORM.
    FORM USEREXIT_SOURCE_DETERMINATION.
    set source
    VBAP-WERKS          = zzfield1.
    set item category
    VBAP-PSTYV          = zzfield2.
    ENDFORM.
    *eject
    Reward Points if it is helpful
    Thanks
    Seshu

  • Why does iCal automatically change the date of the entry i am making to the day before??

    why does iCal automatically change the date of the entry i am making to the day before??
    for example, when i am attempting to make a 'all-day' appointment on october 2nd 2011, it automatically shifts it to october 1st.
    but if i am doing a timed appointment for only a few hours, it will allow me to put it on that day.
    i am trying to put in travel dates so any help on how to fix this, would be greatly appreciated.

    alsdman,
    Quit iCal, and try removing the com.apple.iCal.plist file from your Macintosh HD/Users/yourusername/Library/Preferences Folder. Since that Library is now hidden, you have to use the Finder>Go Menu>Depress the "Option" key>Library. Drag the .plist file to your desktop, and log out/in or restart and check iCal for functionality.
    Also go to System Preferences...>Language & Text>Formats>Region: and set/re-set the appropriate "Region."

  • Why do Certain fonts change when I convert to PDF from Microsoft word?  They start out 60s chic and end up as a standard font.

    Why do some fonts change when converted from Microsoft word to PDF?  It starts out as 60s chic and changes to standard font.

    Related to the question, I suspect you have licensed fonts that cannot be embedded. Thus, the PDF is using what it is finding to be an equivalent as well as it can guess. Did you check the font list in the PDF?

  • How to handle source code changes in apex

    hi all,
    can anybody help me plz...
    how to handle source code changes in apex.
    which development process is best suite for apex.
    Regards
    Alekh

    Thanks Andy, so as per the suggestion we have to handle the above snippet as individual if block statements as i had shown below.
    But in this case how we show the else part as NULL.
    correct me if my understanding is wrong.
    if  'Products' in (:P1_ENG_GRP1, :P1_ENG_GRP2, :P_ENG_GRP3) then
                    lv_to_email_id :='[email protected]';
    end if;
    if  'Materials' in (:P1_ENG_GRP1, :P1_ENG_GRP2, :P_ENG_GRP3) then
               lv_to_email_id :='[email protected]';
    end if;Thanks,
    Anoo..

  • When i change permission of folder why it doesn't change the permission inside that folder?

    When i change permission of folder why it doesn't change the permission to inside  files of that folder?

    have to select "apply to enclosed items" options

  • Why does all alphabets change to capital when converting pdf to word using Adobe Acrobat XI

    Why does all alphabets change to capital when converting pdf to word using Adobe Acrobat XI

    Word 2013 uses its own pdf creator engine as far as I know. The step I performed were:
    1 - In the save settings I told word to embed fonts (sorry for the language, I have the Italian client)
    2 - Export from Word -> Save As -> .pdf adding also the table of contents/index
    N.B. I cannot use PDF/A, and in any case it doesn't embed the font
    A working solution is to use Acrobat XI to convert it or print with Adobe PDF printer, results:
    The problems are 2:
    1 - It doesn't create any bookmark and doesn't create links from the table of images to the linked images
    2 - Images, also with the preset "High Quality Printing" customized using "No compression", are really ugly and if you zoom a bit more than 100% they totally be s**t. It wasn't that way with PDF created by word.
    In the end, or I find they way to open the pdf created by word and embedd the missing font, or I find a way to make Acrobat XI creating bookmarks from the word file.
    Suggestion?

  • Why can't I change to size of my test in emails now? CanI go back to previous email version. This one is horrible!!!

    Why can't I change to size of my test in emails now? CanI go back to previous email version. This one is horrible. On my last update I was able to easilt find old emails now they disappear!!!! WTF?
    This version cannot change the text size Do I have to go back to IE?

    Which email site do you use?
    And some general advice:
    When you have a problem with one particular site, a good "first thing to try" is clearing your Firefox cache and deleting your saved cookies for the site.
    (1) Bypass Firefox's Cache
    Use Ctrl+Shift+r to reload the page fresh from the server.
    Alternately, you also can clear Firefox's cache completely using:
    "3-bar" menu button (or Tools menu) > Options > Advanced
    On the Network mini-tab > Cached Web Content : "Clear Now"
    If you have a large hard drive, this might take a few minutes.
    (2) Remove the site's cookies (save any pending work first). While viewing a page on the site, try either:
    * right-click and choose View Page Info > Security > "View Cookies"
    * Alt+t (open the classic Tools menu) > Page Info > Security > "View Cookies"
    In the dialog that opens, you can remove the site's cookies individually.
    Then try reloading the page. Does that help?

  • HT201210 Why can't I change the location of my device backups?

    Why can't I change the location of my device backups?
    iTunes seems to force me to use my c:\ drive as the destination for all backups. 
    Background: I have set up my c:\ drive only for programs - all data is stored on separate drives - including my iTunes library and all media. So, I can't skinny down the c:\ drive any more without uninstalling programs.
    The issue is that my 10,000 rpm, 280 GB - C:\ drive is fast but small and is now FULL after I got about 1/2 way through a 128 GB backup of my ipad.  (Yes, all movies have been deleted off of the iPad to minimize the size of the backup.)
    I deleted the partial iPad backup, moved all the Mobile Applications to another drive, emptied the recycle bin and tried again with my much smaller iPhone.  You guessed it: the io7 update hung and both of my devices are now paper weights.
    Which leaves me f*cked, anyone know how I can un-f myself? 

    SPURCHASE wrote:
    The issue is that my 10,000 rpm, 280 GB - C:\ drive is fast but small and is now FULL after I got about 1/2 way through a 128 GB backup of my ipad.  (Yes, all movies have been deleted off of the iPad to minimize the size of the backup.)
    iTunes movies are not part of an iDevice backup.
    Videos & photos you take with the camera (in the Camera roll) are part of the backup but those should be sync'd to the computer and removed from the camera roll.

  • Code changes are not reflecting

    Hi,
    I am facing one strange issue.
    One of my colleague developer made some code changes. He checkin the code and was transported successfully to quality system. The changes are working fine in quality system.
    Now using my NWDS I synced the code by connecting to NWDI. When I build and deployed the code in my local server I am not able to see the all the code changes in my system. I am able to see some label changes but not all the code changes.
    I checked the deployment of my local server by keeping some print statements and it is fine.
    I removed the entire configuration from Development Configurations perspective and imported the configuration, created the project again. But still I am facing the same issue.
    Can anyone help me in resolving this issue.
    Regards
    MQ

    Hello MQ,
    That is weired..Can you check in C:/USR/...  where your JSP's and Java classes gets deployed. See if you get the changes deployed at this location you are looking for. You need to decompile your class file to Java file to see the content of it. If you still have issues , remove all the DC's from your NWDS, import again from the track , undeploy your EAR from SDM, and deploy it again.
    But some other functionalities which are coming in my system are not coming in that system.  Did you deploy to any server? If so, are you seeing all your changes on the server. Check you are connecting to right NWDI and to the right track.
    I am sure you might have tried all these options..but nothing is striking to my  mind at this time.
    Thanks,
    Raj

  • Why is the code, in which I know Im right about, isn't retrieving my serial number?

    Why is the code, in which I know Im right about, isn't retrieving my serial number?

    I bought the copy from staples. Opened it and it has two CDs, one Mac and one Windows. Also is a card saying 'look on back for codes' DA DA DA. On the other side it says 'redemption code' exactly. Right below was a letter/nmber code, which fit exactly when entered. I might add that the once grey icon becomes blue after entering the last digit. So I know the type of code is correct, but it appears invalid since that's what's displaying in a yellow caption box after pushing enter

Maybe you are looking for

  • How do I transfer bookmarks from one computer to another using a CD and not get dupulation of bookmarks

    I want to copy my bookmarks to a Cd to take to another computer location and than transfer them to another computer without having duplication of bookmarks and without having to piece-meal look for each bookmark duplicate. How do I find bookmarks on

  • Installing photoshop extended (cs6) on to new computer

    Hi So I've just recently gotten another computer and I would like to download photoshop extended on it however I can't find it anywhere in the products to download trial and verify code, is it no longer available? Thanks

  • External displays and projectors

    I've been having problems getting my MacbookAir (Mid 2012) running OSX 10.8.2 to use external displays and video projectors via VGA and DVI adapters. The problem is that if I am connected to my external monitor and disconnect the magsafe power adapte

  • How to change height of highlight

    I am highlighting some text in a document that I converted from a web page using the converter in Acrobat. The highlighting height is about 2 lines of text high, so as I highlight one line it also highlights half of the line above and half of the lin

  • Vertical report with two columns

    I have table with picture. I can display common sql report(horizontal or vertical). Is it possible to display this to two columns (eshop).Two vertical columns (for example field of records 10x2). Message was edited by: user542927