Floating-point number C + + arithmetic operator __c++

Source: Internet
Author: User
Tags arithmetic arithmetic operators
floating point numbers

The computer divides floating point numbers into two-part storage. Part represents a value. The other part is used to magnify or shrink the value. The effect of scaling is to move the decimal point, which is the name of the term floating-point. two representation methods of floating point numbers 1. Standard decimal point notation

D.DD 2, E (e) notation

D.dde+n (D.dden) refers to move the decimal point to the right n bit, d.dde-n to move the decimal point to the left of N-bit significant digits

From the first number on the left that is not 0, to the exact number of digits, all numbers are called valid numbers for this number.
C and C + + for floating-point number of significant digits is required, float6 bit, double15 bit.
code example

Float.cpp--Floating=point types
#include <iostream>
int main ()
{
    using namespace std;
    COUT.SETF (Ios_base::fixed,ios_base::floatfield);
    float tub=10.0/3.0;
    Double mint=10.0/3.0;
    const float MILLION=1.0E6;

    cout<< "tub=" <<tub;
    cout<< ", a million tubs =" <<million*tub;
    cout<< ". \nand ten millions tubs =";
    cout<<10*million*tub<<endl;

    cout<< "mint =" <<mint<< "and a million mints =";
    cout<<million*mint<< Endl;
    return 0;
}

C + + arithmetic operators modulo operator

% modulus operator, whose value is the same as the symbol for the dividend conversion (C++11) when initialized in {} mode

C++11 the initialization of curly braces is called list initialization, because this initialization is often used to provide a list of values for complex data, and he has more stringent requirements for type conversions and does not allow narrowing.

const int code =;
int x =;
Char C1 {31325};//does not allow char
c2 = {66};//Allow char C3 = {code};//
allow
char C4 = {x};//not be allowed
x = 31325;
char c5 = x;//Allow
C + + compiler arithmetic expression type conversion validation tableIf the type of another operand is a long double, the other operand is converted to a long double. Otherwise, if there is one operand of type double, the other operand is converted to double. Otherwise, if the type of the operand is float, the other operand is converted to float. Otherwise, the operand is an integer, so an integral elevation is performed. In this case, if the two operands are both signed or unsigned, and one of the operands is lower than the other, the type is converted to a high level. Converts a signed operand to the type that the unsigned operand belongs to if one operand is signed and the other operand is unsigned and the level of the unsigned operand is higher than the signed number. Otherwise, if a signed type can represent all possible values for an unsigned type, the unsigned operand is converted to the type of the signed operand. Otherwise, the two operands are converted to unsigned versions of the signed type.

Static_cast<> can be used to convert a value from a numeric type to another numeric type.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.