1 /*
2  * hunt-proton: AMQP Protocol library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 module hunt.proton.amqp.Decimal32;
13 
14 import hunt.math;
15 import hunt.Number;
16 
17 class Decimal32 : Number
18 {
19     private  BigDecimal _underlying;
20     private  int _bits;
21 
22     this(BigDecimal underlying)
23     {
24         _underlying = underlying;
25         _bits = calculateBits( underlying );
26     }
27 
28     this( int bits)
29     {
30         _bits = bits;
31         _underlying = calculateBigDecimal(bits);
32     }
33 
34     static int calculateBits(BigDecimal underlying)
35     {
36         return 0;  //TODO.
37     }
38 
39     static BigDecimal calculateBigDecimal(int bits)
40     {
41         return BigDecimal.ZERO; // TODO
42     }
43 
44 
45     override
46     public int intValue()
47     {
48         return _underlying.intValue();
49     }
50 
51     override
52     public long longValue()
53     {
54         return _underlying.longValue();
55     }
56 
57     override
58     public float floatValue()
59     {
60         return _underlying.floatValue();
61     }
62 
63     override
64     public double doubleValue()
65     {
66         return _underlying.doubleValue();
67     }
68 
69     public int getBits()
70     {
71         return _bits;
72     }
73 
74    override bool opEquals(Object o)
75     {
76         if (this is o)
77         {
78             return true;
79         }
80         if (o is null || cast(Decimal32)o is null)
81         {
82             return false;
83         }
84 
85         Decimal32 decimal32 =  cast(Decimal32)o;
86 
87         if (_bits != decimal32.getBits())
88         {
89             return false;
90         }
91 
92         return true;
93     }
94 
95 
96     override
97     byte byteValue()
98     {
99         return 1;
100     }
101 
102     override short shortValue()
103     {
104         return 1;
105     }
106 
107     override string toString()
108     {
109         return "";
110     }
111 }