WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
safemath.h
Go to the documentation of this file.
1/******************************************************************************
2* Copyright (c) ATTX LLC 2024. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, LLC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, LLC.
15******************************************************************************/
16/*
17Safe math header file
18---------------------
19This file defines basic functions for safe mathematical operations.
20Rather than raising an error on fail cases (i.e. divide by zero),
21the following libraries are designed to check for errors and return
22corresponding codes.
23
24Author: Alex Reynolds
25*/
26
27#ifndef CORE_SAFEMATH_H
28#define CORE_SAFEMATH_H
29
30#include "types.h"
31
32#define SAFE_MATH_ZERO_TOLERANCE 1e-15
33#define SAFE_MATH_FLOAT_TOLERANCE 1e-6
34
35namespace clockwerk {
36
42 int16 safeDivide(float a, float b, float &result);
43 int16 safeDivide(double a, double b, double &result);
44 int16 safeDivide(int32 a, int32 b, int32 &result);
45 int16 safeDivide(uint64 a, uint64 b, uint64 &result);
46
51 int16 safeSqrt(float input, float &result);
52 int16 safeSqrt(double input, double &result);
53
59 int16 safeNroot(float input, int32 rt, float &result);
60 int16 safeNroot(double input, int32 rt, double &result);
61
66 int16 safeAcos(float input, float &result);
67 int16 safeAcos(double input, double &result);
68
73 int16 safeAsin(float input, float &result);
74 int16 safeAsin(double input, double &result);
75
80 int16 safeTan(float input, float &result);
81 int16 safeTan(double input, double &result);
82
88 bool floatEquals(floating_point a, floating_point b,
89 floating_point tolerance=SAFE_MATH_FLOAT_TOLERANCE);
90
94 int16 sgn(floating_point val);
95}
96
97#endif
Definition CircularBuffer.hpp:28
bool floatEquals(floating_point a, floating_point b, floating_point tolerance)
Compares if two floats are equal within a certain range.
Definition safemath.cpp:155
int16 safeAsin(float input, float &result)
Overloaded functions to perform save sine inverse.
Definition safemath.cpp:126
int16 safeAcos(float input, float &result)
Overloaded functions to perform save cosine inverse.
Definition safemath.cpp:111
int16 safeNroot(float input, int32 rt, float &result)
Overloaded functions to perform safe n root.
Definition safemath.cpp:74
int16 safeTan(float input, float &result)
Overloaded functions to perform safe tangent.
Definition safemath.cpp:141
int16 safeSqrt(float input, float &result)
Overloaded functions to perform safe square root.
Definition safemath.cpp:57
int16 safeDivide(float a, float b, float &result)
Overloaded functions to perform safe division.
Definition safemath.cpp:24
int16 sgn(floating_point val)
Return the sign of the value.
Definition safemath.cpp:164
#define SAFE_MATH_FLOAT_TOLERANCE
Definition safemath.h:33