From: Mbaccar AT aol DOT com Message-ID: Date: Sat, 29 May 1999 17:26:54 EDT Subject: Re: how to round fp-numbers correctly ? To: djgpp AT delorie DOT com CC: Mbaccar AT aol DOT com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: AOL 4.0 for Windows sub 11 Reply-To: djgpp AT delorie DOT com > I want to round an fp-number to the nearest representable integer value. > The standard rounding methode simply leaves out the mantisse of an > fp-number (e.g 0.5 is rounded to 0 not to 1). Adding 0.5 only works if > the fp-number is positive, otherwise I have to check if the fp-number is > negative and then would have to substract 0.5. This would waste too much > time. Changing the rounding methode with "_control87(RC_NEAR,MCW_RC);" > didn't work. I don't know why .So what can I do to solve this problem ? > This should not be too difficult because there are a lot of > fp-instructions which "push" and "round" an fp-number. Shall I use the > inline-assembler ? If you know a lower bound for the numbers you are dealing with, I would use: round (fp - min + 0.5) + min where min is the lower bound integer number. You could probably come up with a smilar rule if you had an upper bound. The idea is to always round negative or positive numbers which accounts for the shift. If you don't have bounded numbers, then what you said is right, you need to treat positive and negative numbers separately. -Mohamed