LibRan  0.1
Pseudo-random number distribution generator
Functions
LRerror.c File Reference

LibRan error codes and messages. More...

#include <stdio.h>
#include "libran.h"
Include dependency graph for LRerror.c:

Go to the source code of this file.

Functions

char * LRstrerror (int LRerrno)
 LRstrerror(int LRerrno) - return some explanatory text regarding the given LibRan errno. More...
 
char * LRstrerrno (int LRerrno)
 LRstrerrno(int LRerrno) - return the errno code string for the given LibRan errno. More...
 
void LRperror (char *str, int LRerrno)
 LRperror(char *str, int LRerrno) - print out explanatory error message to stderr. More...
 

Detailed Description

LibRan error codes and messages.

The LibRan error routines are patterned after the Standard C perror()/strerror() routines and the like.

The object creation routines like LR_new and LR_bin_new will return a NULL value if they fail. No error value is returned otherwise.

Many of the LibRan routines return a random variate or distribution function value. When these result in an error these functions return NAN (Not-A-Number).

The LR_obj and LR_bin objects have an errno attribute which can be queried.

An example code fragment:

#include <math.h>
#include "libran.h"
...
LR_obj *o = LR_new(piece, LR_double);
if (!*o) { // handle error }
...
if (isnan(x = LRd_RAN(o)) {
// handle error
LRperror("MyApp",o->errno);
}
...

However, the other routines, especially those that return an integer value are returning a LibRan error value if non-zero.

#include "libran.h"
...
LR_bin *b = LR_bin_new(100);
if (!*b) { // handle error }
...
if (!LR_bin_set(b,2.0)) {
// handle error
LRperror("MyApp",b->errno);
}
...

Use these routines to identify the specific LibRan error.

Definition in file LRerror.c.

Function Documentation

◆ LRperror()

void LRperror ( char *  str,
int  LRerrno 
)

LRperror(char *str, int LRerrno) - print out explanatory error message to stderr.

If the char str string is not NULL then prepend this string to the LibRan error message with a " : " delimiter and sent to stderr .

Parameters
strString to prepend to error message
LRerrnoLibRan error number
Returns
void - but outputs an error message to stderr

Definition at line 157 of file LRerror.c.

◆ LRstrerrno()

char* LRstrerrno ( int  LRerrno)

LRstrerrno(int LRerrno) - return the errno code string for the given LibRan errno.

Parameters
LRerrnoLibRan error number
Returns
char * pointer to static constant string.

Definition at line 112 of file LRerror.c.

◆ LRstrerror()

char* LRstrerror ( int  LRerrno)

LRstrerror(int LRerrno) - return some explanatory text regarding the given LibRan errno.

Parameters
LRerrnoLibRan error number
Returns
char * pointer to static constant string.

Definition at line 71 of file LRerror.c.