sPyNNaker neural_modelling 7.1.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 EXP(x)   expk(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 102 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 106 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 110 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 114 of file maths-util.h.

◆ ONE

#define ONE   REAL_CONST(1.0000)

A REAL 1.0.

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

◆ HALF

#define HALF   REAL_CONST(0.5000)

A REAL 0.5.

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

◆ ZERO

#define ZERO   REAL_CONST(0.0000)

A REAL 0.0.

Definition at line 121 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 123 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 128 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 133 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 151 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 162 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 180 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 185 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 190 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 195 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 201 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:121

Square of a value.

Definition at line 207 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 212 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 89 of file maths-util.h.

◆ UREAL

typedef unsigned accum UREAL

Type used for "unsigned real" numbers.

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

◆ FRACT

typedef long fract FRACT

Type used for "fractional" numbers.

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

◆ UFRACT

typedef unsigned long fract UFRACT

Type used for "unsigned fractional" numbers.

Definition at line 98 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 222 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 230 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 238 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 246 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 271 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 253 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 262 of file maths-util.h.