Go Floating Point: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 21: Line 21:
var x float = 1.23e3
var x float = 1.23e3
</syntaxhighlight>
</syntaxhighlight>
=Printing Floating Point Numbers=
{{Internal|Go_Printing_to_Stdout_and_Stderr#Floating_Point_Numbers|Printing Floating Point Numbers with <tt>fmt.Printf()</tt>}}
=Complex Numbers=
=Complex Numbers=
<syntaxhighlight lang='go'>
<syntaxhighlight lang='go'>
var z complex128 = complex(2, 3)
var z complex128 = complex(2, 3)
</syntaxhighlight>
</syntaxhighlight>

Revision as of 00:51, 23 August 2023

Internal

Overview

Floating-point numbers are designated by the following pre-declared type identifiers:

  • Single precision float32 4 bytes IEEE-754 binary floating point, approximately 6 digits of precision.
  • Double precision float64, 15 digits of precision.
  • Complex: complex64 and complex128.

There is no float, as in the integer case, we must explicitly provide the precision.

Uninitialized variable value: +0.000000e+000

Floating-Point Literals

Decimals:

var x float = 123.45

Scientific notation, with exponent in base 10:

var x float = 1.23e3

Printing Floating Point Numbers

Printing Floating Point Numbers with fmt.Printf()

Complex Numbers

var z complex128 = complex(2, 3)