Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scientific notation's type

int s = 1e9;

What is type of 1e9 and how precise is it? (Is it exactly equal to 1000000000?)

Printing type of a value/variable to stdout would be useful if it's possible.

like image 796
a-z Avatar asked Nov 28 '11 14:11

a-z


People also ask

What are the 4 rules of scientific notation?

Scientific Notation Rules The exponent must be a non-zero integer, that means it can be either positive or negative. The absolute value of the coefficient is greater than or equal to 1 but it should be less than 10. Coefficients can be positive or negative numbers including whole and decimal numbers.

What is scientific notation in computer?

Updated: 11/16/2019 by Computer Hope. A method of writing a very large or small numbers, scientific notation is an integer between 1 and 10 multiplied by the power of 10. For example, "987,000,000" could be written in scientific notation as 9.87 * 108, 9.87 * 10^8, or 9.87e+8.

Where is scientific notation used?

Scientific notation is used by scientists, mathematicians, and engineers when they are working with very large or very small numbers. Using exponential notation, large and small numbers can be written in a way that is easier to read.


1 Answers

1e9 is a double that has an exact representation in the IEEE floating point representation. The C++ standard doesn't mandate IEEE floating point.

s is an int, so the double value will be automatically converted to an int. How this takes place is to some extent up to the implementation. On most machines nowadays, this conversion means s will be given an initial value of 1000000000.

like image 155
David Hammen Avatar answered Oct 21 '22 08:10

David Hammen