Home > Back-end >  C and C the number of significant digits for a double
C and C the number of significant digits for a double

Time:09-16

After I made a score of decimal topic, and learned to use variable control precision,
Namely: printf (" %. * lf ", n, x); N will automatically replace the *, so as to control the accuracy of x for the output variable,

Topic is


but then I found for the introduction of different libraries would affect the number of significant digits double variables,

Note: please ignore me while in c + +, but still USES the scanf and printf, this is in the control variable,

Code:
 
//c + +

#include
using namespace std;

Int main ()
{
Int a, b, c;
While (the scanf (" % d % d % d ", & amp; A, & amp; B, & amp; C)!=EOF & amp; & ! (a==0 & amp; & B==0 & amp; & C==0))
{
Double the result=1.0 * a/b;
Printf (" %. * lf \ n, c, result);
}
return 0;
}

//input 8 3 33
//output 2.666666666666666518636930049979128



//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//C

#include

Int main ()
{
Int a, b, c;
Double the result;
While (the scanf (" % d % d % d ", & amp; A, & amp; B, & amp; C)!=EOF & amp; & ! (a==0 & amp; & B==0 & amp; & C==0))
{
Result=1.0 * a/b;
Printf (" %. * lf \ n, c, result);
}
return 0;
}

//input 8 3 33
//output 2.666666666666666500000000000000000 (apparently lost accuracy)




Want to ask bosses of BBS, is this why? Why the introduction of different libraries can lead to effective double digits, is universal in that c + + header file have what effect?

My compiler is: Dev - c + +
GCC version: GCC version 3.4.5 (mingw - vista special r3)

CodePudding user response:

Not loss of accuracy, but the display is not the same, that is to say, the c + + and c printf handling inconsistent

CodePudding user response:

Floating-point format http://bbs.csdn.net/topics/390676437

CodePudding user response:

Please learn how to observe before understanding and discussion!

Computer composition principle and DOS command to assembly language, C language (not including the C + +), code written specification and data structure, compiling principle, operating system and computer network, database principle, the regular expression to other languages (including C + +), architecture...

To learn programming advice:
Multi-purpose cerebellum and hand and less in the brain, eyes and mouth, will learn faster programming!
Eye over thousand times than hand it again!
Book is better than one thousand lines of hand knock a line!
Hand knock is better than one thousand lines of a single step line!
Single step source code is better than one thousand lines of single-step the Debug version of the corresponding assembly line!
Single step the Debug version of the corresponding assembly is better than one thousand lines of single-step Release version corresponding to the assembly line!
Will not step the Release version of the corresponding assembly? In you want to step the Release version of C/C + + code snippets in the front of the temporarily add DebugBreak (); Rebuild all, and then run in the IDE, (average person I don't tell him!

Single step class instances "tectonic" or "copy" or "as a function parameter" or "as a function return value return" or "to participate in various operations" or "out of scope" statement of corresponding assembly code after a few steps, will come to the class of "constructor" or "copy constructor" or "operator overloading" or "of" the destructor corresponding C/C + + source code,

VC debugging when press Alt + 8, Alt + 7, Alt + 6 and Alt + 5, open the assembly window, stack window, memory window and registers the window to see each other C corresponding assembly, single step, and observe the corresponding stack memory and registers changes, this again is not what all understand,
For VC, the so-called 'when debugging is compiled to connect through the later, after press F10 or F11 key step by step, or in a row after press F9 set the breakpoint press F5 execution stops at the breakpoint,

CodePudding user response:

Understand a printf print only a floating number, but why two parameters. And the printed result also is right,,,, and %. * lf is what mean?

CodePudding user response:

Understands that this usage, studied the
I compiled using GCC and g + +, respectively, the result is the same, there is no loss of accuracy
Should be the problem of the compiler
  • Related