日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

《Two Dozen Short Lessons in Haskell》(二十)分数

發(fā)布時(shí)間:2023/12/1 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 《Two Dozen Short Lessons in Haskell》(二十)分数 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

《Two Dozen Short Lessons in Haskell》(Copyright ? 1995, 1996, 1997 by Rex Page,有人翻譯為Haskell二十四學(xué)時(shí)教程,該書(shū)如果不用于贏利,可以任意發(fā)布,但需要保留他們的copyright)這本書(shū)是學(xué)習(xí) Haskell的一套練習(xí)冊(cè),共有2本,一本是問(wèn)題,一本是答案,分為24個(gè)章節(jié)。在這個(gè)站點(diǎn)有PDF文件。幾年前剛開(kāi)始學(xué)習(xí)Haskell的時(shí)候,感覺(jué)前幾章還可以看下去,后面的內(nèi)容越來(lái)越難以理解。現(xiàn)在對(duì)函數(shù)式編程有了一些了解后,再來(lái)看這些題,許多內(nèi)容變得簡(jiǎn)單起來(lái)了。

初學(xué)Haskell之前一定要記住:

把你以前學(xué)習(xí)面向過(guò)程的常規(guī)的編程語(yǔ)言,如Pascal、C、Fortran等等統(tǒng)統(tǒng)忘在腦后,函數(shù)式編程完全是不一樣的編程模型,用以前的術(shù)語(yǔ)和思維來(lái)理解函數(shù)式編程里的概念,只會(huì)讓你困惑和迷茫,會(huì)嚴(yán)重地影響你的學(xué)習(xí)進(jìn)度。

這個(gè)學(xué)習(xí)材料內(nèi)容太多,想把整書(shū)全面翻譯下來(lái)非常困難,只有通過(guò)練習(xí)題將一些知識(shí)點(diǎn)串起來(lái),詳細(xì)學(xué)習(xí)Haskell還是先看其它一些入門書(shū)籍吧,這本書(shū)配套著學(xué)學(xué)還是不錯(cuò)的。

第二十章 分?jǐn)?shù)

1 The Haskell class Fractional includes

a? integral, real, and complex numbers

b? numbers between zero and one, but not numbers bigger than one

c? both floating point and rational numbers

d? the Mandelbrot set 指的分形圖形

?

2 The mantissa of a floating point number determines?

a? where the decimal point goes

b? the range of the number and its sign

c? the magnitude and precision of the number

d? the sign of the number and the digits in its decimal numeral

?

3? The exponent of a floating point number determines

a where the decimal point goes

b the range of the number and its sign

c the magnitude and precision of the number

d the sign of the number and the digits in its decimal numeral

?

4? The following denote floating point numbers as the should appear in a Haskell script

a 1.89533e+25, 18.01528974, 1.05522e-24, +27.0

b 1.89533 × 1025, 18.01528974, 1.05522 × 10-24, -27.0

c 1.89533e+25, 18.01528974, 1.05522e-24, -27.0

d all of the above

?

5? Analog to digital conversion converts a number

a? from a set containing a great many numbers to a number from a much smaller set

b? to zero or one

c? to a pattern of zeros and ones

d? by a digital analogy process

?

6? Which of the following formulas would useful for analog to digital conversion?

a? floor((x - a)/dx)

b? floor(n?(x - a)/(b - a))

c? floor . (/ dx) . (+(- a))

d? all of the above

?

7? Numbers of type Rational in Haskell scripts are

a? compatible with floating point numbers in arithmetic operations

b? constructed from two integers by putting a percent-sign between them

c? especially useful when precision is not the most important factor

d? all of the above

=============================

=============================

1 c

書(shū)中答案是a,不知道是怎么回事?

?

2 d

類型Float和Double的數(shù)都包括2個(gè)部分:mantissa小數(shù)部分,exponent指數(shù)部分。

小數(shù)部分決定了該數(shù)的正負(fù)號(hào)和有效數(shù)字個(gè)數(shù)。

關(guān)于詳情可以看看IEEE754浮點(diǎn)數(shù)表示。

?

3 a

指數(shù)部分決定了小數(shù)點(diǎn)的位置。

?

4 c

+27.0是錯(cuò)誤的表示法,不能把加號(hào)放在前面。另外1. 和 .1 也都不是正確的表示法。

?

5 a

模數(shù)轉(zhuǎn)換就是把范圍很大的數(shù)轉(zhuǎn)換到一定范圍內(nèi)的數(shù)。

?

6 d

有點(diǎn)迷惑性,書(shū)中的公式對(duì)應(yīng)著答案a。

答案c是另一種表示法。

答案b是把dx=(b-a)/n代入a中。

?

7 b

Haskell的分?jǐn)?shù)可以用兩個(gè)整數(shù),在中間放一個(gè)百分號(hào)來(lái)表示。例如:3%5,5%3,-232%365

直接在ghci中輸入上面的表達(dá)式會(huì)出現(xiàn)Not in scope: `%'錯(cuò)誤,需要加載Data.Ratio模塊。

:m Data.Ratio

轉(zhuǎn)載于:https://www.cnblogs.com/speeding/archive/2013/05/01/3015218.html

總結(jié)

以上是生活随笔為你收集整理的《Two Dozen Short Lessons in Haskell》(二十)分数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。