LDBL_MAX and LDBL_MIN returns an a wrong answer when I submmited my code to an online judge












0















I'm practicing some questions online using an online judge that does not support English; query: should I link the question (that's not in English) here?



The problem is quite simple, I'm asked to input N which will be the amount of numbers that I will insert. Then, I'm asked to find out which has the biggest value and smallest value. I'm also asked to calculate the average and the standard deviation of those numbers. I'm provided a formula for the standard deviation, too. Problem is, when I tried using LDBL_MIN and LDBL_MAX in my code below:



#include <iostream>
#include <iomanip>
#include <math.h>
#include <float.h>

using namespace std;

int main() {
int N;
cin >> N;
long double maxValue = LDBL_MIN, minValue = LDBL_MAX, sds = 0, avg = 0;

for (int i = 0; i < N; i++) {
long double temp;
cin >> temp;
if (maxValue < temp)
maxValue = temp;
if (minValue > temp)
minValue = temp;

avg += temp;
sds += temp * temp;
}

avg /= N;
sds = sqrt((sds - (N * avg * avg)) / (N - 1));
cout << fixed << setprecision(2) << minValue << " " << maxValue << " " << avg << " " << sds << endl;

return 0;
}


I get a wrong answer (I got one wrong answer out of four test cases). So one of my friends suggested me to try using the lower bound - 1 and upper bound - 1 of the constraint given by the question and it returned all correct. I changed the maxValue part to:



long double maxValue = -1000001, minValue = 1000001



What happened here? I thought that LDBL_MIN and LDBL_MAX would both give the same results as the alternative my friend suggested.










share|improve this question























  • Which compiler did you use ? when LBDL_MIN/MAX did not work as expected, you should use maxValue = minValue = first_input_value.

    – tunglt
    Nov 20 '18 at 13:16











  • Was you code required to handle subnormal, zero, and negative inputs?

    – Patricia Shanahan
    Nov 20 '18 at 14:01











  • You are probably focusing on the wrong problem. avg /= N is not going to end well when the machine test your program with N==0.

    – Hans Passant
    Nov 20 '18 at 15:39











  • @EricPostpischil Replacing LBDL_MIN with -1000001 should change behavior for inputs in the range (-1000001, LBDL_MIN), which includes the negative numbers greater than -1000001, zero, and the subnormal positive numbers.

    – Patricia Shanahan
    Nov 20 '18 at 16:01






  • 1





    @PatriciaShanahan: Ah, LDBL_MIN is actually misnamed; it should be LDBL_MIN_POSITIVE_NORMAL. That could explain OP’s observation.

    – Eric Postpischil
    Nov 20 '18 at 16:24
















0















I'm practicing some questions online using an online judge that does not support English; query: should I link the question (that's not in English) here?



The problem is quite simple, I'm asked to input N which will be the amount of numbers that I will insert. Then, I'm asked to find out which has the biggest value and smallest value. I'm also asked to calculate the average and the standard deviation of those numbers. I'm provided a formula for the standard deviation, too. Problem is, when I tried using LDBL_MIN and LDBL_MAX in my code below:



#include <iostream>
#include <iomanip>
#include <math.h>
#include <float.h>

using namespace std;

int main() {
int N;
cin >> N;
long double maxValue = LDBL_MIN, minValue = LDBL_MAX, sds = 0, avg = 0;

for (int i = 0; i < N; i++) {
long double temp;
cin >> temp;
if (maxValue < temp)
maxValue = temp;
if (minValue > temp)
minValue = temp;

avg += temp;
sds += temp * temp;
}

avg /= N;
sds = sqrt((sds - (N * avg * avg)) / (N - 1));
cout << fixed << setprecision(2) << minValue << " " << maxValue << " " << avg << " " << sds << endl;

return 0;
}


I get a wrong answer (I got one wrong answer out of four test cases). So one of my friends suggested me to try using the lower bound - 1 and upper bound - 1 of the constraint given by the question and it returned all correct. I changed the maxValue part to:



long double maxValue = -1000001, minValue = 1000001



What happened here? I thought that LDBL_MIN and LDBL_MAX would both give the same results as the alternative my friend suggested.










