File: Fixed.custom

package info (click to toggle)
clutter-sharp 1.0.0~alpha3~git20090817.r1.349dba6-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 4,104 kB
  • ctags: 2,193
  • sloc: xml: 23,456; cs: 9,946; sh: 3,393; perl: 1,213; makefile: 270; awk: 50; sed: 13
file content (112 lines) | stat: -rw-r--r-- 3,319 bytes parent folder | download
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// 
// Fixed.custom
//  
// Author:
//   Aaron Bockover <abockover@novell.com>
// 
// Copyright 2009 Novell, Inc.
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

public static readonly int Bits = 32;
public static readonly int FixedQ = Bits - 16;
public static readonly int MaxValue = 0x7fffffff;
public static readonly int MinValue = unchecked ((int)0x80000000);

public static readonly int Epsilon = 1;
public static readonly int Fixed_1 = (1 << FixedQ);
public static readonly int Fixed_0_5 = 32768;
public static readonly int Fixed_30 = FromInt (30);
public static readonly int Fixed_45 = FromInt (45);
public static readonly int Fixed_60 = FromInt (60);
public static readonly int Fixed_90 = FromInt (90);
public static readonly int Fixed_120 = FromInt (120);
public static readonly int Fixed_180 = FromInt (180);
public static readonly int Fixed_240 = FromInt (240);
public static readonly int Fixed_255 = FromInt (255);
public static readonly int Fixed_270 = FromInt (270);
public static readonly int Fixed_360 = FromInt (360);
public static readonly int Fixed_2_PI = 0x0006487f;
public static readonly int Fixed_PI = 0x0003243f;
public static readonly int Fixed_PI_2 = 0x00019220;
public static readonly int Fixed_PI_4 = 0x0000c910;
public static readonly int RadiansToDegrees = 0x394bb8;

public static int Fraction (int x)
{
    return x & ((1 << FixedQ) - 1);
}

public static int Floor (int x)
{
    return x >= 0
        ? x >> FixedQ
        : ~((~x) >> FixedQ);
}

public static int Ceiling (int x)
{
    return Floor (x) + 0xffff;
}

public static int FromFloat (float val)
{
    return (int)(val * (double)Fixed_1);
}

public static int FromDouble (double val)
{
    return (int)(val * (double)Fixed_1);
}

public static int FromInt (int val)
{
    return val << FixedQ;
}

public static float ToFloat (int fix)
{
    return (float)((int)fix / 65536.0);
}

public static double ToDouble (int fix)
{
    return (double)((int)fix / 65536.0);
}

public static int ToInt (int fix)
{
    return fix >> FixedQ;
}

public static int Mul (int a, int b)
{
    return (int)(((long)a * (long)b) >> FixedQ);
}

public static int Div (int a, int b)
{
    return (int)((((long) a) << FixedQ) / b);
}

public static int MulDiv (int a, int b, int c)
{
    return Div (Mul (a, b), c);
}