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