share|improve this question























  • Which compiler did you use ? when LBDL_MIN/MAX did not work as expected, you should use maxValue = minValue = first_input_value.

    – tunglt
    Nov 20 '18 at 13:16











  • Was you code required to handle subnormal, zero, and negative inputs?

    – Patricia Shanahan
    Nov 20 '18 at 14:01











  • You are probably focusing on the wrong problem. avg /= N is not going to end well when the machine test your program with N==0.

    – Hans Passant
    Nov 20 '18 at 15:39











  • @EricPostpischil Replacing LBDL_MIN with -1000001 should change behavior for inputs in the range (-1000001, LBDL_MIN), which includes the negative numbers greater than -1000001, zero, and the subnormal positive numbers.

    – Patricia Shanahan
    Nov 20 '18 at 16:01






  • 1





    @PatriciaShanahan: Ah, LDBL_MIN is actually misnamed; it should be LDBL_MIN_POSITIVE_NORMAL. That could explain OP’s observation.

    – Eric Postpischil
    Nov 20 '18 at 16:24














0












0








0








I'm practicing some questions online using an online judge that does not support English; query: should I link the question (that's not in English) here?



The problem is quite simple, I'm asked to input N which will be the amount of numbers that I will insert. Then, I'm asked to find out which has the biggest value and smallest value. I'm also asked to calculate the average and the standard deviation of those numbers. I'm provided a formula for the standard deviation, too. Problem is, when I tried using LDBL_MIN and LDBL_MAX in my code below:



#include <iostream>
#include <iomanip>
#include <math.h>
#include <float.h>

using namespace std;

int main() {
int N;
cin >> N;
long double maxValue = LDBL_MIN, minValue = LDBL_MAX, sds = 0, avg = 0;

for (int i = 0; i < N; i++) {
long double temp;
cin >> temp;
if (maxValue < temp)
maxValue = temp;
if (minValue > temp)
minValue = temp;

avg += temp;
sds += temp * temp;
}

avg /= N;
sds = sqrt((sds - (N * avg * avg)) / (N - 1));
cout << fixed << setprecision(2) << minValue << " " << maxValue << " " << avg << " " << sds << endl;

return 0;
}


I get a wrong answer (I got one wrong answer out of four test cases). So one of my friends suggested me to try using the lower bound - 1 and upper bound - 1 of the constraint given by the question and it returned all correct. I changed the maxValue part to:



long double maxValue = -1000001, minValue = 1000001



What happened here? I thought that LDBL_MIN and LDBL_MAX would both give the same results as the alternative my friend suggested.










share|improve this question














I'm practicing some questions online using an online judge that does not support English; query: should I link the question (that's not in English) here?



The problem is quite simple, I'm asked to input N which will be the amount of numbers that I will insert. Then, I'm asked to find out which has the biggest value and smallest value. I'm also asked to calculate the average and the standard deviation of those numbers. I'm provided a formula for the standard deviation, too. Problem is, when I tried using LDBL_MIN and LDBL_MAX in my code below:



#include <iostream>
#include <iomanip>
#include <math.h>
#include <float.h>

using namespace std;

int main() {
int N;
cin >> N;
long double maxValue = LDBL_MIN, minValue = LDBL_MAX, sds = 0, avg = 0;

for (int i = 0; i < N; i++) {
long double temp;
cin >> temp;
if (maxValue < temp)
maxValue = temp;
if (minValue > temp)
minValue = temp;

avg += temp;
sds += temp * temp;
}

avg /= N;
sds = sqrt((sds - (N * avg * avg)) / (N - 1));
cout << fixed << setprecision(2) << minValue << " " << maxValue << " " << avg << " " << sds << endl;

return 0;
}


I get a wrong answer (I got one wrong answer out of four test cases). So one of my friends suggested me to try using the lower bound - 1 and upper bound - 1 of the constraint given by the question and it returned all correct. I changed the maxValue part to:



long double maxValue = -1000001, minValue = 1000001



What happened here? I thought that LDBL_MIN and LDBL_MAX would both give the same results as the alternative my friend suggested.







