Displaying big doubles in C [duplicate]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1
















This question already has an answer here:




  • Printf big double value with high precision in C

    4 answers




I've got a problem with diplaying big doubles.



Here's a code I've prepared:



#include <stdio.h>
#include <float.h>
#define M_PI 3.141592653589793238462643383279502884197169399375105820974944
int main()
{
printf("%.70fn",M_PI);
return 0;
}


It displays:



3.1415926535897931159979634685441851615905761718750000000000000000000000


But once I change M_PI for DBL_MAX everything is shown correctly.
What's worse is that when dot in M_PI definition is removed (leaving a really big number) the result is 0.



What do I do wrong? How can I display some huge numbers?










share|improve this question













marked as duplicate by gsamaras c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 18:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Removing the dot changes it to an integer. Try moving the dot to the end instead.

    – Patricia Shanahan
    Nov 24 '18 at 17:44











  • After moving it, 0 is no longer displayed but the number has chagned value after 16 digit, just like M_PI in my question.

    – Igor
    Nov 24 '18 at 17:49













  • double has effectively 53 bits of significand, equivalent to about 15.9 decimal digits, so rounding error after the 16th significant digit should be expected, and is nothing to do with printing.

    – Patricia Shanahan
    Nov 24 '18 at 17:54


















-1
















This question already has an answer here:




  • Printf big double value with high precision in C

    4 answers




I've got a problem with diplaying big doubles.



Here's a code I've prepared:



#include <stdio.h>
#include <float.h>
#define M_PI 3.141592653589793238462643383279502884197169399375105820974944
int main()
{
printf("%.70fn",M_PI);
return 0;
}


It displays:



3.1415926535897931159979634685441851615905761718750000000000000000000000


But once I change M_PI for DBL_MAX everything is shown correctly.
What's worse is that when dot in M_PI definition is removed (leaving a really big number) the result is 0.



What do I do wrong? How can I display some huge numbers?










share|improve this question













marked as duplicate by gsamaras c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 18:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Removing the dot changes it to an integer. Try moving the dot to the end instead.

    – Patricia Shanahan
    Nov 24 '18 at 17:44











  • After moving it, 0 is no longer displayed but the number has chagned value after 16 digit, just like M_PI in my question.

    – Igor
    Nov 24 '18 at 17:49













  • double has effectively 53 bits of significand, equivalent to about 15.9 decimal digits, so rounding error after the 16th significant digit should be expected, and is nothing to do with printing.

    – Patricia Shanahan
    Nov 24 '18 at 17:54














-1












-1








-1









This question already has an answer here:




  • Printf big double value with high precision in C

    4 answers




I've got a problem with diplaying big doubles.



Here's a code I've prepared:



#include <stdio.h>
#include <float.h>
#define M_PI 3.141592653589793238462643383279502884197169399375105820974944
int main()
{
printf("%.70fn",M_PI);
return 0;
}


It displays:



3.1415926535897931159979634685441851615905761718750000000000000000000000


But once I change M_PI for DBL_MAX everything is shown correctly.
What's worse is that when dot in M_PI definition is removed (leaving a really big number) the result is 0.



What do I do wrong? How can I display some huge numbers?










share|improve this question















This question already has an answer here:




  • Printf big double value with high precision in C

    4 answers




I've got a problem with diplaying big doubles.



Here's a code I've prepared:



#include <stdio.h>
#include <float.h>
#define M_PI 3.141592653589793238462643383279502884197169399375105820974944
int main()
{
printf("%.70fn",M_PI);
return 0;
}


It displays:



3.1415926535897931159979634685441851615905761718750000000000000000000000


But once I change M_PI for DBL_MAX everything is shown correctly.
What's worse is that when dot in M_PI definition is removed (leaving a really big number) the result is 0.



What do I do wrong? How can I display some huge numbers?





This question already has an answer here:




  • Printf big double value with high precision in C

    4 answers








c printing double






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 17:27









IgorIgor

153




153




