《Two Dozen Short Lessons in Haskell》(二十)分数
《Two Dozen Short Lessons in Haskell》(Copyright ? 1995, 1996, 1997 by Rex Page,有人翻譯為Haskell二十四學(xué)時(shí)教程,該書如果不用于贏利,可以任意發(fā)布,但需要保留他們的copyright)這本書是學(xué)習(xí) Haskell的一套練習(xí)冊(cè),共有2本,一本是問題,一本是答案,分為24個(gè)章節(jié)。在這個(gè)站點(diǎn)有PDF文件。幾年前剛開始學(xué)習(xí)Haskell的時(shí)候,感覺前幾章還可以看下去,后面的內(nèi)容越來越難以理解。現(xiàn)在對(duì)函數(shù)式編程有了一些了解后,再來看這些題,許多內(nèi)容變得簡(jiǎn)單起來了。
初學(xué)Haskell之前一定要記住:
把你以前學(xué)習(xí)面向過程的常規(guī)的編程語言,如Pascal、C、Fortran等等統(tǒng)統(tǒng)忘在腦后,函數(shù)式編程完全是不一樣的編程模型,用以前的術(shù)語和思維來理解函數(shù)式編程里的概念,只會(huì)讓你困惑和迷茫,會(huì)嚴(yán)重地影響你的學(xué)習(xí)進(jìn)度。
這個(gè)學(xué)習(xí)材料內(nèi)容太多,想把整書全面翻譯下來非常困難,只有通過練習(xí)題將一些知識(shí)點(diǎn)串起來,詳細(xì)學(xué)習(xí)Haskell還是先看其它一些入門書籍吧,這本書配套著學(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
書中答案是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)迷惑性,書中的公式對(duì)應(yīng)著答案a。
答案c是另一種表示法。
答案b是把dx=(b-a)/n代入a中。
?
7 b
Haskell的分?jǐn)?shù)可以用兩個(gè)整數(shù),在中間放一個(gè)百分號(hào)來表示。例如: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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 闲鱼语音听不见怎么办
- 下一篇: 原神精锻用魔矿怎么获得