I'm new to the PowerBASIC world, but (years ago) I used to do some Pascal programming. I'm trying to get back into the swing of things, but stumbling on some of the basic aspects of the language. For example, I'm not having much luck implementing a function like this:
(*-----------------------------------------------------------------------*)
(* ATN2: arctangent of y/x for two arguments *)
(* (correct quadrant; -180 deg <= ATN2 <= +180 deg) *)
(*-----------------------------------------------------------------------*)
FUNCTION ATN2(Y,X:REAL):REAL;
CONST RAD=0.0174532925199433;
VAR AX,AY,PHI: REAL;
BEGIN
IF (X=0.0) AND (Y=0.0)
THEN ATN2:=0.0
ELSE
BEGIN
AX:=ABS(X); AY:=ABS(Y);
IF (AX>AY)
THEN PHI:=ARCTAN(AY/AX)/RAD
ELSE PHI:=90.0-ARCTAN(AX/AY)/RAD;
IF (X<0.0) THEN PHI:=180.0-PHI;
IF (Y<0.0) THEN PHI:=-PHI;
ATN2:=PHI;
END;
END;
Worse, I have some mathematical functions like this that used Assembler (under Virtual Pascal), and I couldn't get those to operate, either.
I think I'm just missing something fundamental in the constructs, but I'd appreciate any pointers.
Best,
Frank
(*-----------------------------------------------------------------------*)
(* ATN2: arctangent of y/x for two arguments *)
(* (correct quadrant; -180 deg <= ATN2 <= +180 deg) *)
(*-----------------------------------------------------------------------*)
FUNCTION ATN2(Y,X:REAL):REAL;
CONST RAD=0.0174532925199433;
VAR AX,AY,PHI: REAL;
BEGIN
IF (X=0.0) AND (Y=0.0)
THEN ATN2:=0.0
ELSE
BEGIN
AX:=ABS(X); AY:=ABS(Y);
IF (AX>AY)
THEN PHI:=ARCTAN(AY/AX)/RAD
ELSE PHI:=90.0-ARCTAN(AX/AY)/RAD;
IF (X<0.0) THEN PHI:=180.0-PHI;
IF (Y<0.0) THEN PHI:=-PHI;
ATN2:=PHI;
END;
END;
Worse, I have some mathematical functions like this that used Assembler (under Virtual Pascal), and I couldn't get those to operate, either.
I think I'm just missing something fundamental in the constructs, but I'd appreciate any pointers.
Best,
Frank
Comment