sPyNNaker neural_modelling 7.3.1
Loading...
Searching...
No Matches
Macros | Typedefs | Functions | Variables
maths-util.h File Reference

maths-util.h - first created 7/10/2013 version 0.1 More...

#include <stdfix.h>
#include <stdfix-full-iso.h>
#include <stdfix-exp.h>
#include <sqrt.h>

Go to the source code of this file.

Macros

#define START   0
 just for my convenience with zero offset arrays
 
#define REAL_CONST(x)   x##k
 Define a constant of type REAL.
 
#define UREAL_CONST(x)   x##uk
 Define a constant of type UREAL.
 
#define FRACT_CONST(x)   x##lr
 Define a constant of type FRACT.
 
#define UFRACT_CONST(x)   x##ulr
 Define a constant of type UFRACT.
 
#define ONE   REAL_CONST(1.0000)
 A REAL 1.0.
 
#define HALF   REAL_CONST(0.5000)
 A REAL 0.5.
 
#define ZERO   REAL_CONST(0.0000)
 A REAL 0.0.
 
#define ACS_DBL_TINY   REAL_CONST(0.000001)
 A REAL "very small number" (0.000001)
 
#define SQRT(x)   sqrtk(x)
 This calculates the square-root of the argument.
 
#define SQRTU(x)   sqrtuk(x)
 This calculates the square-root of the argument.
 
#define EXP(x)   expk(x)
 This calculates the exponential (to base e) of the argument.
 
#define EXPU(x)   expuk(x)
 This calculates the exponential (to base e) of the argument.
 
#define ABS(x)   absfx(x)
 This calculates the absolute value of the argument.
 
#define SIGN(x, y)   ((macro_arg_1=(y)) >= ZERO ? ABS(x) : -ABS(x))
 This calculates the value of an argument with the sign copied from another argument.
 
#define REAL_COMPARE(x, op, y)   (bitsk((x)) op bitsk((y)))
 Compare two REAL numbers.
 
#define REAL_TWICE(x)   ((x) * 2.000000k)
 Multiply by two.
 
#define REAL_HALF(x)   ((x) * 0.500000k)
 Divide by two.
 
#define MIN_HR(a, b)
 Minimum of two values.
 
#define MAX_HR(a, b)
 Maximum of two values.
 
#define SQR(a)
 Square of a value.
 
#define CUBE(a)
 Cube of a value.
 

Typedefs

typedef unsigned int Card
 A Cardinal type.
 
typedef accum REAL
 Type used for "real" numbers.
 
typedef unsigned accum UREAL
 Type used for "unsigned real" numbers.
 
typedef long fract FRACT
 Type used for "fractional" numbers.
 
typedef unsigned long fract UFRACT
 Type used for "unsigned fractional" numbers.
 

Functions

uint64_t udiv64 (uint64_t, uint64_t)
 
static REAL kdivk (REAL a, REAL b)
 Divides an accum by another accum.
 
static UREAL ukdivuk (UREAL a, UREAL b)
 Divides an unsigned accum by another unsigned accum.
 
static int32_t udivk (int32_t a, REAL b)
 Divides an integer by an accum.
 
static REAL kdivui (REAL a, uint32_t b)
 Divides an accum by an unsigned integer.
 
static UREAL pow_of_2 (REAL p)
 Calculates 2^p where p is a real number (rather than just an integer). This is still quicker than general power operations.
 

Variables

static const uint32_t fract_powers_2 []
 
static const uint32_t fract_powers_half []
 

Detailed Description

maths-util.h - first created 7/10/2013 version 0.1

some defines and other helper types/functions for applying ACS/HR types and ideas to SpiNNaker numerical coding

loose and transient toolbox of helper functions and macros until more structure present in maths libraries

this version 4-2-2014 is slightly cut down to allow source builds of neuron update code

Definition in file maths-util.h.

Macro Definition Documentation

◆ START

#define START   0

just for my convenience with zero offset arrays

Definition at line 44 of file maths-util.h.

◆ REAL_CONST

#define REAL_CONST (   x)    x##k

Define a constant of type REAL.

Parameters
xThe literal form of the number

Definition at line 104 of file maths-util.h.

