ScienLON.lib for LONworks

Introduction

Applications for LON systems can be written in the Neuron C language. This is a dialect of the standard C language that includes some specific extensions for the LON environment. In Neuron C, standard mathematical operations like addition and multiplication of floating point numbers are supported. However, other mathematical functions like logarithms and trigonometric functions are not available.

At Snijder Micro Systems a scientific functions package was developed for the LON system. This page describes the functions provided by this library, including accuracy and performance information.


Available functions

ln(x) natural logarithm of x
log(x) base 10 logarithm of x
exp(x) exponential function, ex
alog(x) exponential function, 10x
xtoy(x, y) generic exponential function, xy
sin(x) sine function
cos(x) cosine function
tan(x) tangent function
asin(x) arcsine function
atan(x) arccosine function
atan(x) arctangent function
sqrt(x) square root function

All functions are implemented using the standard IEEE 754 simple precision floating point format. This is, 1 sign bit, 8 exponent bits, and 23 mantissa bits. This allows for a decimal range of 10-38 to 1038 approximately, with roughly ~7 digit accuracy.


Accuracy

Accuracy is specified as a relative error. The relative error of a function result with argument x is given by the following equation:

relative_error(x) = [f_calc(x) - f_exact(x)] / f_exact(x)

where f_calc is the value returned by the implementation and f_exact the exact, expected value. Due to the 32 bit IEEE 754 floating point representation, this accuracy can not be better than 1.2E-7. The actual error will depend on the argument value. Table 1 summarizes the relative error for the library functions in several argument ranges.

Table 1. ScienLON.lib accuracy
Function Argument range Rel. error
ln(x), log(x) [0.92, 1.01]
[3.4e-38, 3.4e38]
<1E-5
<1E-6
exp(x) [-15, 15]
[-88, 87]
<1E-6
<1E-5
alog(x) [-4, 4]
[-37.91, 37.78]
<1E-6
<1E-5
xtoy(x,y) [(0.1, 10), (-15, 15)] <1E-5
sin(x) [0, 2pi]
[pi - 1E-6, pi + 1E-6]
[2pi - 1E-6, 2pi]
<1E-6
<1E-5
<2E-5
cos(x) [0, 2pi]
[pi/2 - 0.08, pi/2 + 0.16]
[3pi/2 - 0.16, 3pi/2 + 0.16]
<1E-6
<2E-5
<2E-5
tan(x) [0, pi/2]
[pi/2 - 0.11, pi/2]
<1E-6
<2E-5
asin(x) - -
acos(x) - -
atan(x) [3.4E-38, 3.4E38] <1E-6
sqrt(x) [3.4E-38 , 8.5E37] <1E-6

Performance

Processing times for the library functions can depend on the the argument values. Therefore performance data was measured for different argument values. Table 2 summarizes maximum and minimum calculation times for all functions in the library. This data that was measured on a Neuron 3150 CPU running at 10 MHz. Note that argument values may exist for which calculation time is actually larger than the times shown in this table.

Table 2. ScienLON.lib performance
Function Min time (ms) Max time (ms)
ln(x) 16 21
log(x) 17 22
exp(x) 14 22
alog(x) 15 22
xtoy(x,y) 30 40
sin(x) 15 27
cos(x) 14 25
tan(x) 31 54
asin(x) - -
acos(x) - -
atan(x) 16 20
sqrt(x) 8 9