{"id":31,"date":"2007-01-06T23:53:59","date_gmt":"2007-01-06T12:53:59","guid":{"rendered":"http:\/\/new.allocinit.net\/blog\/2007\/01\/06\/floating-point-isnt-base-10-folks-and-thats-not-encryption\/"},"modified":"2023-04-19T21:51:41","modified_gmt":"2023-04-19T10:51:41","slug":"floating-point-isnt-base-10-folks-and-thats-not-encryption","status":"publish","type":"post","link":"https:\/\/www.allocinit.net\/blog\/2007\/01\/06\/floating-point-isnt-base-10-folks-and-thats-not-encryption\/","title":{"rendered":"Floating Point Isn&#8217;t Base-10 Folks and That&#8217;s Not Encryption"},"content":{"rendered":"<p><a href=\"http:\/\/theocacao.com\/\">Scott Stevenson<\/a> recently <a href=\"http:\/\/theocacao.com\/document.page\/383\">talked about Cha-Ching<\/a>. <a href=\"http:\/\/www.midnightapps.com\/chaching\/\">Cha-Ching<\/a> is a &#8220;money manager&#8221;, or so Midnight Apps say. After Scott&#8217;s praise, I thought I&#8217;d take a look to see what all the fuss was about.<\/p>\n<p>Unfortunately, it seems the Midnight Apps crew don&#8217;t quite understand the concept of floating point numbers and how they&#8217;re stored. A floating point number can not accurately store every base 10 number you can write down.<\/p>\n<p>The IEEE 754 floating point standard stores single precision floating point numbers as a sign bit, an 8-bit exponent, and 23-bit mantissa. While I don&#8217;t have the time to explain floating point completely, suffice to say a simple value like $5.10 can&#8217;t be accurately represented with a binary floating point number. There&#8217;s a heap of information about floating point arithmetic in a classic paper <a href=\"http:\/\/docs.sun.com\/source\/806-3568\/ncg_goldberg.html\">What Every Computer Scientist Should Know About Floating-Point Arithmetic<\/a>.<\/p>\n<p>It seems someone brought to the attention of the Midnight Apps team this problem in a <a href=\"http:\/\/www.midnightapps.com\/forum\/viewtopic.php?id=64\">forum thread<\/a> and they now say this is fixed: I&#8217;m betting (and I haven&#8217;t seen a fixed version to be sure) that all they&#8217;ve done is apply a data formatter to that text field. This just masks the problem, the transaction will still it appears be processed as a floating point value, and that&#8217;s not something one does with monetary values.<\/p>\n<p>At this stage this was all I was going to write about Cha-Ching: it seemed to be an interesting application. It was probably not that exciting, but not that terrible, and written by some developers who haven&#8217;t done enough study to understand floating point numbers. Easy enough mistake to make. That was until I discovered&#8230;<\/p>\n<p>The preference option for &#8220;encryption&#8221; of the database that does nothing of the sort. What it actually does is set a preference &#8220;ShouldEncryptDatabase&#8221; in NSUserDefaults and stores the password in the keychain (!!!). The data file is left in clear text in a happy happy XML document. You can edit the password Cha-Ching will require by simply modifying the keychain entry, or remove the need entirely by changing the &#8220;ShouldEncryptDatabase&#8221; flag to no.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scott Stevenson recently talked about Cha-Ching. Cha-Ching is a &#8220;money manager&#8221;, or so Midnight Apps say. After Scott&#8217;s praise, I thought I&#8217;d take a look to see what all the fuss was about. Unfortunately, it seems the Midnight Apps crew don&#8217;t quite understand the concept of floating point numbers and how they&#8217;re stored. A floating [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.allocinit.net\/blog\/wp-json\/wp\/v2\/posts\/31"}],"collection":[{"href":"https:\/\/www.allocinit.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.allocinit.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.allocinit.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.allocinit.net\/blog\/wp-json\/wp\/v2\/comments?post=31"}],"version-history":[{"count":1,"href":"https:\/\/www.allocinit.net\/blog\/wp-json\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":60,"href":"https:\/\/www.allocinit.net\/blog\/wp-json\/wp\/v2\/posts\/31\/revisions\/60"}],"wp:attachment":[{"href":"https:\/\/www.allocinit.net\/blog\/wp-json\/wp\/v2\/media?parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.allocinit.net\/blog\/wp-json\/wp\/v2\/categories?post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.allocinit.net\/blog\/wp-json\/wp\/v2\/tags?post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}