[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Problem with asin() and acos()
From: |
jlf |
Subject: |
[avr-gcc-list] Problem with asin() and acos() |
Date: |
Tue, 1 Oct 2002 22:39:02 +0200 |
Greetings,
the acos() and asin() calls cause me some trouble,
they return incorrect numbers as shown for acos in
the listing below. tan(x), sin(x) and cos(x) are ok.
In a posting on the avr-gcc mailing list july 27th
Jamie Morken (address@hidden) describes
exactly the same problem.
What strokes me in Jamie's desciption is that he gets
the same (wrong) result as I did:
y=1.00000000 => acos(y)=0.08713222
(I would expect something close to 0...).
So, does anybody know if acos/asin really are flawed? Is there
any possible work-around? Or have I missed something?
If there are any (verified) code examples out there which uses
acon or asin, please post an example or an URL.
I use the ATMega163 and the latest windows-distro from avrFreaks:
- avr-gcc 3.2
- avr-libc-20020612
- binutils-20020614
- jesper
-------------------------------------------------------------------------------
Examples for acos in the range 0-PI/2:
cos() is ok, but acos() is no good in the 0-PI/4 range
x=0.00000000 cos(x)=1.00000000 acos(cos(x))=0.08713222
x=0.10000000 cos(x)=0.99500416 acos(cos(x))=0.12311018
x=0.20000000 cos(x)=0.98006656 acos(cos(x))=0.20516956
x=0.30000002 cos(x)=0.95533648 acos(cos(x))=0.30128932
x=0.40000000 cos(x)=0.92106096 acos(cos(x))=0.40036808
x=0.50000000 cos(x)=0.87758256 acos(cos(x))=0.50010836
x=0.60000004 cos(x)=0.82533560 acos(cos(x))=0.60002904
x=0.70000008 cos(x)=0.76484216 acos(cos(x))=0.70000688
x=0.80000008 cos(x)=0.69670680 acos(cos(x))=0.80000120
x=0.90000008 cos(x)=0.62160992 acos(cos(x))=0.90000024
x=1.00000008 cos(x)=0.54030208 acos(cos(x))=1.00000024
x=1.10000016 cos(x)=0.45359604 acos(cos(x))=1.10000016
x=1.20000016 cos(x)=0.36235760 acos(cos(x))=1.20000016
x=1.30000016 cos(x)=0.26749868 acos(cos(x))=1.30000016
x=1.40000016 cos(x)=0.16996696 acos(cos(x))=1.40000016
x=1.50000016 cos(x)=0.07073699 acos(cos(x))=1.50000016
--------------------------------------------------------------------------------
Source:
#include <math.h>
...
static float x;
for (x=0; x<M_PI/2; x+=0.1) {
uart_puts("x="); /* send string constant... */
uart_putld(x); /* send double... */
uart_puts(" cos(x)=");
uart_putld(cos(x));
uart_puts(" acos(cos(x))=");
uart_putld(acos(cos(x)));
uart_puts("\n\r");
}
--------------------------------------------------------------------------------
My Makefile:
# Simple Makefile Volker Oth (c) 1999
# edited by AVRfreaks.net nov.2001
########### change these lines according to your project ##################
#put the name of the target mcu here (at90s8515, at90s8535, attiny22, atmega603
etc.)
MCU = atmega163
#put the name of the target file here (without extension)
TRG = dsc-v0
#put your C sourcefiles here
SRC = main.c dp.c xform.c
#put additional assembler source file here
ASRC =
#additional libraries and object files to link
# LIB = -lm
#additional includes to compile
INC =
#assembler flags
ASFLAGS = -Wa, -gstabs
#compiler flags
# CPFLAGS = -g -Os -Wall -Wstrict-prototypes -Wa,-ahlms=$(<:.c=.lst)
CPFLAGS = -g -O0 -Wall -Wstrict-prototypes -Wa,-ahlms=$(<:.c=.lst)
#linker flags
LDFLAGS = -Wl,-Map=$(TRG).map,--cref -lm
########### you should not need to change the following line #############
include $(AVR)/avrfreaks/avr_make
###### dependencies, add any dependencies you need here ###################
$(TRG).o : $(TRG).c
~
avr-gcc-list at http://avr1.org
- [avr-gcc-list] Problem with asin() and acos(),
jlf <=