souffle  2.0.2-371-g6315b36
FloatConstant.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file FloatConstant.h
12  *
13  * Defines a class for evaluating values in the Relational Algebra Machine
14  *
15  ************************************************************************/
16 
17 #pragma once
18 
19 #include "ram/Constant.h"
20 #include "souffle/RamTypes.h"
21 #include <ostream>
22 
23 namespace souffle::ram {
24 
25 /**
26  * @class FloatConstant
27  * @brief Represents a float constant
28  *
29  * For example:
30  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
31  * float(3.3)
32  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
33  */
34 class FloatConstant : public Constant {
35 public:
36  explicit FloatConstant(RamFloat val) : Constant(ramBitCast(val)) {}
37 
38  /** @brief Get value of the constant. */
39  RamFloat getValue() const {
40  return ramBitCast<RamFloat>(constant);
41  }
42 
43  /** Create clone */
44  FloatConstant* clone() const override {
45  return new FloatConstant(getValue());
46  }
47 
48 protected:
49  void print(std::ostream& os) const override {
50  os << "float(" << getValue() << ")";
51  }
52 };
53 
54 } // namespace souffle::ram
Constant.h
souffle::ram::FloatConstant::FloatConstant
FloatConstant(RamFloat val)
Definition: FloatConstant.h:42
souffle::ram::Constant::Constant
Constant(RamDomain constant)
Definition: Constant.h:44
souffle::RamFloat
float RamFloat
Definition: RamTypes.h:60
souffle::ram::FloatConstant
Represents a float constant.
Definition: FloatConstant.h:40
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::Constant::constant
const RamDomain constant
Constant value.
Definition: Constant.h:52
souffle::ram::FloatConstant::print
void print(std::ostream &os) const override
Print RAM node.
Definition: FloatConstant.h:55
souffle::ram::FloatConstant::getValue
RamFloat getValue() const
Get value of the constant.
Definition: FloatConstant.h:45
RamTypes.h
souffle::ramBitCast
To ramBitCast(From source)
In C++20 there will be a new way to cast between types by reinterpreting bits (std::bit_cast),...
Definition: RamTypes.h:87
souffle::ram::FloatConstant::clone
FloatConstant * clone() const override
Create clone.
Definition: FloatConstant.h:50