Geant4-11
Macros | Typedefs | Enumerations | Functions
nf_utilities.h File Reference
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdarg.h>

Go to the source code of this file.

Macros

#define nf_floatToShortestString_includeSign   ( 1 << 2 )
 
#define nf_floatToShortestString_keepPeriod   ( 1 << 1 )
 
#define nf_floatToShortestString_trimZeros   ( 1 << 0 )
 
#define NUMERICALFUNCTIONS_SVN_VERSION   110+
 

Typedefs

typedef enum nfu_status_e nfu_status
 

Enumerations

enum  nfu_status_e {
  nfu_Okay , nfu_mallocError , nfu_insufficientMemory , nfu_badIndex ,
  nfu_XNotAscending , nfu_badIndexForX , nfu_XOutsideDomain , nfu_invalidInterpolation ,
  nfu_badSelf , nfu_divByZero , nfu_unsupportedInterpolationConversion , nfu_unsupportedInterpolation ,
  nfu_empty , nfu_tooFewPoints , nfu_domainsNotMutual , nfu_badInput ,
  nfu_badNorm , nfu_badIntegrationInput , nfu_otherInterpolation , nfu_failedToConverge ,
  nfu_oddNumberOfValues
}
 

Functions

char * nf_floatToShortestString (double value, int significantDigits, int favorEFormBy, int flags)
 
void * nfu_calloc (size_t size, size_t n)
 
void * nfu_free (void *p)
 
double nfu_getInfinity (double sign)
 
double nfu_getNAN (void)
 
int nfu_isNAN (double d)
 
void * nfu_malloc (size_t size)
 
void nfu_printErrorMsg (char *fmt,...)
 
void nfu_printMsg (char *fmt,...)
 
void * nfu_realloc (size_t size, void *old)
 
void nfu_setMemoryDebugMode (int mode)
 
const char * nfu_statusMessage (nfu_status status)
 
nfu_status nfu_stringToListOfDoubles (char const *str, int64_t *numberConverted, double **doublePtr, char **endCharacter)
 

Macro Definition Documentation

◆ nf_floatToShortestString_includeSign

#define nf_floatToShortestString_includeSign   ( 1 << 2 )

Definition at line 18 of file nf_utilities.h.

◆ nf_floatToShortestString_keepPeriod

#define nf_floatToShortestString_keepPeriod   ( 1 << 1 )

Definition at line 17 of file nf_utilities.h.

◆ nf_floatToShortestString_trimZeros

#define nf_floatToShortestString_trimZeros   ( 1 << 0 )

Definition at line 16 of file nf_utilities.h.

◆ NUMERICALFUNCTIONS_SVN_VERSION

#define NUMERICALFUNCTIONS_SVN_VERSION   110+

Definition at line 14 of file nf_utilities.h.

Typedef Documentation

◆ nfu_status

typedef enum nfu_status_e nfu_status

Enumeration Type Documentation

◆ nfu_status_e

Enumerator
nfu_Okay 
nfu_mallocError 
nfu_insufficientMemory 
nfu_badIndex 
nfu_XNotAscending 
nfu_badIndexForX 
nfu_XOutsideDomain 
nfu_invalidInterpolation 
nfu_badSelf 
nfu_divByZero 
nfu_unsupportedInterpolationConversion 
nfu_unsupportedInterpolation 
nfu_empty 
nfu_tooFewPoints 
nfu_domainsNotMutual 
nfu_badInput 
nfu_badNorm 
nfu_badIntegrationInput 
nfu_otherInterpolation 
nfu_failedToConverge 
nfu_oddNumberOfValues 

Definition at line 25 of file nf_utilities.h.

@ nfu_unsupportedInterpolation
Definition: nf_utilities.h:28
@ nfu_domainsNotMutual
Definition: nf_utilities.h:28
@ nfu_XNotAscending
Definition: nf_utilities.h:26
@ nfu_invalidInterpolation
Definition: nf_utilities.h:27
@ nfu_Okay
Definition: nf_utilities.h:25
@ nfu_badSelf
Definition: nf_utilities.h:27
@ nfu_oddNumberOfValues
Definition: nf_utilities.h:30
@ nfu_mallocError
Definition: nf_utilities.h:25
@ nfu_insufficientMemory
Definition: nf_utilities.h:25
@ nfu_badNorm
Definition: nf_utilities.h:29
@ nfu_badIntegrationInput
Definition: nf_utilities.h:29
@ nfu_XOutsideDomain
Definition: nf_utilities.h:26
@ nfu_badIndex
Definition: nf_utilities.h:26
@ nfu_failedToConverge
Definition: nf_utilities.h:30
@ nfu_tooFewPoints
Definition: nf_utilities.h:28
@ nfu_unsupportedInterpolationConversion
Definition: nf_utilities.h:27
@ nfu_badInput
Definition: nf_utilities.h:29
@ nfu_badIndexForX
Definition: nf_utilities.h:26
@ nfu_empty
Definition: nf_utilities.h:28
@ nfu_divByZero
Definition: nf_utilities.h:27
@ nfu_otherInterpolation
Definition: nf_utilities.h:29
enum nfu_status_e nfu_status

