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;
}
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?
c printing double
marked as duplicate by gsamaras
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.
add a comment |
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?
c printing double
marked as duplicate by gsamaras
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
add a comment |
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?
c printing double
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
c printing double
asked Nov 24 '18 at 17:27
IgorIgor
153
153
marked as duplicate by gsamaras
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
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
add a comment |
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.
add a comment |
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.
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.
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
add a comment |
add a comment |
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