-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixed.cs
More file actions
36 lines (33 loc) · 1.06 KB
/
Fixed.cs
File metadata and controls
36 lines (33 loc) · 1.06 KB
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
using System;
using System.Globalization;
using System.Windows.Controls;
namespace VisiMatrix
{
public static class Fixed
{
public static Single Float(UInt32 data, int floatingBits)
{
var multiplier = 1 << floatingBits;
var value = ((Single) (data & (multiplier - 1)))/multiplier;
var intBits = (int)data >> floatingBits;
if ((intBits & (multiplier >> 1)) > 0)//means that intBits < 0
{
intBits |= ~ (multiplier - 1);
}
return value + intBits;
}
public static UInt32 Int(Single data, int floatingBits)
{
var high = ((uint) data) << floatingBits;
var low = (uint) ((data - (int) data)*(1 << floatingBits));
return high | low;
}
public static double Parse(TextBox box)
{
Double x;
return Double.TryParse(box.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out x)
? x
: Double.Parse(box.Text);
}
}
}