第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

學(xué)習(xí)圍棋—范圍

學(xué)習(xí)圍棋—范圍

Go
開滿天機 2021-05-14 18:19:12
嗨,我是Go編程語言的新手。我正在從http://www.golang-book.com/學(xué)習(xí)在第4章的練習(xí)中,有一個關(guān)于從華氏溫度轉(zhuǎn)換為攝氏度的問題。我將答案編碼如下    package mainimport "fmt"func main(){    fmt.Println("Enter temperature in Farentheit ");    var input float64    fmt.Scanf("%f",&input)    var outpu1 float64 = ( ( (input-32)* (5) ) /9)    var outpu2 float64=  (input-32) * (5/9)    var outpu3 float64= (input -32) * 5/9    var outpu4 float64=  ( (input-32) * (5/9) )     fmt.Println("the temperature in Centigrade is ",outpu1)    fmt.Println("the temperature in Centigrade is ",outpu2)    fmt.Println("the temperature in Centigrade is ",outpu3)    fmt.Println("the temperature in Centigrade is ",outpu4) }輸出如下sreeprasad:projectsInGo sreeprasad$ go run convertFarentheitToCentigrade.go Enter temperature in Farentheit 12.234234the temperature in Centigrade is  -10.980981111111111the temperature in Centigrade is  -0the temperature in Centigrade is  -10.980981111111111the temperature in Centigrade is  -0我的問題是關(guān)于outpu2和outpu4。括號是正確的,但是它如何或為什么顯示-0。誰能解釋一下
查看完整描述

2 回答

?
天涯盡頭無女友

TA貢獻1831條經(jīng)驗 獲得超9個贊

很簡單,該表達式(5/9)被評估為(int(5)/int(9))equals 0。嘗試(5./9)

為了弄清楚為什么會發(fā)生這種情況,它處理了確定表達式變量類型的順序。

我猜想b / c的(5/9)存在不考慮input上述情況2和4,編譯器將它們解釋為,int并簡單地將表達式替換為0,這時零被認為取決于輸入,因此float64在最終之前采用類型匯編。

一般來說,Go不會為您轉(zhuǎn)換數(shù)字類型,因此這是唯一對我有意義的解釋。


查看完整回答
反對 回復(fù) 2021-05-24
?
桃花長相依

TA貢獻1860條經(jīng)驗 獲得超8個贊

圍棋語言規(guī)格說明float32float64簽署浮動遵循IEEE-754標準的數(shù)字。以下是引自維基百科的文字-簽名為零

IEEE 754浮點算術(shù)標準(目前大多數(shù)支持浮點數(shù)的計算機和編程語言都在使用)要求+0和?0。零可被視為擴展實數(shù)線的變體,因此1 / ?0 =-∞和1 / + 0 = +∞,僅對±0 /±0和±∞/±∞未定義以零除。

顯然,input當afloat64加上負32時,它變成另一個float64為負數(shù)。5/9評估為0。負數(shù)float64計時0-0。

有趣的是,如果您將input整數(shù)替換為,例如1,則會得到0而不是-0。似乎在Go中,浮點數(shù)同時具有+0-0,而整數(shù)則沒有。

編輯: PhiLho在注釋中解釋了為什么整數(shù)不具有浮點數(shù)的原因:標準化的浮點數(shù)具有+ 0,-0,NaN,+ Infinity和-Infinity的特殊表示形式,而您無法保留一些位組合整數(shù)具有這樣的含義。


查看完整回答
反對 回復(fù) 2021-05-24
  • 2 回答
  • 0 關(guān)注
  • 273 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號