Data type integer??? JS | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Data type integer??? JS

Currently I'm learning Data Types in JS. Some things in it I found really hard to understand. I have searched it as well in Google but it still looks hard to properly understand. Request you to provide simple answers as you can as I'm not math student. Thanks in advance! So here are my questions: What is: 1) Real Data Type? 2) Fixed Point Numbers? 3) Floating Point Numbers? 4) Single precision Floating Point Number? 5) Double Precision Floating Point Number?

30th May 2020, 7:30 AM
Himanshu Rai
Himanshu Rai - avatar
3 Answers
+ 2
2) We can take a real number like 12345.678 and convert it to scientific notation, like we did in high school: 12345.678 = 1.2345678 * 10^4. Then we can store our real number as two whole numbers, 12345678 and 4. That's floating point numbers. It gives us more flexibility because the level of precision is not fixed, like with fixed point numbers. However, if a floating point number takes up say 32 bits of storage there is a maximum level of precision we can store. Sometimes we need more precision than this 32 bit "single precision", and so we also have 64 bit "double precision" numbers. So it all comes down to how the computer represents real numbers. We cannot have infinite precision and there are trade offs. Keep in mind that I am simplifying. A.computer works in binary which makes this even more tricky.
30th May 2020, 8:47 AM
Schindlabua
Schindlabua - avatar
+ 2
Javascript only has a "number" type that works for all numbers (kind of). So it's not the best language for learning about that sort of thing. Anyway: Storing whole numbers (1, 2, 3, ..) in a computer is easy. A computer's job is literally working with numbers. Real numbers (1.3, √2, 4/7, ...) are more tricky. We somehow need to be able to take any real number and store it as whole numbers because that's all a computer can do. We can: 1) Take a whole number, 1234567 and pretend like the last 3 digits are for the fractional part, after the comma: 1234.567—that's fixed point numbers. In this example you can store exactly 3 digits after the dot. That's 3 digits of precision. Of course we can not represent all real numbers this way, a 3 digit precision fixed point number cannot represent 1.2345 because that would require 4 digits of precision. [cont.]
30th May 2020, 8:43 AM
Schindlabua
Schindlabua - avatar
0
Thanks buddy for clarifying it in simple language!😊
30th May 2020, 9:09 AM
Himanshu Rai
Himanshu Rai - avatar