YARP
Yet Another Robot Platform
NetFloat64.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef YARP_OS_NETFLOAT64_H
8 #define YARP_OS_NETFLOAT64_H
9 
10 #include <yarp/conf/numeric.h>
11 
12 #include <yarp/os/api.h>
13 
15 //
16 // The goal of this file is just to define a 64 bit signed little-endian
17 // IEC 559/IEEE 754 floating point type.
18 //
20 
21 #if !YARP_FLOAT64_IS_IEC559
22  // YARP assumes that floating point values are serialized as IEC 559/IEEE 754
23  // floating point types.
24  // If you receive the following error, this means that float and double, on
25  // your platform, are not IEC 559, and therefore some conversion must be
26  // performed whenever reading or writing a floating point value from the
27  // network.
28  // See, for example https://github.com/MalcolmMcLean/ieee754/ for a possible
29  // implementation of the read and write methods.
30  YARP_COMPILER_ERROR("Unsupported compiler. Please implement yarp::os::NetFloat64")
31 #endif
32 
33 namespace yarp {
34 namespace os {
35 
40 #ifdef YARP_LITTLE_ENDIAN
41 
43 
44 #else // YARP_LITTLE_ENDIAN
45 
46 typedef yarp::conf::float64_t RawNetFloat64;
47 union UnionNetFloat64
48 {
50  unsigned char c[8];
51 };
53 {
54 private:
55  double raw_value;
56  double swap(double x) const;
57  RawNetFloat64 get() const;
58  void set(RawNetFloat64 v);
59 
60 public:
61  NetFloat64();
62  NetFloat64(RawNetFloat64 val);
63  operator RawNetFloat64() const;
64  RawNetFloat64 operator+(RawNetFloat64 v) const;
65  RawNetFloat64 operator-(RawNetFloat64 v) const;
66  RawNetFloat64 operator*(RawNetFloat64 v) const;
67  RawNetFloat64 operator/(RawNetFloat64 v) const;
68  void operator+=(RawNetFloat64 v);
69  void operator-=(RawNetFloat64 v);
70  void operator*=(RawNetFloat64 v);
71  void operator/=(RawNetFloat64 v);
72 };
73 
74 #endif // YARP_LITTLE_ENDIAN
75 
76 } // namespace os
77 } // namespace yarp
78 
79 #endif // YARP_OS_NETFLOAT64_H
Vector & operator+=(Vector &a, const double &s)
Addition operator between a scalar and a vector (defined in Math.h).
Definition: math.cpp:38
Vector operator+(const Vector &a, const double &s)
Mathematical operations.
Definition: math.cpp:27
Vector operator-(const Vector &a, const double &s)
Subtraction operator between a vector and a scalar (defined in Math.h).
Definition: math.cpp:82
Vector operator*(double k, const Vector &b)
Scalar-vector product operator (defined in Math.h).
Definition: math.cpp:143
Vector & operator*=(Vector &a, double k)
Vector-scalar product operator (defined in Math.h).
Definition: math.cpp:154
Vector & operator/=(Vector &a, const Vector &b)
Vector-vector element-wise division operator (defined in Math.h).
Definition: math.cpp:266
Vector operator/(const Vector &a, const Vector &b)
Vector-vector element-wise division operator (defined in Math.h).
Definition: math.cpp:260
Vector & operator-=(Vector &a, const double &s)
Subtraction operator between a vector and a scalar (defined in Math.h).
Definition: math.cpp:98
double float64_t
Definition: numeric.h:77
yarp::conf::float64_t NetFloat64
Definition of the NetFloat64 type.
Definition: NetFloat64.h:42
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_COMPILER_ERROR(x)
Generate an error at build time on supported compilers.
Definition: system.h:110
#define YARP_os_API
Definition: api.h:18