c++ floating-point






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 12:57









Richard WRichard W

353115




353115













  • Which compiler did you use ? when LBDL_MIN/MAX did not work as expected, you should use maxValue = minValue = first_input_value.

    – tunglt
    Nov 20 '18 at 13:16











  • Was you code required to handle subnormal, zero, and negative inputs?

    – Patricia Shanahan
    Nov 20 '18 at 14:01











  • You are probably focusing on the wrong problem. avg /= N is not going to end well when the machine test your program with N==0.

    – Hans Passant
    Nov 20 '18 at 15:39











  • @EricPostpischil Replacing LBDL_MIN with -1000001 should change behavior for inputs in the range (-1000001, LBDL_MIN), which includes the negative numbers greater than -1000001, zero, and the subnormal positive numbers.

    – Patricia Shanahan
    Nov 20 '18 at 16:01






  • 1





    @PatriciaShanahan: Ah, LDBL_MIN is actually misnamed; it should be LDBL_MIN_POSITIVE_NORMAL. That could explain OP’s observation.

    – Eric Postpischil
    Nov 20 '18 at 16:24



















  • Which compiler did you use ? when LBDL_MIN/MAX did not work as expected, you should use maxValue = minValue = first_input_value.

    – tunglt
    Nov 20 '18 at 13:16











  • Was you code required to handle subnormal, zero, and negative inputs?

    – Patricia Shanahan
    Nov 20 '18 at 14:01











  • You are probably focusing on the wrong problem. avg /= N is not going to end well when the machine test your program with N==0.

    – Hans Passant
    Nov 20 '18 at 15:39











  • @EricPostpischil Replacing LBDL_MIN with -1000001 should change behavior for inputs in the range (-1000001, LBDL_MIN), which includes the negative numbers greater than -1000001, zero, and the subnormal positive numbers.

    – Patricia Shanahan
    Nov 20 '18 at 16:01






  • 1





    @PatriciaShanahan: Ah, LDBL_MIN is actually misnamed; it should be LDBL_MIN_POSITIVE_NORMAL. That could explain OP’s observation.

    – Eric Postpischil
    Nov 20 '18 at 16:24

















Which compiler did you use ? when LBDL_MIN/MAX did not work as expected, you should use maxValue = minValue = first_input_value.

– tunglt
Nov 20 '18 at 13:16





Which compiler did you use ? when LBDL_MIN/MAX did not work as expected, you should use maxValue = minValue = first_input_value.

– tunglt
Nov 20 '18 at 13:16













Was you code required to handle subnormal, zero, and negative inputs?

– Patricia Shanahan
Nov 20 '18 at 14:01





Was you code required to handle subnormal, zero, and negative inputs?

– Patricia Shanahan
Nov 20 '18 at 14:01













You are probably focusing on the wrong problem. avg /= N is not going to end well when the machine test your program with N==0.

– Hans Passant
Nov 20 '18 at 15:39





You are probably focusing on the wrong problem. avg /= N is not going to end well when the machine test your program with N==0.

– Hans Passant
Nov 20 '18 at 15:39













@EricPostpischil Replacing LBDL_MIN with -1000001 should change behavior for inputs in the range (-1000001, LBDL_MIN), which includes the negative numbers greater than -1000001, zero, and the subnormal positive numbers.

– Patricia Shanahan
Nov 20 '18 at 16:01





@EricPostpischil Replacing LBDL_MIN with -1000001 should change behavior for inputs in the range (-1000001, LBDL_MIN), which includes the negative numbers greater than -1000001, zero, and the subnormal positive numbers.

– Patricia Shanahan
Nov 20 '18 at 16:01




1




1





@PatriciaShanahan: Ah, LDBL_MIN is actually misnamed; it should be LDBL_MIN_POSITIVE_NORMAL. That could explain OP’s observation.

– Eric Postpischil
Nov 20 '18 at 16:24





@PatriciaShanahan: Ah, LDBL_MIN is actually misnamed; it should be LDBL_MIN_POSITIVE_NORMAL. That could explain OP’s observation.

– Eric Postpischil
Nov 20 '18 at 16:24












1 Answer
1






active

