C Control The I Unit-M Advanced 5 Vdc Inputs / outputs 16 x digital I/Os / 8 x analogue or digital I/Os Program memory 2 198805 Datenbogen
Produktcode
198805
DETAILS OF THE DATA TYPE FLOAT
Internal organisation
While the C-Control usually has just BYTE and WORD Types, even for non professionals easy to handle,
now there is the new Data Type Float. It consists on one byte exponent and 3 byte mantissa with sign.
Therefore a floating point value occupies 4 bytes (32 bit).
Value size
The flaoting point Module is able to compute values in the range of +-1 × 10±38.
Accuracy
You will find that even simple values can not be expressed 100% accurate with a 32bit Floating Point
System. The value 1234 will be shown as 1233.999, but this is not a computing error. It is based on the
limited accuracy of every 32 bit Floating Point System.
While the C-Control usually has just BYTE and WORD Types, even for non professionals easy to handle,
now there is the new Data Type Float. It consists on one byte exponent and 3 byte mantissa with sign.
Therefore a floating point value occupies 4 bytes (32 bit).
Value size
The flaoting point Module is able to compute values in the range of +-1 × 10±38.
Accuracy
You will find that even simple values can not be expressed 100% accurate with a 32bit Floating Point
System. The value 1234 will be shown as 1233.999, but this is not a computing error. It is based on the
limited accuracy of every 32 bit Floating Point System.
INTERNAL HANDLING OF FP OPERATIONS
For simple calculations it is not required to know this details. But very complex computations may lead to
stack overflows if some basics are not considered.
The C-Control Stack
The stack is a memory used for temporary storage of values. This can be values needed for calculations or
addresses, needed for a return from a subroutine.
For a brief information of stack usage see this example:
MyFloat=FloatVar1*Floatvar2
This expression is compiled to a token code that causes the operating system to do the following:
stack overflows if some basics are not considered.
The C-Control Stack
The stack is a memory used for temporary storage of values. This can be values needed for calculations or
addresses, needed for a return from a subroutine.
For a brief information of stack usage see this example:
MyFloat=FloatVar1*Floatvar2
This expression is compiled to a token code that causes the operating system to do the following:
Put content of FloatVar1 to Stack
Put content of Floatvar2 to Stack
Pull last 2 stack entries from stack and push them into FP Accumulators (FPACC)
Multiply the FPACCs content
Push the result to stack
Pull the last stack entry from stack and move it to MyFloat
Put content of Floatvar2 to Stack
Pull last 2 stack entries from stack and push them into FP Accumulators (FPACC)
Multiply the FPACCs content
Push the result to stack
Pull the last stack entry from stack and move it to MyFloat
If the term is more complex, many values will be pushed to stack before any calculation is done and they are
removed from stack.
Example:
MyFloat=Floatvar3-FloatVar1*(Floatvar2+Floatvar4)
removed from stack.
Example:
MyFloat=Floatvar3-FloatVar1*(Floatvar2+Floatvar4)
Content of FloatVar3 to Stack
Content of Floatvar1 to Stack
Content of FloatVar2 to Stack
Content of Floatvar4 to Stack
Pull last 2 stack entries from stack, load them in to FPACCs
Add FPACCs
Push result to Stack
Pull last 2 stack entries from stack, load them in to FPACCs
Multiply FPACCs
Push result to Stack
Pull last 2 stack entries from stack, load them in to FPACCs
Subtract FPACCs
Push result to Stack
Pull last stack entry and move to MyFloat
Content of Floatvar1 to Stack
Content of FloatVar2 to Stack
Content of Floatvar4 to Stack
Pull last 2 stack entries from stack, load them in to FPACCs
Add FPACCs
Push result to Stack
Pull last 2 stack entries from stack, load them in to FPACCs
Multiply FPACCs
Push result to Stack
Pull last 2 stack entries from stack, load them in to FPACCs
Subtract FPACCs
Push result to Stack
Pull last stack entry and move to MyFloat
You can see that even this simple term pushes 4 float values to stack, before calculation is done and values
are removed from stack. Here 16 Bytes Stack are used for this simple term. And remember that a subroutine
call also adds two bytes return address to stack.
29