libUTL++
Float.h
1 #pragma once
2 
4 
5 #include <math.h>
6 #include <libutl/Number.h>
7 
9 
10 UTL_NS_BEGIN;
11 
13 
21 
23 class Float : public Number<double>
24 {
27 
28 public:
33  Float(double f);
34 
39  Float(const String& str)
40  {
41  set(str);
42  }
43 
44  virtual int compare(const Object& rhs) const;
45 
46  virtual void serialize(Stream& stream, uint_t io, uint_t mode = ser_default);
47 
48  virtual String toString() const;
49 
50  virtual String
51  toString(const char* fmt)
52  {
53  return super::toString(fmt);
54  }
55 
61  String toString(uint_t digits) const;
62 
63  void
64  set(double n)
65  {
66  super::set(n);
67  }
68 
69  virtual Number<double>& set(const String& str);
70 
72  bool
73  isInt() const
74  {
75  return (_n == floor(_n));
76  }
77 
79  Float
80  abs() const
81  {
82  return Float(fabs(_n));
83  }
84 
86  Float mod(const Float& rhs) const;
87 };
88 
90 
91 UTL_NS_END;
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
Definition: macros.h:532
String toString(const FwdIt &begin, const FwdIt &end, const String &sep, bool key=false)
Obtain a string representation of a sequence (via Object::toString()).
void serialize(bool &b, Stream &stream, uint_t io, uint_t mode=ser_default)
Serialize a boolean.
default representation (via getSerializeMode())
Definition: util.h:75
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
Numeric value.
Definition: Number.h:23
Character string.
Definition: String.h:31
Float abs() const
Get the absolute value of self.
Definition: Float.h:80
Floating point number.
Definition: Float.h:23
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
Stream I/O abstraction.
Definition: Stream.h:68
bool isInt() const
Determine whether the number is an integer (has no fractional component).
Definition: Float.h:73
Root of UTL++ class hierarchy.
Definition: Object.h:52
int compare(bool lhs, bool rhs)
Compare two boolean values.
Float(const String &str)
Constructor.
Definition: Float.h:39