oldest

votes


















2














LDBL_MIN is the smallest positive normalized value that can be represented as a long double. So it's slightly greater than 0. That's different from the integer macros, which give the smallest value that can be represented. Floating-point types are usually symmetrical, so use -LDBL_MAX to get the smallest representable value. Or, in C++, use std::numeric_limits<long double>::lowest().






share|improve this answer
























  • I see! That's why I got it wrong. I'm supposed to test the negative inputs, too. I thought that LDBL_MIN would give me the true smallest value of long double< hence the counterpart of LDBL_MAX. Thank you, I did not know that I could do -LDBL_MIN to achieve the same effect.

    – Richard W
    Nov 20 '18 at 17:09











  • One thing, though, what does normalized value mean?

    – Richard W
    Nov 20 '18 at 17:10






  • 1





    Re: normalized value: suppose you have a personal rule to always write decimal values with one digit to the left of the decimal point: 1.03e6, etc. And suppose you have a rule that the exponent can't be any smaller than -10. So 1.00e-10 is the smallest normalized value you can represent. In order to have values that are closer to 0, you can go with 0.10e-10, and 0.01e-10. Those are denormalized values -- they have the minimum allowed exponent and don't have a 1 to the left of the decimal point. You get smaller values, but with less precision. That's what many floating-point systems do.

    – Pete Becker
    Nov 20 '18 at 18:18











  • I see. I meant -LDBL_MAX, by the way. In regard to normalized value, why do I have to follow that rule (always writing decimal values with one digit to the left of the decimal point)? What benefit does following that rule give? Also, wouldn't it be equal to 0 if I wrote 0.00e-10 instead of 0.01e-10?

    – Richard W
    Nov 21 '18 at 1:32













  • The point of that analogy is that that’s how floating-point math works on many systems.

    – Pete Becker
    Nov 21 '18 at 3:56











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393501%2fldbl-max-and-ldbl-min-returns-an-a-wrong-answer-when-i-submmited-my-code-to-an-o%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














LDBL_MIN is the smallest positive normalized value that can be represented as a long double. So it's slightly greater than 0. That's different from the integer macros, which give the smallest value that can be represented. Floating-point types are usually symmetrical, so use -LDBL_MAX to get the smallest representable value. Or, in C++, use std::numeric_limits<long double>::lowest().






share|improve this answer
























  • I see! That's why I got it wrong. I'm supposed to test the negative inputs, too. I thought that LDBL_MIN would give me the true smallest value of long double< hence the counterpart of LDBL_MAX. Thank you, I did not know that I could do -LDBL_MIN to achieve the same effect.

    – Richard W
    Nov 20 '18 at 17:09











  • One thing, though, what does normalized value mean?

    – Richard W
    Nov 20 '18 at 17:10






  • 1





    Re: normalized value: suppose you have a personal rule to always write decimal values with one digit to the left of the decimal point: 1.03e6, etc. And suppose you have a rule that the exponent can't be any smaller than -10. So 1.00e-10 is the smallest normalized value you can represent. In order to have values that are closer to 0, you can go with 0.10e-10, and 0.01e-10. Those are denormalized values -- they have the minimum allowed exponent and don't have a 1 to the left of the decimal point. You get smaller values, but with less precision. That's what many floating-point systems do.

    – Pete Becker
    Nov 20 '18 at 18:18











  • I see. I meant -LDBL_MAX, by the way. In regard to normalized value, why do I have to follow that rule (always writing decimal values with one digit to the left of the decimal point)? What benefit does following that rule give? Also, wouldn't it be equal to 0 if I wrote 0.00e-10 instead of 0.01e-10?

    – Richard W
    Nov 21 '18 at 1:32













  • The point of that analogy is that that’s how floating-point math works on many systems.

    – Pete Becker
    Nov 21 '18 at 3:56
















2














LDBL_MIN is the smallest positive normalized value that can be represented as a long double. So it's slightly greater than 0. That's different from the integer macros, which give the smallest value that can be represented. Floating-point types are usually symmetrical, so use -LDBL_MAX to get the smallest representable value. Or, in C++, use std::numeric_limits<long double>::lowest().






