This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

BamzeNET pastebin

Posted by Strom Thu 19th Aug 18:02

001 
002 
003 
004 
005 
006 
007 
008 
009 
010 
011 
012 
013 
014 
015 
016 
017 
018 
019 
020 
021 
022 
023 
024 
025 
026 
027 
028 
029 
030 
031 
032 
033 
034 
035 
036 
037 
038 
039 
040 
041 
042 
043 
044 
045 
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
        char *xT = "29.00000";
        char *x = "23.20000";
        char *xR = "5.800000";
        double dT = strtod(xT, NULL);
        double d = strtod(x, NULL);
        double dR = strtod(xR, NULL);

        printf("Parsing '%s' to %.20f=%10f=%f\n",
                        xT,
                        dT,dT,dT);
        printf("Parsing '%s' to %.20f=%10f=%f\n",
                        x,
                        d,d,d);
        printf("Parsing '%s' to %.20f=%10f=%f\n",
                        xR,
                        dR,dR,dR);

        printf("Is %.2f == %2f-%2f? ", dR, dT, d);
        if(dR == (dT - d))
                printf("Yes, proper calculation!\n");
        else            printf("No :( Fail calc \n");

        printf("Is %.2f-%2f == %2f? ", dT, dR, d);
        if(dT-dR == d)
                printf("Yes, proper calculation!\n");
        else            printf("No :( Fail calc \n");
        return 0;
}






$ gcc -O test.c -o test -Wall &&  ./test
Parsing '29.00000' to 29.00000000000000000000= 29.000000=29.000000
Parsing '23.20000' to 23.19999999999999928946= 23.200000=23.200000
Parsing '5.800000' to 5.79999999999999982236=  5.800000=5.800000
Is 5.80 == 29.000000-23.200000? No :( Fail calc 
Is 29.00-5.800000 == 23.200000? Yes, proper calculation!

The following amendments have been posted:

Submit a correction or amendment below. (click here to make a fresh posting)
Name

Remember my name in a cookie

To cope with spam please enter "im not a spambot" with first char in every word capitalized:


Code: To ensure legibility, keep your code lines under 80 characters long.
Include comments to indicate what you need feedback on.