Difference between revisions of "FixD"

From SCAR Divi Manual
Jump to: navigation, search
(Created page with "==Definition== <source lang="scar" lines="false"> function FixD(Degrees: Extended): Extended; </source> ===Source=== <source lang="scar"> function FixD(Degrees: Extended): Exten...")
 
 
(3 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
<source lang="scar">
 
<source lang="scar">
 
function FixD(Degrees: Extended): Extended;
 
function FixD(Degrees: Extended): Extended;
 +
var
 +
  t: Integer;
 
begin
 
begin
   Result := Degrees mod 360;
+
  if Degrees < 0 then t := -1 else t := 1;
   if Result < 0 then Inc(Result, 360);
+
   Result := Abs(Degrees);
 +
  Result := (Floor(Result) mod 360 + DecRet(Result)) * t;
 +
   if Result < 0 then Result := Result + 360;
 
end;
 
end;
 
</source>
 
</source>
Line 17: Line 21:
  
 
==Description==
 
==Description==
Fixes an angle specified by '''Degrees''' in [http://en.wikipedia.org/wiki/Degree_%28angle%29 degrees] by adding/subtracting 360 until the value is larger than or equals 0 and is smaller than or equals 360.
+
Fixes an angle specified by '''Degrees''' in [http://en.wikipedia.org/wiki/Degree_%28angle%29 degrees] by adding/subtracting 360 until the value is part of the range [0,360[.
  
 
==Example==
 
==Example==
 
<source lang="scar">
 
<source lang="scar">
 
begin
 
begin
   WriteLn(FixD(25));
+
   WriteLn(FixD(180));
   WriteLn(FixD(385));
+
   WriteLn(FixD(-180));
 +
  WriteLn(FixD(360));
 +
  WriteLn(FixD(540));
 
end.
 
end.
 
</source>
 
</source>
  
 
Output:
 
Output:
  25
+
  180
  25
+
  180
 +
0
 +
180
  
 
==See Also==
 
==See Also==

Latest revision as of 10:29, 1 July 2011

Definition

function FixD(Degrees: Extended): Extended;

Source

function FixD(Degrees: Extended): Extended;
var
  t: Integer;
begin
  if Degrees < 0 then t := -1 else t := 1;
  Result := Abs(Degrees);
  Result := (Floor(Result) mod 360 + DecRet(Result)) * t;
  if Result < 0 then Result := Result + 360;
end;

Availability

SCAR Divi 3.00 > Current

Description

Fixes an angle specified by Degrees in degrees by adding/subtracting 360 until the value is part of the range [0,360[.

Example

begin
  WriteLn(FixD(180));
  WriteLn(FixD(-180));
  WriteLn(FixD(360));
  WriteLn(FixD(540));
end.

Output:

180
180
0
180

See Also