YARP
Yet Another Robot Platform
NetFloat32.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_NETFLOAT32_H
11 #define YARP_OS_NETFLOAT32_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 32 bit signed little-endian
20 // IEC559/IEEE 754 floating point type.
21 //
23 
24 #if !YARP_FLOAT32_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::NetFloat32")
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::float32_t RawNetFloat32;
50 union UnionNetFloat32
51 {
53  unsigned char c[4];
54 };
56 {
57 private:
58  double raw_value;
59  double swap(double x) const;
60  RawNetFloat32 get() const;
61  void set(RawNetFloat32 v);
62 
63 public:
64  NetFloat32();
65  NetFloat32(RawNetFloat32 val);
66  operator RawNetFloat32() const;
67  RawNetFloat32 operator+(RawNetFloat32 v) const;
68  RawNetFloat32 operator-(RawNetFloat32 v) const;
69  RawNetFloat32 operator*(RawNetFloat32 v) const;
70  RawNetFloat32 operator/(RawNetFloat32 v) const;
71  void operator+=(RawNetFloat32 v);
72  void operator-=(RawNetFloat32 v);
73  void operator*=(RawNetFloat32 v);
74  void operator/=(RawNetFloat32 v);
75 };
76 
77 #endif // YARP_LITTLE_ENDIAN
78 
79 } // namespace os
80 } // namespace yarp
81 
82 #endif // YARP_OS_NETFLOAT32_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
yarp::os::NetFloat32
yarp::conf::float32_t NetFloat32
Definition of the NetFloat32 type.
Definition: NetFloat32.h:45
yarp::conf::float32_t
float float32_t
Definition: numeric.h:50
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