YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
NetFloat32.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_NETFLOAT32_H
8#define YARP_OS_NETFLOAT32_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 32 bit signed little-endian
17// IEC559/IEEE 754 floating point type.
18//
20
21#if !YARP_FLOAT32_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::NetFloat32")
31#endif
32
33namespace yarp::os {
34
39#ifdef YARP_LITTLE_ENDIAN
40
42
43#else // YARP_LITTLE_ENDIAN
44
47{
49 unsigned char c[4];
50};
52{
53private:
54 double raw_value;
55 double swap(double x) const;
56 RawNetFloat32 get() const;
57 void set(RawNetFloat32 v);
58
59public:
60 NetFloat32();
61 NetFloat32(RawNetFloat32 val);
62 operator RawNetFloat32() const;
63 RawNetFloat32 operator+(RawNetFloat32 v) const;
64 RawNetFloat32 operator-(RawNetFloat32 v) const;
65 RawNetFloat32 operator*(RawNetFloat32 v) const;
66 RawNetFloat32 operator/(RawNetFloat32 v) const;
67 void operator+=(RawNetFloat32 v);
68 void operator-=(RawNetFloat32 v);
69 void operator*=(RawNetFloat32 v);
70 void operator/=(RawNetFloat32 v);
71};
72
73#endif // YARP_LITTLE_ENDIAN
74
75} // namespace yarp::os
76
77#endif // YARP_OS_NETFLOAT32_H
A mini-server for performing network communication in the background.
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, const double &s)
Subtraction operator between a vector and a scalar (defined in Math.h).
Definition math.cpp:98
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/=(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, double k)
Vector-scalar product operator (defined in Math.h).
Definition math.cpp:154
float float32_t
Definition numeric.h:76
An interface to the operating system, including Port based communication.
yarp::conf::float32_t NetFloat32
Definition of the NetFloat32 type.
Definition NetFloat32.h:41
#define YARP_COMPILER_ERROR(x)
Generate an error at build time on supported compilers.
Definition system.h:112
#define YARP_os_API
Definition api.h:18