|
发表于 2014-1-21 07:55:29
|
显示全部楼层
- #include <stdio.h>
- #include <stdlib.h>
- #include "math.h"
- typedef signed char int8_t;
- typedef unsigned char uint8_t;
- typedef signed short int16_t;
- typedef unsigned short uint16_t;
- typedef signed int int32_t;
- typedef unsigned int uint32_t;
- typedef float flt_t;
- typedef double lflt_t;
- int8_t _roll_cal_(lflt_t src, lflt_t* dst, lflt_t* limit, uint32_t n_max)
- {
- lflt_t error;
- for (*dst = src, *limit = *limit? *limit : 0 - *limit; n_max; n_max--)
- {
- error = src - (*dst - sin(*dst));
- *dst += error / (1 - cos(*dst));
- if ((error < *limit) && (-error < *limit))
- {
- *limit = error;
- return 0;
- }
- }
- return -1;
- }
- int main(int argc, char** argv)
- {
- lflt_t result, error = 0.0003;
- if (_roll_cal_(6, &result, &error, 8))
- {
- printf((const char*)"cal fail!\n");
- }
- printf((const char*)"error = %lf\n", error);
- printf((const char*)"result = %lf\n", result - sin(result));
- return EXIT_SUCCESS;
- }
复制代码 |
|