Solved

Strange calculation result in CLIPPER 5

Posted on 1998-10-15
2
247 Views
Last Modified: 2010-04-26
I am using CLIPPER version 5. The following comparasion never equal on a specific condition.

IF Tot1+Tot2+Tot3+Tot4+Tot5 = User_Fonc()
   Process....
 
User_Fonc is a function who add number inputed from the screen, the result is return  at end of the function
RETURN Result     (Numeric value 9999.99)

The problem is if all Tot... = 200.00

and the result of the function were 5 input of 33.33 plus
a last input of 33.35  (total should be 200.00)

The IF condition never satisfied because the function does not give the same answer as the addition of Tot...

Using debug the sum of the Tot.. field = 200.00 and the number out of the function is 200.00.

Why CLIPPER 5 find the two number not equal?

It is working find for any other combinasion of number.
(use 5 X  33.34 and 1 X 33.30 it will work)

Thanks
PS: Old language but this bug just came out recently.

Jacques Theroux
0
Comment
Question by:theroux
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
mark2150 earned 200 total points
ID: 1011497
You should *NEVER* test for equality with REAL #'s. There is almost always "roundoff lint" that you don't see. If your value is, say, 33.33000000000001 and your format mask is ##.## then it will display as 33.33 but is *NOT* internally.

This is *NOT* "bug". Make sure your values really end at two places like:

X = INT( X * 100 ) /100

Either that or range your test:

sum = (Tot1+Tot2+Tot3+Tot4+Tot5)

if (sum > 200.00) and (sum < 200.01) then...

Either method will work.

M

0
 

Author Comment

by:theroux
ID: 1011498
I note MARK2150 average and give 150 point because he made the effort to response to this question but  the answer was not realy good. I try the same situation using NATURAL CICS, COBOL MVS, ASSEMBLER and the result was find every time.  I did not try FORTRAN, FOCUS, BASIC/VISUAL BASIC, I did not have time to try those language.

I used the get around to bypass the bug  but MARK 2150 had a mistake on his IF statement, it should read ">=". MARK2150 should not make affirmation like  he did with NEVER all over the answer. I was more interested to find if a new version of CLIPPER is out and may be solved the problem.

Thanks
Jacques Théroux
     
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
BIOS update failed, laptop dead. Any options to revive the system? 19 187
Dell Power edge R310 10 73
Laptop models need quick answer 24 38
Repair SAS HDD 5 68
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question