pl_search_cpp 1.4
Loading...
Searching...
No Matches
pfloat.hpp
Go to the documentation of this file.
1/*
2MIT License
3
4Copyright (c) 2025 [Peter Robinson]
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24
25#ifndef PL_SEARCH_PFLOAT_HPP
26#define PL_SEARCH_PFLOAT_HPP
27
28#include "term.hpp"
29#include "typedefs.hpp"
30
31#include <string>
32#include <typeinfo>
33
39namespace pl_search {
40
47class PFloat : public Term {
48public:
53 PFloat(double value) : value(value) {}
54
55
60 std::string repr() const override { return std::to_string(value); }
61
67 bool isEqualTo(Term &t) const override {
68 PFloat *f = dynamic_cast<PFloat *>(&t);
69 if (f == nullptr)
70 return false;
71 return value == f->value;
72 }
73
79 bool isLessThan(Term &t) const override;
80
85 double getValue() const { return value; }
86
87protected:
88 double value;
89};
90
91} // namespace pl_search
92
93#endif // PL_SEARCH_PFLOAT_HPP
Represents a Prolog float.
Definition pfloat.hpp:47
bool isEqualTo(Term &t) const override
Checks if the term is equal to another term.
Definition pfloat.hpp:67
std::string repr() const override
Returns a string representation of the float.
Definition pfloat.hpp:60
bool isLessThan(Term &t) const override
< operator for a PFloat and a Term
Definition term.cpp:106
double getValue() const
Returns the value of the float.
Definition pfloat.hpp:85
double value
The value of the float.
Definition pfloat.hpp:88
PFloat(double value)
Constructs a PFloat with the given value.
Definition pfloat.hpp:53
Abstract base class for terms that approximate Prolog terms.
Definition term.hpp:50
Definition choice_iterator.hpp:16
Definition of the Term class.
Definition of common typedefs used in the pl_search library.