share|improve this answer
























  • I see! That's why I got it wrong. I'm supposed to test the negative inputs, too. I thought that LDBL_MIN would give me the true smallest value of long double< hence the counterpart of LDBL_MAX. Thank you, I did not know that I could do -LDBL_MIN to achieve the same effect.

    – Richard W
    Nov 20 '18 at 17:09











  • One thing, though, what does normalized value mean?

    – Richard W
    Nov 20 '18 at 17:10






  • 1





    Re: normalized value: suppose you have a personal rule to always write decimal values with one digit to the left of the decimal point: 1.03e6, etc. And suppose you have a rule that the exponent can't be any smaller than -10. So 1.00e-10 is the smallest normalized value you can represent. In order to have values that are closer to 0, you can go with 0.10e-10, and 0.01e-10. Those are denormalized values -- they have the minimum allowed exponent and don't have a 1 to the left of the decimal point. You get smaller values, but with less precision. That's what many floating-point systems do.

    – Pete Becker
    Nov 20 '18 at 18:18











  • I see. I meant -LDBL_MAX, by the way. In regard to normalized value, why do I have to follow that rule (always writing decimal values with one digit to the left of the decimal point)? What benefit does following that rule give? Also, wouldn't it be equal to 0 if I wrote 0.00e-10 instead of 0.01e-10?

    – Richard W
    Nov 21 '18 at 1:32













  • The point of that analogy is that that’s how floating-point math works on many systems.

    – Pete Becker
    Nov 21 '18 at 3:56














2












2








2







LDBL_MIN is the smallest positive normalized value that can be represented as a long double. So it's slightly greater than 0. That's different from the integer macros, which give the smallest value that can be represented. Floating-point types are usually symmetrical, so use -LDBL_MAX to get the smallest representable value. Or, in C++, use std::numeric_limits<long double>::lowest().






share|improve this answer













LDBL_MIN is the smallest positive normalized value that can be represented as a long double. So it's slightly greater than 0. That's different from the integer macros, which give the smallest value that can be represented. Floating-point types are usually symmetrical, so use -LDBL_MAX to get the smallest representable value. Or, in C++, use std::numeric_limits<long double>::lowest().







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 15:30









Pete BeckerPete Becker

58k442119




58k442119













  • I see! That's why I got it wrong. I'm supposed to test the negative inputs, too. I thought that LDBL_MIN would give me the true smallest value of long double< hence the counterpart of LDBL_MAX. Thank you, I did not know that I could do -LDBL_MIN to achieve the same effect.

    – Richard W
    Nov 20 '18 at 17:09











  • One thing, though, what does normalized value mean?

    – Richard W
    Nov 20 '18 at 17:10






  • 1





    Re: normalized value: suppose you have a personal rule to always write decimal values with one digit to the left of the decimal point: 1.03e6, etc. And suppose you have a rule that the exponent can't be any smaller than -10. So 1.00e-10 is the smallest normalized value you can represent. In order to have values that are closer to 0, you can go with 0.10e-10, and 0.01e-10. Those are denormalized values -- they have the minimum allowed exponent and don't have a 1 to the left of the decimal point. You get smaller values, but with less precision. That's what many floating-point systems do.

    – Pete Becker
    Nov 20 '18 at 18:18











  • I see. I meant -LDBL_MAX, by the way. In regard to normalized value, why do I have to follow that rule (always writing decimal values with one digit to the left of the decimal point)? What benefit does following that rule give? Also, wouldn't it be equal to 0 if I wrote 0.00e-10 instead of 0.01e-10?

    – Richard W
    Nov 21 '18 at 1:32













  • The point of that analogy is that that’s how floating-point math works on many systems.

    – Pete Becker
    Nov 21 '18 at 3:56



















  • I see! That's why I got it wrong. I'm supposed to test the negative inputs, too. I thought that LDBL_MIN would give me the true smallest value of long double< hence the counterpart of LDBL_MAX. Thank you, I did not know that I could do -LDBL_MIN to achieve the same effect.

    – Richard W
    Nov 20 '18 at 17:09











  • One thing, though, what does normalized value mean?

    – Richard W
    Nov 20 '18 at 17:10






  • 1





    Re: normalized value: suppose you have a personal rule to always write decimal values with one digit to the left of the decimal point: 1.03e6, etc. And suppose you have a rule that the exponent can't be any smaller than -10. So 1.00e-10 is the smallest normalized value you can represent. In order to have values that are closer to 0, you can go with 0.10e-10, and 0.01e-10. Those are denormalized values -- they have the minimum allowed exponent and don't have a 1 to the left of the decimal point. You get smaller values, but with less precision. That's what many floating-point systems do.

    – Pete Becker
    Nov 20 '18 at 18:18











  • I see. I meant -LDBL_MAX, by the way. In regard to normalized value, why do I have to follow that rule (always writing decimal values with one digit to the left of the decimal point)? What benefit does following that rule give? Also, wouldn't it be equal to 0 if I wrote 0.00e-10 instead of 0.01e-10?

    – Richard W
    Nov 21 '18 at 1:32













  • The point of that analogy is that that’s how floating-point math works on many systems.

    – Pete Becker
    Nov 21 '18 at 3:56

















