steveneads Posted December 19, 2019 Posted December 19, 2019 What is the best way to do the equivalent of "trunc" in code that runs in the kernel?
Omron Forums Support Posted December 19, 2019 Posted December 19, 2019 Do you mean C code or PMAC Script?
Omron Forums Support Posted December 20, 2019 Posted December 20, 2019 In the script environment, you can use "ceil" to round up and "floor" to round down.
steveneads Posted December 20, 2019 Author Posted December 20, 2019 I am trying to use it in C code that is included with usrcode.c
Omron Forums Support Posted January 3, 2020 Posted January 3, 2020 In C we also have the functions "floor" and "ceil". Below is a bgcplc 0 I used to test this. 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; }
steve.milici Posted January 3, 2020 Posted January 3, 2020 In C we also have the functions "floor" and "ceil". Below is a bgcplc 0 I used to test this. 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().
steveneads Posted January 7, 2020 Author Posted January 7, 2020 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?
Recommended Posts