Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.UUCP Newsgroups: comp.lang.c Subject: Re: MSC 4.0 and Floating Point problem Message-ID: <6425@brl-smoke.ARPA> Date: Sat, 12-Sep-87 17:11:36 EDT Article-I.D.: brl-smok.6425 Posted: Sat Sep 12 17:11:36 1987 Date-Received: Sun, 13-Sep-87 08:50:07 EDT References: <396@devon.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 11 Keywords: Floating In article <396@devon.UUCP> paul@devon.UUCP (Paul Sutcliffe Jr.) writes: >I am having trouble with math accuracy while developing a program Welcome to the wonderful world of floating-point arithmetic! > result = (long)(atof(f) * (double)amount) + atol(a); The problem is that the product is inexact (due to the nature of floating-point), and by casting to (long) you truncate it rather than round it to the nearest integer. If the product is known to be nonnegative, add 0.5 to it before casting.