I see! That's why I got it wrong. I'm supposed to test the negative inputs, too. I thought that LDBL_MIN would give me the true smallest value of long double< hence the counterpart of LDBL_MAX. Thank you, I did not know that I could do -LDBL_MIN to achieve the same effect.

– Richard W
Nov 20 '18 at 17:09





I see! That's why I got it wrong. I'm supposed to test the negative inputs, too. I thought that LDBL_MIN would give me the true smallest value of long double< hence the counterpart of LDBL_MAX. Thank you, I did not know that I could do -LDBL_MIN to achieve the same effect.

– Richard W
Nov 20 '18 at 17:09













One thing, though, what does normalized value mean?

– Richard W
Nov 20 '18 at 17:10





One thing, though, what does normalized value mean?

– Richard W
Nov 20 '18 at 17:10




1




1





Re: normalized value: suppose you have a personal rule to always write decimal values with one digit to the left of the decimal point: 1.03e6, etc. And suppose you have a rule that the exponent can't be any smaller than -10. So 1.00e-10 is the smallest normalized value you can represent. In order to have values that are closer to 0, you can go with 0.10e-10, and 0.01e-10. Those are denormalized values -- they have the minimum allowed exponent and don't have a 1 to the left of the decimal point. You get smaller values, but with less precision. That's what many floating-point systems do.

– Pete Becker
Nov 20 '18 at 18:18





Re: normalized value: suppose you have a personal rule to always write decimal values with one digit to the left of the decimal point: 1.03e6, etc. And suppose you have a rule that the exponent can't be any smaller than -10. So 1.00e-10 is the smallest normalized value you can represent. In order to have values that are closer to 0, you can go with 0.10e-10, and 0.01e-10. Those are denormalized values -- they have the minimum allowed exponent and don't have a 1 to the left of the decimal point. You get smaller values, but with less precision. That's what many floating-point systems do.

– Pete Becker
Nov 20 '18 at 18:18













I see. I meant -LDBL_MAX, by the way. In regard to normalized value, why do I have to follow that rule (always writing decimal values with one digit to the left of the decimal point)? What benefit does following that rule give? Also, wouldn't it be equal to 0 if I wrote 0.00e-10 instead of 0.01e-10?

– Richard W
Nov 21 '18 at 1:32







I see. I meant -LDBL_MAX, by the way. In regard to normalized value, why do I have to follow that rule (always writing decimal values with one digit to the left of the decimal point)? What benefit does following that rule give? Also, wouldn't it be equal to 0 if I wrote 0.00e-10 instead of 0.01e-10?

– Richard W
Nov 21 '18 at 1:32















The point of that analogy is that that’s how floating-point math works on many systems.

– Pete Becker
Nov 21 '18 at 3:56





The point of that analogy is that that’s how floating-point math works on many systems.

– Pete Becker
Nov 21 '18 at 3:56




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393501%2fldbl-max-and-ldbl-min-returns-an-a-wrong-answer-when-i-submmited-my-code-to-an-o%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings