2014-09-16 07:03 AM
Hello,
I would like to do some mathematical calulations like square root, sin, cos,... with the SPC560D. Does ST provide any libraries for that purpose which I can include in my SPC5 project? Best regards, PatrikSolved! Go to Solution.
2014-09-19 06:30 AM
#include <errno.h>
#include <stdio.h> /* printf */
#include <math.h> /* sin */
#include <float.h>
#define PI 3.14159265
/* For sprintf porting */
void *sbrk(size_t incr) {
extern uint8_t __heap_base__;
extern uint8_t __heap_end__;
static uint8_t *p = &__heap_base__;
static uint8_t *newp;
newp = p + incr;
if (newp > &__heap_end__) {
errno = ENOMEM;
return (void *)-1;
}
return p = newp;
}
/*
* Application entry point.
*/
int main(void) {
char string[60];
double param, result;
.......................
param = 30.0;
result = sin (param*PI/180)*1000;
sprintf (string, ''The sine of %d degrees is %d.\n'', (int)param, (int)result );
it works well ;)
Best regards
Erwan2014-09-19 06:30 AM
#include <errno.h>
#include <stdio.h> /* printf */
#include <math.h> /* sin */
#include <float.h>
#define PI 3.14159265
/* For sprintf porting */
void *sbrk(size_t incr) {
extern uint8_t __heap_base__;
extern uint8_t __heap_end__;
static uint8_t *p = &__heap_base__;
static uint8_t *newp;
newp = p + incr;
if (newp > &__heap_end__) {
errno = ENOMEM;
return (void *)-1;
}
return p = newp;
}
/*
* Application entry point.
*/
int main(void) {
char string[60];
double param, result;
.......................
param = 30.0;
result = sin (param*PI/180)*1000;
sprintf (string, ''The sine of %d degrees is %d.\n'', (int)param, (int)result );
it works well ;)
Best regards
Erwan