Function Documentation

◆ nf_floatToShortestString()

char * nf_floatToShortestString ( double  value,
int  significantDigits,
int  favorEFormBy,
int  flags 
)

Definition at line 66 of file nf_stringToDoubles.cc.

66 {
67
68 int n1, ne, nf, digitsRightOfPeriod_f, exponent;
69 char Str_e[512], Str_f[512], *Str_r = Str_e, Fmt[32], *e1, *e2;
70 const char *sign = "";
71
73
74 if( !isfinite( value ) ) {
75 sprintf( Fmt, "%%%sf", sign );
76 sprintf( Str_e, Fmt, value );
77 return( strdup( Str_e ) );
78 }
79
80 significantDigits--;
81 if( significantDigits < 0 ) significantDigits = 0;
82 if( significantDigits > 24 ) significantDigits = 24;
83
84 sprintf( Fmt, "%%%s.%de", sign, significantDigits );
85 sprintf( Str_e, Fmt, value );
86
87 e1 = strchr( Str_e, 'e' );
88 if( significantDigits == 0 ) {
89 if( *(e1 - 1) != '.' ) {
90 char *e3;
91
92 e2 = strchr( e1, 0 );
93 e3 = e2 + 1;
94 for( ; e2 != e1; e2--, e3-- ) *e3 = *e2;
95 *(e1++) = '.';
96 }
97 }
98 *e1 = 0;
99 n1 = (int) strlen( Str_e ) - 1;
100 if( flags & nf_floatToShortestString_trimZeros ) while( Str_e[n1] == '0' ) n1--; // Loop checking, 11.06.2015, T. Koi
102 if( !( flags & nf_floatToShortestString_keepPeriod ) ) if( Str_e[n1] == '.' ) n1--;
103 n1++;
104 Str_e[n1] = 0;
105
106 e1++;
107 exponent = (int) strtol( e1, &e2, 10 );
108 if( exponent != 0 ) { /* If 0, the exponent was "e+00". */
109 for( e1 = Str_e; *e1 != 0; e1++ ) ;
110 sprintf( e1, "e%d", exponent );
111
112 digitsRightOfPeriod_f = significantDigits - exponent;
113 if( ( digitsRightOfPeriod_f > 25 ) || ( exponent > 50 ) ) return( strdup( Str_r ) );
114 if( digitsRightOfPeriod_f < 0 ) digitsRightOfPeriod_f = 0;
115
116 sprintf( Fmt, "%%%s.%df", sign, digitsRightOfPeriod_f );
117 sprintf( Str_f, Fmt, value );
118
119 ne = (int) strlen( Str_e );
120 nf = (int) strlen( Str_f );
121 if( strchr( Str_f, '.' ) != NULL ) { /* '.' in string. */
122 if( flags & nf_floatToShortestString_trimZeros ) while( Str_f[nf-1] == '0' ) nf--; // Loop checking, 11.06.2015, T. Koi
123 if( Str_f[nf-1] == '.' ) {
124 if( !( flags & nf_floatToShortestString_keepPeriod ) ) nf--;
125 } }
126 else { /* Maybe we want a '.' else it looks like an integer, "12345." vs "12345". */
128 Str_f[nf] = '.';
129 nf++;
130 }
131 }
132 Str_f[nf] = 0;
133
134 if( ( nf + favorEFormBy ) < ne ) Str_r = Str_f;
135 }
136 return( strdup( Str_r ) );
137}
static const G4double e1[44]
static const G4double e2[44]
static const G4double e3[45]
G4int sign(const T t)
#define isfinite
#define nf_floatToShortestString_includeSign
Definition: nf_utilities.h:18
#define nf_floatToShortestString_trimZeros
Definition: nf_utilities.h:16
#define nf_floatToShortestString_keepPeriod
Definition: nf_utilities.h:17

References e1, e2, e3, isfinite, nf_floatToShortestString_includeSign, nf_floatToShortestString_keepPeriod, nf_floatToShortestString_trimZeros, and G4INCL::Math::sign().

◆ nfu_calloc()

void * nfu_calloc ( size_t  size,
size_t  n 
)

Definition at line 123 of file nf_utilities.cc.