marked as duplicate by gsamaras c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 18:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by gsamaras c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 24 '18 at 18:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Removing the dot changes it to an integer. Try moving the dot to the end instead.

    – Patricia Shanahan
    Nov 24 '18 at 17:44











  • After moving it, 0 is no longer displayed but the number has chagned value after 16 digit, just like M_PI in my question.

    – Igor
    Nov 24 '18 at 17:49













  • double has effectively 53 bits of significand, equivalent to about 15.9 decimal digits, so rounding error after the 16th significant digit should be expected, and is nothing to do with printing.

    – Patricia Shanahan
    Nov 24 '18 at 17:54



















  • Removing the dot changes it to an integer. Try moving the dot to the end instead.

    – Patricia Shanahan
    Nov 24 '18 at 17:44











  • After moving it, 0 is no longer displayed but the number has chagned value after 16 digit, just like M_PI in my question.

    – Igor
    Nov 24 '18 at 17:49













  • double has effectively 53 bits of significand, equivalent to about 15.9 decimal digits, so rounding error after the 16th significant digit should be expected, and is nothing to do with printing.

    – Patricia Shanahan
    Nov 24 '18 at 17:54

















Removing the dot changes it to an integer. Try moving the dot to the end instead.

– Patricia Shanahan
Nov 24 '18 at 17:44





Removing the dot changes it to an integer. Try moving the dot to the end instead.

– Patricia Shanahan
Nov 24 '18 at 17:44













After moving it, 0 is no longer displayed but the number has chagned value after 16 digit, just like M_PI in my question.

– Igor
Nov 24 '18 at 17:49







After moving it, 0 is no longer displayed but the number has chagned value after 16 digit, just like M_PI in my question.

– Igor
Nov 24 '18 at 17:49















double has effectively 53 bits of significand, equivalent to about 15.9 decimal digits, so rounding error after the 16th significant digit should be expected, and is nothing to do with printing.

– Patricia Shanahan
Nov 24 '18 at 17:54





double has effectively 53 bits of significand, equivalent to about 15.9 decimal digits, so rounding error after the 16th significant digit should be expected, and is nothing to do with printing.

– Patricia Shanahan
Nov 24 '18 at 17:54












1 Answer
1






active

oldest

votes


















0














In IEEE 754 64-bit binary floating point, the most common implementation of double, 3.141592653589793115997963468544185161590576171875 is the closest representable number to 3.141592653589793238462643383279502884197169399375105820974944, and so is what should be printed. In most cases, rounding error on conversion to double will appear after about 16 decimal digits.



DBL_MAX, by its definition, has to be exactly representable as a double, so there is no rounding error on its conversion from decimal string to double.






share|improve this answer
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    In IEEE 754 64-bit binary floating point, the most common implementation of double, 3.141592653589793115997963468544185161590576171875 is the closest representable number to 3.141592653589793238462643383279502884197169399375105820974944, and so is what should be printed. In most cases, rounding error on conversion to double will appear after about 16 decimal digits.



    DBL_MAX, by its definition, has to be exactly representable as a double, so there is no rounding error on its conversion from decimal string to double.






    share|improve this answer






























      0














      In IEEE 754 64-bit binary floating point, the most common implementation of double, 3.141592653589793115997963468544185161590576171875 is the closest representable number to 3.141592653589793238462643383279502884197169399375105820974944, and so is what should be printed. In most cases, rounding error on conversion to double will appear after about 16 decimal digits.



      DBL_MAX, by its definition, has to be exactly representable as a double, so there is no rounding error on its conversion from decimal string to double.






      share|improve this answer




























        0












        0








        0







        In IEEE 754 64-bit binary floating point, the most common implementation of double, 3.141592653589793115997963468544185161590576171875 is the closest representable number to 3.141592653589793238462643383279502884197169399375105820974944, and so is what should be printed. In most cases, rounding error on conversion to double will appear after about 16 decimal digits.



        DBL_MAX, by its definition, has to be exactly representable as a double, so there is no rounding error on its conversion from decimal string to double.






        share|improve this answer















        In IEEE 754 64-bit binary floating point, the most common implementation of double, 3.141592653589793115997963468544185161590576171875 is the closest representable number to 3.141592653589793238462643383279502884197169399375105820974944, and so is what should be printed. In most cases, rounding error on conversion to double will appear after about 16 decimal digits.



        DBL_MAX, by its definition, has to be exactly representable as a double, so there is no rounding error on its conversion from decimal string to double.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 24 '18 at 18:49









        too honest for this site

        1




        1










        answered Nov 24 '18 at 17:50









        Patricia ShanahanPatricia Shanahan

        22.6k22760




        22.6k22760

















            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()