Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nf_utilities.h File Reference
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdarg.h>
Include dependency graph for nf_utilities.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

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

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

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

Macro Definition Documentation

#define nf_floatToShortestString_includeSign   ( 1 << 2 )

Definition at line 18 of file nf_utilities.h.

#define nf_floatToShortestString_keepPeriod   ( 1 << 1 )

Definition at line 17 of file nf_utilities.h.

#define nf_floatToShortestString_trimZeros   ( 1 << 0 )

Definition at line 16 of file nf_utilities.h.

#define NUMERICALFUNCTIONS_SVN_VERSION   110+

Definition at line 14 of file nf_utilities.h.

Typedef Documentation

typedef enum nfu_status_e nfu_status

Enumeration Type Documentation

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.

enum nfu_status_e nfu_status

Function Documentation

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 
72  if( flags & nf_floatToShortestString_includeSign ) sign = "+";
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". */
127  if( flags & nf_floatToShortestString_keepPeriod ) {
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 }
#define nf_floatToShortestString_trimZeros
Definition: nf_utilities.h:16
const XML_Char int const XML_Char * value
Definition: expat.h:331
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
#define isfinite
#define nf_floatToShortestString_includeSign
Definition: nf_utilities.h:18
#define nf_floatToShortestString_keepPeriod
Definition: nf_utilities.h:17
G4int sign(const T t)

Here is the call graph for this function:

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 }
const char * p
Definition: xmltok.h:285
const G4int n
static int nfu_debugging
Definition: nf_utilities.cc:49

Here is the caller graph for this function:

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 }
const char * p
Definition: xmltok.h:285
static int nfu_debugging
Definition: nf_utilities.cc:49

Here is the caller graph for this function:

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 }
G4int sign(const T t)
double nfu_getNAN ( void  )

Definition at line 54 of file nf_utilities.cc.

54  {
55 
56  return( NAN );
57 }

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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 }
const char * p
Definition: xmltok.h:285
static int nfu_debugging
Definition: nf_utilities.cc:49

Here is the caller graph for this function:

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 }
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 }
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 }
const char * p
Definition: xmltok.h:285
static int nfu_debugging
Definition: nf_utilities.cc:49

Here is the caller graph for this function:

void nfu_setMemoryDebugMode ( int  mode)

Definition at line 106 of file nf_utilities.cc.

106  {
107 
108  nfu_debugging = mode;
109 }
static int nfu_debugging
Definition: nf_utilities.cc:49
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 );
84  case nfu_badIndexForX : return( badIndexForX_message );
87  case nfu_badSelf : return( badSelf_message );
88  case nfu_divByZero : return( divByZero_message );
91  case nfu_empty : return( empty_message );
92  case nfu_tooFewPoints : return( tooFewPoints_message );
94  case nfu_badInput : return( badInput_message );
95  case nfu_badNorm : return( badNorm_message );
100  }
101  return( unknownStatus_message );
102 }
static const char empty_message[]
Definition: nf_utilities.cc:38
static const char mallocError_message[]
Definition: nf_utilities.cc:27
static const char unsupportedInterpolation_message[]
Definition: nf_utilities.cc:36
static const char XNotAscending_message[]
Definition: nf_utilities.cc:30
static const char insufficientMemory_message[]
Definition: nf_utilities.cc:28
static const char badIndex_message[]
Definition: nf_utilities.cc:29
static const char unsupportedInterpolationConversion_message[]
Definition: nf_utilities.cc:37
static const char tooFewPoints_message[]
Definition: nf_utilities.cc:39
static const char badSelf_message[]
Definition: nf_utilities.cc:34
static const char unknownStatus_message[]
Definition: nf_utilities.cc:41
static const char otherInterpolation_message[]
Definition: nf_utilities.cc:45
static const char XOutsideDomain_message[]
Definition: nf_utilities.cc:32
static const char Okay_message[]
Definition: nf_utilities.cc:26
static const char notMutualDomian_message[]
Definition: nf_utilities.cc:40
static const char divByZero_message[]
Definition: nf_utilities.cc:35
static const char badIntegrationInput_message[]
Definition: nf_utilities.cc:44
static const char failedToConverge_message[]
Definition: nf_utilities.cc:46
static const char invalidInterpolation_message[]
Definition: nf_utilities.cc:33
static const char badIndexForX_message[]
Definition: nf_utilities.cc:31
static const char badInput_message[]
Definition: nf_utilities.cc:42
static const char badNorm_message[]
Definition: nf_utilities.cc:43
static const char oddNumberOfValues_message[]
Definition: nf_utilities.cc:47

Here is the caller graph for this function:

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)

Here is the call graph for this function:

Here is the caller graph for this function: