Post Reply 
What is wrong with my code?
01-21-2021, 08:27 PM (This post was last modified: 01-21-2021 08:39 PM by C.Ret.)
Post: #4
RE: What is wrong with my code?
Hello,

Please excuse my dummy question : What is the purpose of this section ?
Code:
IF 0 THEN BREAK;
END;


P.S.: Running the numeric example {1, 2 , 3 4 for respectively a,b,c and d) directly from 'HOME' command line I got the expected 2*√2 exact response.

By running the original code, I get the same "ungainly" 665857/235416 ratio than rawi.

Apparently, the small roundoff error due to storing the value in the r variable makes the EXACT function not to 'detect' the square root.

Here is how I modified the initial code to get the expected exact result:

Code:
EXPORT DBTP()
BEGIN
LOCAL a:=0,b:=0,c:=0,d:=0;
PRINT();
IF INPUT({{a,[0],{10,20,1}},{b,[0],{40,20,1}},{c,[0],{10,20,2}},{d,[0],{40,20,2}}},
            "Distance between 2 Points",
            {"X₁:","Y₁:","X₂:","Y₂:"},
            {"Input a value for X₁ (Real number).","Input a value for Y₁ (Real number).","Input a value for X₂ (Real number).","Input a value for Y₂ (Real number)."})
   ==0 THEN BREAK; END;

LOCAL r:=exact(√((c-a)^2+(d-b)^2));

PRINT("
  Distance between points:
  "+r+"");
END;

The test catch any zero value produce when INPUT is cancel by the user.

Since the variable r is most symbolic than a number, I don't initalize it to a real value, nor I store any real value in it making the EXACT function "ungainly".


Hope this help a few ...
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
What is wrong with my code? - Spybot - 01-20-2021, 09:05 PM
RE: What is wrong with my code? - rawi - 01-21-2021, 05:13 AM
RE: What is wrong with my code? - C.Ret - 01-21-2021 08:27 PM
RE: What is wrong with my code? - Spybot - 01-23-2021, 01:25 AM
RE: What is wrong with my code? - C.Ret - 01-23-2021, 07:56 PM
RE: What is wrong with my code? - Han - 01-24-2021, 03:31 AM
RE: What is wrong with my code? - Spybot - 01-24-2021, 03:40 PM



User(s) browsing this thread: 2 Guest(s)