123 {
124
125 void *p = calloc( size, n );
126
127 if( nfu_debugging ) printf( "nfu_calloc %12p size = %8llu, n = %8llu\n", p, (long long unsigned) size, (long long unsigned) n );
128 return( p );
129}
static int nfu_debugging
Definition: nf_utilities.cc:49

References CLHEP::detail::n, and nfu_debugging.

Referenced by ptwX_new(), ptwXY_new(), and ptwXY_thin().

◆ nfu_free()

void * nfu_free ( void *  p)

Definition at line 143 of file nf_utilities.cc.

143 {
144
145 if( p != NULL ) {
146 if( nfu_debugging ) printf( "nfu_free %12p\n", p );
147 free( p );
148 }
149 return( NULL );
150}

References free, and nfu_debugging.

Referenced by nf_Legendre_free(), nf_Legendre_new(), nf_Legendre_release(), ptwX_free(), ptwX_fromString(), ptwX_new(), ptwX_release(), ptwXY_cloneToInterpolation(), ptwXY_copy(), ptwXY_free(), ptwXY_fromString(), ptwXY_mergeFrom(), ptwXY_mergeFromXYs(), ptwXY_new(), ptwXY_release(), and ptwXY_thin().

◆ nfu_getInfinity()

double nfu_getInfinity ( double  sign)

Definition at line 68 of file nf_utilities.cc.

68 {
69
70 if( sign < 0 ) return( -INFINITY );
71 return( INFINITY );
72}

References G4INCL::Math::sign().

◆ nfu_getNAN()

double nfu_getNAN ( void  )

Definition at line 54 of file nf_utilities.cc.

54 {
55
56 return( NAN );
57}

Referenced by ptwXY_div_ptwXY(), ptwXY_getXMaxAndFrom(), and ptwXY_getXMinAndFrom().

◆ nfu_isNAN()

int nfu_isNAN ( double  d)

Definition at line 61 of file nf_utilities.cc.

61 {
62
63 return( is_nan( d ) );
64}
#define is_nan(a)
Definition: nf_utilities.cc:18

References is_nan.

Referenced by ptwXY_div_ptwXY().

◆ nfu_malloc()

void * nfu_malloc ( size_t  size)

Definition at line 113 of file nf_utilities.cc.

113 {
114
115 void *p = malloc( size );
116
117 if( nfu_debugging ) printf( "nfu_malloc %12p size = %8llu\n", p, (long long unsigned) size );
118 return( p );
119}

References nfu_debugging.

Referenced by nf_Legendre_new(), nfu_stringToListOfDoubles2(), ptwXY_mergeFrom(), and ptwXY_mergeFromXYs().

◆ nfu_printErrorMsg()

void nfu_printErrorMsg ( char *  fmt,
  ... 
)

Definition at line 166 of file nf_utilities.cc.

166 {
167
168 va_list args;
169
170 va_start( args, fmt );
171 vfprintf( stderr, fmt, args );
172 fprintf( stderr, "\n" );
173 va_end( args );
174
175 exit( EXIT_FAILURE );
176}
static char ** args
Definition: G4Xt.cc:51
def exit()
Definition: g4zmq.py:99

References args, and g4zmq::exit().

◆ nfu_printMsg()

void nfu_printMsg ( char *  fmt,
  ... 
)

Definition at line 154 of file nf_utilities.cc.

154 {
155
156 va_list args;
157
158 va_start( args, fmt );
159 vfprintf( stderr, fmt, args );
160 fprintf( stderr, "\n" );
161 va_end( args );
162}

References args.

◆ nfu_realloc()

void * nfu_realloc ( size_t  size,
void *  old 
)

Definition at line 133 of file nf_utilities.cc.

133 {
134
135 void *p = realloc( old, size );
136
137 if( nfu_debugging ) printf( "nfu_realloc %12p size = %8llu, old = %12p\n", p, (long long unsigned) size, old );
138 return( p );
139}

References nfu_debugging.

Referenced by nf_Legendre_reallocateCls(), ptwX_reallocatePoints(), ptwXY_reallocateOverflowPoints(), and ptwXY_reallocatePoints().

◆ nfu_setMemoryDebugMode()

void nfu_setMemoryDebugMode ( int  mode)

Definition at line 106 of file nf_utilities.cc.

106 {
107
108 nfu_debugging = mode;
109}

References nfu_debugging.

◆ nfu_statusMessage()

const char * nfu_statusMessage ( nfu_status  status)

Definition at line 76 of file nf_utilities.cc.