◆ UREAL_CONST

#define UREAL_CONST (   x)    x##uk

Define a constant of type UREAL.

Parameters
xThe literal form of the number

Definition at line 108 of file maths-util.h.

◆ FRACT_CONST

#define FRACT_CONST (   x)    x##lr

Define a constant of type FRACT.

Parameters
xThe literal form of the number

Definition at line 112 of file maths-util.h.

◆ UFRACT_CONST

#define UFRACT_CONST (   x)    x##ulr

Define a constant of type UFRACT.

Parameters
xThe literal form of the number

Definition at line 116 of file maths-util.h.

◆ ONE

#define ONE   REAL_CONST(1.0000)

A REAL 1.0.

Definition at line 119 of file maths-util.h.

◆ HALF

#define HALF   REAL_CONST(0.5000)

A REAL 0.5.

Definition at line 121 of file maths-util.h.

◆ ZERO

#define ZERO   REAL_CONST(0.0000)

A REAL 0.0.

Definition at line 123 of file maths-util.h.

◆ ACS_DBL_TINY

#define ACS_DBL_TINY   REAL_CONST(0.000001)

A REAL "very small number" (0.000001)

Definition at line 125 of file maths-util.h.

◆ SQRT

#define SQRT (   x)    sqrtk(x)

This calculates the square-root of the argument.

Parameters
[in]xThe REAL-valued argument
Returns
The REAL-valued square root of the argument

Definition at line 130 of file maths-util.h.

◆ SQRTU

#define SQRTU (   x)    sqrtuk(x)

This calculates the square-root of the argument.

Parameters
[in]xThe UREAL-valued argument
Returns
The UREAL-valued square root of the argument

Definition at line 135 of file maths-util.h.

◆ EXP

#define EXP (   x)    expk(x)

This calculates the exponential (to base e) of the argument.

Parameters
[in]xThe REAL-valued argument
Returns
The REAL-valued exponential of the argument

Definition at line 140 of file maths-util.h.

◆ EXPU

#define EXPU (   x)    expuk(x)

This calculates the exponential (to base e) of the argument.

Parameters
[in]xThe UREAL-valued argument
Returns
The UREAL-valued exponential of the argument

Definition at line 145 of file maths-util.h.

◆ ABS

#define ABS (   x)    absfx(x)

This calculates the absolute value of the argument.

Parameters
[in]xThe REAL-valued argument
Returns
The REAL-valued absolute value of the argument

Definition at line 163 of file maths-util.h.

◆ SIGN

#define SIGN (   x,
  y 
)    ((macro_arg_1=(y)) >= ZERO ? ABS(x) : -ABS(x))

This calculates the value of an argument with the sign copied from another argument.

Parameters
[in]xThe REAL value to take the absolute value from
[in]yThe REAL value to take the sign from.
Returns
REAL value that is the combination of the two

Definition at line 174 of file maths-util.h.

◆ REAL_COMPARE

#define REAL_COMPARE (   x,
  op,
  y 
)    (bitsk((x)) op bitsk((y)))

Compare two REAL numbers.

Parameters
[in]xThe first REAL value to compare
opThe comparison operator (e.g., >=)
[in]yThe second REAL value to compare
Returns
True if the comparison returns true, false otherwise

Definition at line 192 of file maths-util.h.

◆ REAL_TWICE

#define REAL_TWICE (   x)    ((x) * 2.000000k)

Multiply by two.

Parameters
[in]xThe REAL argument
Returns
The REAL value that is twice the value of the argument

Definition at line 197 of file maths-util.h.

◆ REAL_HALF

#define REAL_HALF (   x)    ((x) * 0.500000k)

Divide by two.

Parameters
[in]xThe REAL argument
Returns
The REAL value that is half the value of the argument

Definition at line 202 of file maths-util.h.

◆ MIN_HR

#define MIN_HR (   a,
 
)
Value:
({\
__type_of__(a) _a = (a); \
__type_of__(b) _b = (b); \
_a <= _b? _a : _b;})

Minimum of two values.

Definition at line 207 of file maths-util.h.

◆ MAX_HR

#define MAX_HR (   a,
 
)
Value:
({\
__type_of__(a) _a = (a); \
__type_of__(b) _b = (b); \
_a > _b? _a : _b;})

