BRL-CAD
Loading...
Searching...
No Matches
ulp.h
Go to the documentation of this file.
1/* U L P . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2025 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20
21/** @addtogroup bn_ulp
22 *
23 * @brief Library for performing comparisons and dynamically calculating
24 * floating point limits including the Unit in the Last Place (ULP).
25 *
26 * @{ */
27/** @file ulp.h */
28
29#ifndef BN_ULP_H
30#define BN_ULP_H
31
32#include "common.h"
33#include "bn/defines.h"
34
36
37/** @name Machine epsilons, smallest step after 1.0 @ { */
38BN_EXPORT extern double bn_dbl_epsilon(void);
39BN_EXPORT extern float bn_flt_epsilon(void);
40/** @} */
41
42/** @name Numeric positive normalized range limits @ { */
43BN_EXPORT extern double bn_dbl_min(void);
44BN_EXPORT extern double bn_dbl_max(void);
45BN_EXPORT extern float bn_flt_min(void);
46BN_EXPORT extern float bn_flt_max(void);
47/** @} */
48
49/** @name Square-rooted limits @ { */
50BN_EXPORT extern float bn_flt_min_sqrt(void);
51BN_EXPORT extern float bn_flt_max_sqrt(void);
52BN_EXPORT extern double bn_dbl_min_sqrt(void);
53BN_EXPORT extern double bn_dbl_max_sqrt(void);
54/** @} */
55
56/** @name Next possible value up/down from a given value @ { */
57BN_EXPORT extern double bn_nextafter_up(double val);
58BN_EXPORT extern double bn_nextafter_dn(double val);
59BN_EXPORT extern float bn_nextafterf_up(float val);
60BN_EXPORT extern float bn_nextafterf_dn(float val);
61/** @} */
62
63
64/**
65 * @brief Calculate unit in the last place (ULP) for a given value.
66 *
67 * If provided value is positive, it's the positive distance to the
68 * next double. If provided value is negative, it's the negative
69 * distance to the next negative double.
70 *
71 * @param val the input double value.
72 * @return distance to the next representable double precision value
73 */
74BN_EXPORT extern double bn_ulp(double val);
75
76
77/**
78 * @brief same as bn_ulp() but for single precision floating point.
79 */
80BN_EXPORT extern float bn_ulpf(float val);
81
82
84
85#endif /* BN_ULP_H */
86
87/** @} */
88
89/*
90 * Local Variables:
91 * mode: C
92 * indent-tabs-mode: t
93 * c-file-style: "stroustrup"
94 * End:
95 * ex: shiftwidth=4 tabstop=8
96 */
97
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
double bn_dbl_epsilon(void)
float bn_flt_min_sqrt(void)
float bn_flt_epsilon(void)
double bn_nextafter_up(double val)
float bn_flt_max(void)
float bn_flt_min(void)
double bn_ulp(double val)
Calculate unit in the last place (ULP) for a given value.
double bn_dbl_min(void)
double bn_nextafter_dn(double val)
double bn_dbl_max(void)
float bn_ulpf(float val)
same as bn_ulp() but for single precision floating point.
float bn_nextafterf_up(float val)
float bn_nextafterf_dn(float val)
double bn_dbl_min_sqrt(void)
float bn_flt_max_sqrt(void)
double bn_dbl_max_sqrt(void)