<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # **復數** 和浮點數相似,Go提供了兩種復數類型:`complex64`和`complex128`。第一個使用兩個32位浮點數:一個用于實部,另一個用于復數的虛部,而`complex128`使用兩個64位浮點數。復數以`a + bi`的形式表示,其中 `a`和 `b` 是實數,i 是方程 $x^2 =?1$ 的解。 所有這些數字數據類型都在`numbers.go`中分為三個部分進行說明。 第一部分的代碼如下: ```Go package main import ( "fmt" ) func main() { c1 := 12 + 1i c2 := complex(5, 7) fmt.Printf("Type of c1: %T\n", c1) fmt.Printf("Type of c2: %T\n", c2) var c3 complex64 = complex64(c1 + c2) fmt.Println("c3:", c3) fmt.Printf("Type of c3: %T\n", c3) cZero := c3 - c3 fmt.Println("cZero:", cZero) ``` 這部分使用了一些復數進行計算。有兩種方法去創建復數:與`c1`和`c2`一樣直接創建, 或間接地通過計算現有的復數得到,例如`c3`和`cZero`。 >Tip: 如果你錯誤地嘗試將一個復數創建為 `aComplex:= 12 + 2 * i`,那么將會有兩種可能的結果,因為這個語句告訴Go你想要執行一個加法和一個乘法。如果當前作用域中沒有名為i的數值變量,該語句會出現語法錯誤,你的Go代碼編譯將失敗。但是,如果已經定義了一個名為i的數值變量,那么計算將會成功,但是你將不會得到 需的復數(**bug**)。 第二部分代碼如下: ```Go x := 12 k := 5 fmt.Println(x) fmt.Printf("Type of x: %T\n", x) div := x / k fmt.Println("div", div) ``` 在這一部分中,我們使用帶符號的整數。請注意,如果你想對兩個整數做除法,Go認為你想得到整數答案并將計算返回整數除法的**商**。11除以2得到的是整數5而不是5.5。 >Tip: 當你將浮點數轉換為整數時,浮點數的分數將被丟棄且被截斷為零,這意味著一些數據可能會在處理過程中丟失。 最后一部分代碼: ```GO var m, n float64 m = 1.223 fmt.Println("m, n:", m, n) y := 4 / 2.3 fmt.Println("y:", y) divFloat := float64(x) / float64(k) fmt.Println("divFloat", divFloat) fmt.Printf("Type of divFloat: %T\n", divFloat) } ``` 在程序的最后一部分中,我們將使用浮點數。在做除法時, 你可以看到如何使用```float64()```來告訴Go去創建一個```floating-point number```。如果你只是使用 ```divFloat: = float64 (x) / k```, 然后運行代碼時你會得到以下錯誤消息: ```bash $ go run numbers.go # command-line-arguments ./numbers.go:35:25: invalid operation: float64(x) / k (mismatched types float64 and int) ``` 執行 ```numbers.go```,結果輸出如下: ```bash Type of c1: complex128 Type of c2: complex128 c3: (17+8i) Type of c3: complex64 cZero: (0+0i) 12 Type of x: int div 2 m, n: 1.223 0 y: 1.7391304347826086 divFloat 2.4 Type of divFloat: float64 ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看