forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRational.cs
46 lines (40 loc) · 1.02 KB
/
Rational.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MissionPlanner.GeoRef
{
public class Rational
{
uint dem = 0;
uint num = 0;
public Rational(double input)
{
Value = input;
}
public byte[] GetBytes()
{
byte[] answer = new byte[8];
Array.Copy(BitConverter.GetBytes((uint) num), 0, answer, 0, sizeof (uint));
Array.Copy(BitConverter.GetBytes((uint) dem), 0, answer, 4, sizeof (uint));
return answer;
}
public double Value
{
get { return num/dem; }
set
{
if ((value%1.0) != 0)
{
dem = 100;
num = (uint) (value*dem);
}
else
{
dem = 1;
num = (uint) (value);
}
}
}
}
}