IDL compiler front-end library
Loading...
Searching...
No Matches
Fixed.h
Go to the documentation of this file.
1
2/*
3* Nirvana IDL front-end library.
4*
5* This is a part of the Nirvana project.
6*
7* Author: Igor Popov
8*
9* Copyright (c) 2021 Igor Popov.
10*
11* This program is free software; you can redistribute it and/or modify
12* it under the terms of the GNU Lesser General Public License as published by
13* the Free Software Foundation; either version 3 of the License, or
14* (at your option) any later version.
15*
16* This program is distributed in the hope that it will be useful,
17* but WITHOUT ANY WARRANTY; without even the implied warranty of
18* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19* GNU General Public License for more details.
20*
21* You should have received a copy of the GNU Lesser General Public
22* License along with this library. If not, see <http://www.gnu.org/licenses/>.
23*
24* Send comments and/or bug reports to:
25* popov.nirvana@gmail.com
26*/
27#ifndef IDLFE_AST_FIXED_H_
28#define IDLFE_AST_FIXED_H_
29#pragma once
30
31#include <stdint.h>
32#include <string>
33#include <vector>
34
35#if defined (__clang__)
36#pragma GCC diagnostic push
37#pragma GCC diagnostic ignored "-Wunused-private-field"
38#endif
39
40namespace AST {
41
43class Fixed
44{
45public:
49 uint16_t digits () const noexcept
50 {
51 return (uint16_t)digits_;
52 }
53
59 int16_t scale () const noexcept
60 {
61 return (int16_t)-exponent_;
62 }
63
65 std::string to_string () const;
66
71 std::vector <uint8_t> to_BCD () const;
72
73 Fixed () noexcept
74 {}
75
76 static Fixed normalize (const Fixed& f) noexcept;
77
78private:
81 int32_t digits_;
82 int32_t exponent_;
83 uint8_t bits_;
84 uint8_t lsu_ [31];
85};
86
87}
88
89#if defined (__clang__)
90#pragma GCC diagnostic pop
91#endif
92
93#endif
A fixed point constant.
Definition Fixed.h:44
std::string to_string() const
int16_t scale() const noexcept
Definition Fixed.h:59
uint16_t digits() const noexcept
Definition Fixed.h:49
std::vector< uint8_t > to_BCD() const
Abstract Syntax Tree namespace.
Definition Array.h:34