# Thread: Finding a reference error by mathematical conditioning

1. ## Finding a reference error by mathematical conditioning

Hi There,

I am a new comer here. I just want to know few things those are really hard to track down.I am trying to debug a existing F/W code mostly written in c or c++. This IDE and compiler is from a particular DSP/MCU company. This code is a complex one and F/W and S/W mixed together. Some codes are not even understandable because I have very limited knowledge in syntax, pointer datatype and flags etc.Manuals and examples can give some ideas.

Now lets talk a specific problem, .c file includes some dependencies like those are customized,made for particular reason

Code:
```#include "DSP28x_Project.h"
#include "Register.h"
#include "CLA.h"
#include "LED.h"```
From CLA (Control Law Accelerator? library of TI external VOID function with macro has called to compare some reference value of particular parameter. here we go,

Code:
```__interrupt void Cla1Task2 ( void )
{
float Err;

Bf7();// this is a function works for some float variables

Current_T_ch2 = Current_T_ch2 < 0 ? 0 : Current_T_ch2;

if(Tartget_B2 > 0)
{
Err = Tartget_B2 - Current_T_ch2;// target B2 is also a register.
B_Ref2 += PKP2 * (Err - Err_B_P2) + PKI2 * Err;// PKI2 is defined in a register file
Err_B_P2 = Err;

B_Ref2 = B_Ref2 > 0.35 ? 0.35 : (B_Ref2 < 0 ? 0 : B_Ref2);// this one is not understandable
}
}
```

Let me know the mathematical reasoning like, x= x>0.35 ? 0.35 : ( x<0 ? 0 : x);
How ?, : is meaning full? How does compiler read and think? if x> 0.35 then how the condition applies for x<0 2. '?' is the ternary operator.

It is clamping x to between 0.0 an 0.35

Translated:

If x > 0.35 then
Use 0.35

Else If x < 0.0 then
Use 0.0

Else
Use x. 3. Originally Posted by hamster_nz '?' is the ternary operator.

It is clamping x to between 0.0 an 0.35

Translated:

If x > 0.35 then
Use 0.35

Else If x < 0.0 then
Use 0.0

Else
Use x.

Nice feedback indeed.
Does : means that we can place this 2 condition at a time? 4. It is a pretty common pattern that people use. Not because it is particularly nice, but just because it fits on one line. 5. 6. Originally Posted by Salem Some time people overlook silly question.
Does it offence to somewhere else?
If so pardon me. Popular pages Recent additions #include, b_ref2, logical operators, mathematical, variable arguments 