This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RM46L852: Incorrect calculation result of sin/cos function

Part Number: RM46L852

Hi Champs,

I found out an incorrect calculation for sin and cos function. The output of sin/cos should be bounded in ±1. But sometimes, the result was not as the below test results.

 What can make this issue? 

 

Here is my sample code for sin/cos test.

float32_t test_float32 = 0.0001f;

int32_t test_int32, test_int32_2;

 

Test_function(void)

{

    //...

 

    for(i = 0; i < 100000; i++)

    {

        test_int32 = (int32_t)test_float32;

 

        angle_rad_test = cosf(test_float32);

 

        test_int32_2 = (int32_t)((test_float32 - test_float32)/ 2.0f);  //float32_t test_float32, angle_rad_test

 

        printf("count %d, test_int32_2 %d, angle_rad_test %.06f, \n", i, test_int32_2, angle_rad_test);

 

        vTaskDelay(20);

    }

   

    //...

}

 

[Test Result #1]

17:04:47.338 count 507, test_int32_2 0, angle_rad_test 1.000000,
17:04:47.338 count 508, test_int32_2 0, angle_rad_test 1.000000,
17:04:47.373 count 509, test_int32_2 0, angle_rad_test 1.000000,
17:04:47.397 count 510, test_int32_2 0, angle_rad_test 1.000000,
17:04:47.397 count 511, test_int32_2 0, angle_rad_test 1.000000,
17:04:47.435 count 512, test_int32_2 0, angle_rad_test 1.000000,
17:04:47.435 count 513, test_int32_2 0, angle_rad_test 7186416586192395687103271484375000000000000000.000000,
17:04:47.487 count 514, test_int32_2 0, angle_rad_test 1.000000,
17:04:47.487 count 515, test_int32_2 0, angle_rad_test 1.000000,
17:04:47.509 count 516, test_int32_2 0, angle_rad_test 1.000000,
17:04:47.537 count 517, test_int32_2 0, angle_rad_test 1.000000,
17:04:47.550 count 518, test_int32_2 0, angle_rad_test 1.000000,
17:04:47.550 count 519, test_int32_2 0, angle_rad_test 1.000000,

 

[Test Result #2]

17:04:56.545 count 953, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.567 count 954, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.594 count 955, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.614 count 956, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.614 count 957, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.641 count 958, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.658 count 959, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.698 count 960, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.718 count 961, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.736 count 962, test_int32_2 0, angle_rad_test 7186415140226747989654541015625000000000000000.000000,
17:04:56.736 count 963, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.782 count 964, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.804 count 965, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.804 count 966, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.823 count 967, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.841 count 968, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.879 count 969, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.879 count 970, test_int32_2 0, angle_rad_test 1.000000,
17:04:56.933 count 971, test_int32_2 0, angle_rad_test 1.000000,

 

[Test Result #3]

17:05:05.291 count 1370, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.311 count 1371, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.328 count 1372, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.353 count 1373, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.367 count 1374, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.398 count 1375, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.416 count 1376, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.416 count 1377, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.458 count 1378, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.474 count 1379, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.490 count 1380, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.513 count 1381, test_int32_2 0, angle_rad_test 7186416581368986368179321289062500000000000000.000000,
17:05:05.532 count 1382, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.552 count 1383, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.569 count 1384, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.608 count 1385, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.644 count 1386, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.644 count 1387, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.671 count 1388, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.690 count 1389, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.690 count 1390, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.724 count 1391, test_int32_2 0, angle_rad_test 1.000000,
17:05:05.739 count 1392, test_int32_2 0, angle_rad_test 1.000000,

 

[Test Result #4]

17:05:43.640 count 3175, test_int32_2 0, angle_rad_test 1.000000,
17:05:43.670 count 3176, test_int32_2 0, angle_rad_test 1.000000,
17:05:43.670 count 3177, test_int32_2 0, angle_rad_test 1.000000,
17:05:43.693 count 3178, test_int32_2 0, angle_rad_test 1.000000,
17:05:43.693 count 3179, test_int32_2 0, angle_rad_test 1.000000,
17:05:43.693 count 3180, test_int32_2 0, angle_rad_test 1.000000,
17:05:43.693 count 3181, test_int32_2 0, angle_rad_test 1.000000,
17:05:43.693 count 3182, test_int32_2 0, angle_rad_test 712434656989405274391174316406.250000,
17:05:43.693 count 3183, test_int32_2 0, angle_rad_test 1.000000,
17:05:43.693 count 3184, test_int32_2 0, angle_rad_test 1.000000,
17:05:43.693 count 3185, test_int32_2 0, angle_rad_test 1.000000,
17:05:43.693 count 3186, test_int32_2 0, angle_rad_test 1.000000,
17:05:43.713 count 3187, test_int32_2 0, angle_rad_test 1.000000,
17:05:43.713 count 3188, test_int32_2 0, angle_rad_test 1.000000,

 

[Test Result #5]

17:05:31.440 count 2614, test_int32_2 0, angle_rad_test 1.000000,
17:05:31.440 count 2615, test_int32_2 0, angle_rad_test 1.000000,
17:05:31.468 count 2616, test_int32_2 0, angle_rad_test 1.000000,
17:05:31.468 count 2617, test_int32_2 0, angle_rad_test 1.000000,
17:05:31.484 count 2618, test_int32_2 0, angle_rad_test 1.000000,
17:05:31.516 count 2619, test_int32_2 0, angle_rad_test 1.000001,
17:05:31.533 count 2620, test_int32_2 0, angle_rad_test 1.000000,
17:05:31.533 count 2621, test_int32_2 0, angle_rad_test 1.000000,
17:05:31.579 count 2622, test_int32_2 0, angle_rad_test 1.000000,
17:05:31.579 count 2623, test_int32_2 0, angle_rad_test 1.000000,
17:05:31.619 count 2624, test_int32_2 0, angle_rad_test 1.000000,

Here is processor option in CCS.

Thanks, 

Steve