Quang Anh Le
/
Gleitkommaoperation
n.n
Revision 0:cc171456477d, committed 2019-08-05
- Comitter:
- QuangAnhLe
- Date:
- Mon Aug 05 17:49:57 2019 +0000
- Commit message:
- 1.commit
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r cc171456477d main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Aug 05 17:49:57 2019 +0000 @@ -0,0 +1,47 @@ +#include "mbed.h" + +#define sqr(x) (x)*(x) +#define abs(x) (x)<0 ? -(x):(x) +Serial pc(PA_2,PA_3); + +// sin(x)0 x- (x^3/3!)+(x^5/5!)-(x^7/7!)+ (x^9/9!)- (x^11/!)+... +float mysin(float x) + +{ + float sinx=x; + float term=x; + int step=2; + int sign=-1; + + do + { + term *= sqr(x)/(step*(step+1)); + sinx += term * sign; + step += 2; + sign *= -1; + } + while (abs (term) >0.00001F); + + return sinx; +} + + +int main() { + + + float x= 0; + + pc.baud(115200); + while(1) + { + + pc.printf("#A%f\r\n",10*mysin(x)); + + x=x+0.01F; + if (x > 6.28F) + x=0; + + wait(0.1); + } + +} \ No newline at end of file
diff -r 000000000000 -r cc171456477d mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Aug 05 17:49:57 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9bcdf88f62b0 \ No newline at end of file