{"id":13,"date":"2007-07-26T12:42:28","date_gmt":"2007-07-26T19:42:28","guid":{"rendered":"http:\/\/www.elbeno.com\/haskell_soe_blog\/?p=13"},"modified":"2008-01-07T21:48:08","modified_gmt":"2008-01-08T05:48:08","slug":"exercise-41","status":"publish","type":"post","link":"https:\/\/www.elbeno.com\/haskell_soe_blog\/?p=13","title":{"rendered":"Exercise 4.1"},"content":{"rendered":"<pre lang=\"haskell\">inchToPixel :: Float -> Int\r\ninchToPixel x = round (100 * x)\r\n\r\ninchToPixelBad :: Float -> Int\r\ninchToPixelBad x = 100 * round x<\/pre>\n<p>The second definition is bad because rounding a small floating point number leads to a loss of precision in the integer. Better to multiply by 100 first, before rounding. For example, consider:<\/p>\n<pre lang=\"haskell\">inchToPixel 2.5555 = round (100 * 2.5555) = round (255.55) = 256\r\ninchToPixelBad 2.5555 = 100 * round 2.5555 = 100 * 3 = 300<\/pre>\n<p>Quite a difference in the result!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>inchToPixel :: Float -> Int inchToPixel x = round (100 * x) inchToPixelBad :: Float -> Int inchToPixelBad x = 100 * round x The second definition is bad because rounding a small floating point number leads to a loss of precision in the integer. Better to multiply by 100 first, before rounding. For example, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/posts\/13"}],"collection":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13"}],"version-history":[{"count":0,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}