Maximum of two values.

Definition at line 213 of file maths-util.h.

◆ SQR

#define SQR (   a)
Value:
({\
__type_of__(a) _a = (a); \
_a == ZERO? ZERO: _a * _a;})
#define ZERO
A REAL 0.0.
Definition maths-util.h:123

Square of a value.

Definition at line 219 of file maths-util.h.

◆ CUBE

#define CUBE (   a)
Value:
({\
__type_of__(a) _a = (a); \
_a == ZERO? ZERO: _a * _a * _a;})

Cube of a value.

Definition at line 224 of file maths-util.h.

Typedef Documentation

◆ Card

typedef unsigned int Card

A Cardinal type.

Definition at line 41 of file maths-util.h.

◆ REAL

typedef accum REAL

Type used for "real" numbers.

Definition at line 91 of file maths-util.h.

◆ UREAL

typedef unsigned accum UREAL

Type used for "unsigned real" numbers.

Definition at line 94 of file maths-util.h.

◆ FRACT

typedef long fract FRACT

Type used for "fractional" numbers.

Definition at line 97 of file maths-util.h.

◆ UFRACT

typedef unsigned long fract UFRACT

Type used for "unsigned fractional" numbers.

Definition at line 100 of file maths-util.h.

Function Documentation

◆ udiv64()

uint64_t udiv64 ( uint64_t  num,
uint64_t  den 
)
extern

Definition at line 24 of file c_main_neuron_common.h.

◆ kdivk()

static REAL kdivk ( REAL  a,
REAL  b 
)
inlinestatic

Divides an accum by another accum.

Parameters
[in]aThe dividend
[in]bThe divisor
Returns
a divided by b

Definition at line 234 of file maths-util.h.

◆ ukdivuk()

static UREAL ukdivuk ( UREAL  a,
UREAL  b 
)
inlinestatic

Divides an unsigned accum by another unsigned accum.

Parameters
[in]aThe dividend
[in]bThe divisor
Returns
a divided by b

Definition at line 242 of file maths-util.h.

◆ udivk()

static int32_t udivk ( int32_t  a,
REAL  b 
)
inlinestatic

Divides an integer by an accum.

Parameters
[in]aThe dividend
[in]bThe divisor
Returns
a divided by b

Definition at line 250 of file maths-util.h.

◆ kdivui()

static REAL kdivui ( REAL  a,
uint32_t  b 
)
inlinestatic

Divides an accum by an unsigned integer.

Parameters
[in]aThe dividend
[in]bThe divisor
Returns
a divided by b

Definition at line 258 of file maths-util.h.

◆ pow_of_2()

static UREAL pow_of_2 ( REAL  p)
inlinestatic

Calculates 2^p where p is a real number (rather than just an integer). This is still quicker than general power operations.

Parameters
[in]pThe power to raise 2 to; if p >= 16 or <= -16 the result will be saturated to MAX_U_REAL or 0 respectively.

Definition at line 283 of file maths-util.h.

Variable Documentation

◆ fract_powers_2

const uint32_t fract_powers_2[]
static
Initial value:
= {
0x16a09, 0x1306f, 0x1172b, 0x10b55, 0x1059b, 0x102c9, 0x10163, 0x100b1,
0x10058, 0x1002c, 0x10016, 0x1000b, 0x10005, 0x10002, 0x10001
}

2^(1/(2^n)) for values of n between 1 and 15, in U1616 format, then converted to uint32_t for computation. These can be used to work out fractional powers of 2 by multiplication.

Definition at line 265 of file maths-util.h.

◆ fract_powers_half

const uint32_t fract_powers_half[]
static
Initial value:
= {
0xb504, 0xd744, 0xeac0, 0xf525, 0xfa83, 0xfd3e, 0xfe9e, 0xff4e, 0xffa7,
0xffd3, 0xffe9, 0xfff4, 0xfffa, 0xfffd, 0xfffe
}

2^-(1/2^n)) for values of n between 1 and 15, in U1616 format, then converted to uint32_t for computation. These can be used to work out negative fractional power of 2 by multiplication.

Definition at line 274 of file maths-util.h.