Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!35g2000pry.googlegroups.com!not-for-mail
From: "Felipe G. Nievinski" <fgnievinski@gmail.com>
Newsgroups: comp.soft-sys.matlab,sci.math.num-analysis
Subject: robust truncation at n decimal places
Date: Sat, 6 Dec 2008 19:42:44 -0800 (PST)
Organization: http://groups.google.com
Lines: 16
Message-ID: <545015a5-3f51-41e3-a40b-1cf7db531b11@35g2000pry.googlegroups.com>
NNTP-Posting-Host: 128.138.43.113
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1228621365 20646 127.0.0.1 (7 Dec 2008 03:42:45 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 7 Dec 2008 03:42:45 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: 35g2000pry.googlegroups.com; posting-host=128.138.43.113; 
	posting-account=iCBMwwoAAAARtxHOK9kIhRHsTae4FBZX
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) 
	AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.4.154.29 Safari/525.19,gzip(gfe),gzip(gfe)
Bytes: 1682
Xref: news.mathworks.com comp.soft-sys.matlab:505428 sci.math.num-analysis:105693

Hi. Given
    x = 0.99899998
    y = 0.99900000
    za = sscanf(sprintf('%.7f\n',x), '%f')
    zb = fix(x./10^-7).*10^-7
    za == y
    zb == y
then za == y is true, but zb == y is false.
As you see, it's possible to perform a robust truncation at n decimal
places through conversion to/from character string. I was trying to
achive the same using computationally cheaper double precision
arithmetic, without success. Is that it or am I missing something?

Thanks,
Felipe.