Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is E in floating point?

Tags:

c#

.net

What is E+3? What exactly happens here? Can we use this approach in other data types or can we only use it in floating points?

static void Main(string[] args)
{
    double w = 1.7E+3;
    Console.WriteLine(w);
}

Output: 1700

like image 599
Masoud Darvishian Avatar asked May 21 '12 14:05

Masoud Darvishian


People also ask

What is meaning of E in floating-point?

Because superscripted exponents like 107 cannot always be conveniently displayed, the letter E or e is often used to represent times ten raised to the power of (which would be written as "x 10b") and is followed by the value of the exponent.

What is E+ in a number?

The Scientific format displays a number in exponential notation, replacing part of the number with E+n, in which E (exponent) multiplies the preceding number by 10 to the nth power. For example, a 2-decimal scientific format displays 12345678901 as 1.23E+10, which is 1.23 times 10 to the 10th power.

How do you read E numbers?

In statistics, the symbol e is a mathematical constant approximately equal to 2.71828183. Prism switches to scientific notation when the values are very large or very small. For example: 2.3e-5, means 2.3 times ten to the minus five power, or 0.000023.

What are the parts of a floating-point number?

IEEE floating point numbers have three basic components: the sign, the exponent, and the mantissa.


1 Answers

E notation

Most calculators and many computer programs present very large and very small results in scientific notation. Because superscripted exponents like 107 cannot always be conveniently displayed, the letter E or e is often used to represent times ten raised to the power of (which would be written as "x 10b") and is followed by the value of the exponent. Note that in this usage the character e is not related to the mathematical constant e or the exponential function ex (a confusion that is less likely with capital E); and though it stands for exponent, the notation is usually referred to as (scientific) E notation or (scientific) e notation, rather than (scientific) exponential notation (though the latter also occurs). The use of this notation is not encouraged by publications.


As for your second question:

can we use this approach in other data type or we can only use it in floating points?

See the C# spec:

Real literals [the type of numeric literals that are allowed an E in them] are used to write values of types float, double, and decimal.

However, you have to cast or suffix the literal appropriately when assigning to anyhting other than a Double, because any literal with an e or E in it is recognized as a Double in Visual Studio. I cannot find where this behavior is specified.

float f1 = 7E1;     // Compile error. Needs F suffix (7E1F)
decimal d1 = 8E2;   // Compile error. Needs M suffix (8E2M)
double d2 = 9E3;    // Works.

int overninethousand = (int)9E3 + 1; // Works
like image 116
CodeCaster Avatar answered Sep 18 '22 19:09

CodeCaster