unsigned long long and long double and round up/down and precision control and scale control

(If there are any mistakes, please leave a message to correct them, thank you!)

unsigned long long:

Range: 0~2^64-1 = 1844674407370955161;

input Output:

unsigned long long a,b,c;
scanf("%llu",&a);
printf("%llu\n", a);
cin>>b;
cout<<b<<"\n";
scanf("%I64u",&c);
printf("%I64u\n",c );

Some OJs use uLL with %I64u and LL with %I64d, such as codeforces.

Microsoft Visual C++ 6.0: use %I64u

Win system: %llu can be used

Linux system: use %llu

(I heard there is a bigger _int128, but I won't use it)



long double:

Bits: 128 bits

Valid numbers: 18~19

(specifically related to the compiler, operating system)

input Output:

long double a,b;
scanf("%llf",&a);
printf("%llf\n",a );
cin>>b;
cout<<b<<"\n";

tips:

When brushing ACM questions, when the output type is double, you do not necessarily need to use %lf, and generally use %f.

There are also output methods for floating-point types: %e/%E and %g; one is an exponential form, and the other is an automatic selection


Improvement / trade-in:

Round up: double ceil(double x)

Round down: double floor(double x)


rounding:

double b;

int a=(int)(b+0.5);


Precision Control:

1).

const double eps = 1e-8;

When forcing type conversion and comparing floating-point sizes, it is often safer to add eps, and the specific precision of eps depends on the topic!

double cast to int:

int a;
double b;
a = (int)(b+eps);

Compare floating-point type sizes:

double a,b;
if(ab>eps)printf("a is bigger\n");
if(ab<-eps)printf("a is smaller\n");

2).

When controlling how many decimal places are output:

#include <iomanip>

double a;
printf("%.4f\n",a );
printf("%.*f\n",4,a);

double b;
cout.setf(ios::fixed);
cout<<setprecision(4)<<b<<"\n";

double c;
cout<<fixed<<setprecision(4)<<c<<"\n";

cout.unsetf(ios::fixed);//Close fill with 0  
cout <<setprecision(4)<<d<<"\n";



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324476996&siteId=291194637