76 {
77
78 switch( status ) {
79 case nfu_Okay : return( Okay_message );
80 case nfu_mallocError : return( mallocError_message );
82 case nfu_badIndex : return( badIndex_message );
87 case nfu_badSelf : return( badSelf_message );
88 case nfu_divByZero : return( divByZero_message );
91 case nfu_empty : return( empty_message );
94 case nfu_badInput : return( badInput_message );
95 case nfu_badNorm : return( badNorm_message );
100 }
101 return( unknownStatus_message );
102}
static const char mallocError_message[]
Definition: nf_utilities.cc:27
static const char Okay_message[]
Definition: nf_utilities.cc:26
static const char badSelf_message[]
Definition: nf_utilities.cc:34
static const char notMutualDomian_message[]
Definition: nf_utilities.cc:40
static const char unsupportedInterpolationConversion_message[]
Definition: nf_utilities.cc:37
static const char invalidInterpolation_message[]
Definition: nf_utilities.cc:33
static const char badInput_message[]
Definition: nf_utilities.cc:42
static const char tooFewPoints_message[]
Definition: nf_utilities.cc:39
static const char oddNumberOfValues_message[]
Definition: nf_utilities.cc:47
static const char empty_message[]
Definition: nf_utilities.cc:38
static const char divByZero_message[]
Definition: nf_utilities.cc:35
static const char failedToConverge_message[]
Definition: nf_utilities.cc:46
static const char badNorm_message[]
Definition: nf_utilities.cc:43
static const char badIntegrationInput_message[]
Definition: nf_utilities.cc:44
static const char badIndexForX_message[]
Definition: nf_utilities.cc:31
static const char XNotAscending_message[]
Definition: nf_utilities.cc:30
static const char unsupportedInterpolation_message[]
Definition: nf_utilities.cc:36
static const char XOutsideDomain_message[]
Definition: nf_utilities.cc:32
static const char otherInterpolation_message[]
Definition: nf_utilities.cc:45
static const char unknownStatus_message[]
Definition: nf_utilities.cc:41
static const char insufficientMemory_message[]
Definition: nf_utilities.cc:28
static const char badIndex_message[]
Definition: nf_utilities.cc:29

References badIndex_message, badIndexForX_message, badInput_message, badIntegrationInput_message, badNorm_message, badSelf_message, divByZero_message, empty_message, failedToConverge_message, insufficientMemory_message, invalidInterpolation_message, mallocError_message, nfu_badIndex, nfu_badIndexForX, nfu_badInput, nfu_badIntegrationInput, nfu_badNorm, nfu_badSelf, nfu_divByZero, nfu_domainsNotMutual, nfu_empty, nfu_failedToConverge, nfu_insufficientMemory, nfu_invalidInterpolation, nfu_mallocError, nfu_oddNumberOfValues, nfu_Okay, nfu_otherInterpolation, nfu_tooFewPoints, nfu_unsupportedInterpolation, nfu_unsupportedInterpolationConversion, nfu_XNotAscending, nfu_XOutsideDomain, notMutualDomian_message, oddNumberOfValues_message, Okay_message, otherInterpolation_message, tooFewPoints_message, unknownStatus_message, unsupportedInterpolation_message, unsupportedInterpolationConversion_message, XNotAscending_message, and XOutsideDomain_message.

Referenced by MCGIDI_angular_parseFromTOM(), MCGIDI_angularEnergy_parsePointwiseFromTOM(), MCGIDI_energy_parseMadlandNixFromTOM(), MCGIDI_energy_parseNBodyPhaseSpaceFromTOM(), MCGIDI_energyAngular_linear_parseFromTOM(), MCGIDI_fromTOM_pdfOfX(), MCGIDI_KalbachMann_parseFromTOM2(), MCGIDI_LLNL_angularEnergy_parsePointwiseFromTOM(), MCGIDI_misc_Data2ptwXYPointsInUnitsOf(), MCGIDI_product_parseFromTOM(), MCGIDI_product_parsePolynomialMultiplicity(), MCGIDI_target_heated_read(), and MCGIDI_target_heated_recast().

◆ nfu_stringToListOfDoubles()

nfu_status nfu_stringToListOfDoubles ( char const *  str,
int64_t *  numberConverted,
double **  doublePtr,
char **  endCharacter 
)

Definition at line 29 of file nf_stringToDoubles.cc.

29 {
30
31 *numberConverted = 0;
32 *doublePtr = NULL;
33 return( nfu_stringToListOfDoubles2( str, numberConverted, doublePtr, endCharacter ) );
34}
static nfu_status nfu_stringToListOfDoubles2(char const *str, int64_t *numberConverted, double **doublePtr, char **endCharacter)

References nfu_stringToListOfDoubles2().

Referenced by ptwX_fromString(), and ptwXY_fromString().