# 《Two Dozen Short Lessons in Haskell》（二十）分数

《Two Dozen Short Lessons in Haskell》（Copyright © 1995, 1996, 1997 by Rex Page，有人翻译为Haskell二十四学时教程，该书如果不用于赢利，可以任意发布，但需要保留他们的copyright）这本书是学习 Haskell的一套练习册，共有2本，一本是问题，一本是答案，分为24个章节。在这个站点有PDF文件。几年前刚开始学习Haskell的时候，感觉前几章还可以看下去，后面的内容越来越难以理解。现在对函数式编程有了一些了解后，再来看这些题，许多内容变得简单起来了。

### 第二十章 分数

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

2 d

3 a

4 c

+27.0是错误的表示法，不能把加号放在前面。另外1. 和 .1 也都不是正确的表示法。

5 a

6 d

7 b

Haskell的分数可以用两个整数，在中间放一个百分号来表示。例如：3%5，5%3，-232%365

:m Data.Ratio

posted @ 2013-05-01 10:08  申龙斌的程序人生  阅读(722)  评论(0编辑  收藏  举报