Freelancers Network
 
skill list top cap
Homepage
Join the Freelancer's Network
Update your details
Find a freelancer
Post a project
Find a project
Projects Archive
Post a job
Find a job
Jobs Archive
See Dan's Pages
See Andy's Pages
Link to this site
Resources
Join/Leave Forum
Forum Messages
+Additions+ Adverts
Advertising
Contact Us
Subscribe to our newsletter - enter your email address and hit return
Freelancers.net is owned and operated by Andy Stowell and Dan Winchester
skill list end cap
guru web hostcom

Find me again on Freelancers.net

Re: FN-FORUM: ASP Maths Problem!

date posted 1st February 2008 12:32

On Fri, 2008-02-01 at 12:29 +0000, Dom Latter wrote:
> On Friday 01 February 2008 12:40:26 Rob Colton wrote:
>
> > Not sure I understand, isn't it just
> >
> >
>
> Close enough for jazz, but for an *accurate* result you need to use
> integers only, because (in general) *binary* computers don't store
> *decimal* fractions precisely.
>

If you are worried about rounding errors you probably want to use some
sort of decimal type, if your language supports it (I think ASP does,
though I've never used it). It's more intuitive and in the better
implementations (Ada, Java) you can control how things are rounded
(integer arithmetic rounds down, so 99/100 == 0).

This is a good article on all this:

http://www2.hursley.ibm.com/decimal/IEEE-cowlishaw-arith16.pdf

> Not a real issue in this case, but it can be one of those "gotchas"
> that crops up in other problems, so it's a good idea to get in the
> habit of doing integer arithmetic wherever possible, and simplifying
> the equation to reduce rounding errors


> (and save CPU cycles, cos you should).

> So intTotal * 47/200 will do nicely.
>

This could give you 0 depending on the order of evaluation - whether
your compiler sees this as (intTotal*47)/200 or intTotal*(47/200). The
former is more usual, though. Sometimes using floats and rounding right
at the end is the safest course.

Graham

--
Graham Stark, Virtual Worlds, http://www.virtual-worlds.biz
Phone (+44) 01908 618239 Mobile (+44) 07952633185 Skype graham_k_stark



Messages by Day
February 29th 2008
February 28th 2008
February 27th 2008
February 26th 2008
February 25th 2008
February 24th 2008
February 23rd 2008
February 22nd 2008
February 21st 2008
February 20th 2008
February 19th 2008
February 18th 2008
February 17th 2008
February 16th 2008
February 15th 2008
February 14th 2008
February 13th 2008
February 12th 2008
February 11th 2008
February 10th 2008
February 9th 2008
February 8th 2008
February 7th 2008
February 6th 2008
February 5th 2008
February 4th 2008
February 3rd 2008
February 2nd 2008
February 1st 2008


Messages by Month
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008


Messages by Year
2008
2007
2006
2005
2004
2003
2002
2001
2000