Floating point Data types in Go lang

As we have discussed, In our previous article Data types in go lang, In Go lang Numbers can be categorized into two broad categories.
  1. Integral Numbers
  2. Floating point Numbers
We have already discussed integral numbers In this article we will discuss all floating point numbers.

Floating point Numbers

Floating point numbers are those which contains decimal places, for example (2.34 , -90.435 , 0.00007)

Rules for floating point numbers 

  1. Floating point number can contain decimal places, For example (0.006, 2.45)
  2. Can be +ve and -ve.
  3. Floating point number can be written in two formats
    1. Fixed format, example (0.007)
    2. Exponent format, example (0.7 E -4)
    3. 0.7 E -4 is equivalent to 0.7 * 10 <sup>-4</sup>
    4. In 0.7 E -4, 0.7 (part before e) is called mantissa and -4 (part after E) is called exponent.
  4. Exponent format is used when a number is too large or too small to represent in decimal places.
  5. Floating point number can be of 32bits or 64bits in size in go lang.
  6. float32 represents 32 bits floating point numbers also called single precision. It allows maximum 6-7 digits of precision(number of digits after decimal point).
  7. float64 represents 64 bits floating point numbers also called double precision. It allows 14-17 digits precision(number of digits after decimal point)
  8. floating points numbers includes some constant values for undefined results as given below with examples.
    1. 1.0/0 results +INF
    2. -1.0/0 results -INF
  9. Along with the floating point, numbers go also allows a data type for storing complex numbers like 2 + 3i, where 3 is an imaginary number.
  10. For representing complex number complex64 (real float32 , img float32)  and complex128 (real float64, img float64) are given.
  11. In complex64 real number is of type float32 and the imaginary part is also float32 so it occupies 64 bits in memory similarly in the complex128 real and imaginary part of size float64.
So if we finally conclude this article then we can say that floating data types includes four data types in go lang to work with floating numbers which are listed here.
  1. float32
  2. float64
  3. complex64
  4. complex128 


Popular posts from this blog

Program to calculate telephone bill

Sum of two numbers in go lang

Program to check a year is leap year or not.

String in golang


Arrays in C Language

Reserved Words in Java

Data types in Java

Pointers in C Language

Literals in Java