Graphviz 12.0.1~dev.20240715.2254
Loading...
Searching...
No Matches
gv_math.h File Reference

Arithmetic helper functions. More...

#include <assert.h>
#include <limits.h>
#include <stdbool.h>
#include <string.h>
Include dependency graph for gv_math.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static int fcmp (double a, double b)
 comparator for doubles
 
static int imax (int a, int b)
 maximum of two integers
 
static int imin (int a, int b)
 minimum of two integers
 
static bool is_exactly_equal (double a, double b)
 are two values precisely the same?
 
static bool is_exactly_zero (double v)
 is a value precisely 0.0?
 
static int scale_clamp (int original, double scale)
 scale up or down a non-negative integer, clamping to [0, INT_MAX]
 

Function Documentation

◆ fcmp()

static int fcmp ( double  a,
double  b 
)
inlinestatic

Definition at line 13 of file gv_math.h.

Referenced by countHorzCross(), and countVertCross().

Here is the caller graph for this function:

◆ imax()

static int imax ( int  a,
int  b 
)
inlinestatic

Definition at line 24 of file gv_math.h.

Referenced by agerr_va().

Here is the caller graph for this function:

◆ imin()

static int imin ( int  a,
int  b 
)
inlinestatic

Definition at line 27 of file gv_math.h.

Referenced by common_init_node(), dfs(), dfs(), make_map_internal(), node_distinct_coloring_internal2(), QuadTree_get_nearest(), QuadTree_get_nearest_internal(), and sfprint().

Here is the caller graph for this function:

◆ is_exactly_equal()

static bool is_exactly_equal ( double  a,
double  b 
)
inlinestatic

This function should only be used when you know you want comparison with no tolerance, which is rare. Floating-point arithmetic accumulates imprecision, so equality comparisons should generally include a non-zero tolerance to account for this. In general, this function is only applicable for checking things like “is this variable unchanged since a previous assignment from a literal?”

Parameters
aFirst operand to comparison
bSecond operand to comparison
Returns
True if the values are equal

Definition at line 43 of file gv_math.h.

Referenced by is_exactly_zero(), is_set(), point_init(), poly_init(), rgb2hsv(), and routesplines_().

Here is the caller graph for this function:

◆ is_exactly_zero()

static bool is_exactly_zero ( double  v)
inlinestatic

This function should only be used when you know you want comparison with no tolerance, which is rare. Floating-point arithmetic accumulates imprecision, so equality comparisons should generally include a non-zero tolerance to account for this. Valid double representations even include -0.0, for which this function will return false. In general, this function is only applicable for checking things like “is this variable unchanged since a previous assignment from the literal 0?” or “did this value we parsed from user input originate from the string "0.0"?”

Parameters
vValue to check
Returns
True if the value is equal to exactly 0.0

Definition at line 62 of file gv_math.h.

References is_exactly_equal().

Referenced by dotneato_args_initialize(), emit_begin_node(), get_inputscale(), isBox(), isRect(), poly_init(), and poly_inside().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scale_clamp()

static int scale_clamp ( int  original,
double  scale 
)
inlinestatic
Parameters
originalValue to scale
scaleScale factor to apply
Returns
Clamped result

Definition at line 71 of file gv_math.h.

References scale().

Referenced by dot2_rank(), nsiter2(), and rank1().

Here is the call graph for this function:
Here is the caller graph for this function: