Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trunc function
#1
What is the best way to do the equivalent of "trunc" in code that runs in the kernel?
Reply
#2
Do you mean C code or PMAC Script?
Reply
#3
In the script environment, you can use "ceil" to round up and "floor" to round down.
Reply
#4
I am trying to use it in C code that is included with usrcode.c
Reply
#5
In C we also have the functions "floor" and "ceil". Below is a bgcplc 0 I used to test this.

Code:
void user_plcc()
{

    pshm->P[0]=floor(9.3);
    pshm->P[1]=floor(9.7);
    pshm->P[2]=ceil(9.3);
    pshm->P[3]=ceil(9.7);

    pshm->UserAlgo.BgCplc[0]=0;
}
Reply
#6
(01-02-2020, 05:15 PM)Eric Hotchkiss Wrote: In C we also have the functions "floor" and "ceil". Below is a bgcplc 0 I used to test this.

Code:
void user_plcc()
{

    pshm->P[0]=floor(9.3);
    pshm->P[1]=floor(9.7);
    pshm->P[2]=ceil(9.3);
    pshm->P[3]=ceil(9.7);

    pshm->UserAlgo.BgCplc[0]=0;
}

Just don't use it in CaptCompISR().
Reply
#7
Thank you - I've made it work using "floor" with some logic to adjust the result for negative inputs (as I wanted to round towards zero).

Is there an easy way to find a list of C functions that are and are not supported in the Kernel C code?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)