1
/* Copyright (c) 2002 Michael Stumpf <mistumpf@de.pepperl-fuchs.com>
2
Copyright (c) 2006 Dmitry Xmelkov
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are met:
8
* Redistributions of source code must retain the above copyright
9
notice, this list of conditions and the following disclaimer.
10
* Redistributions in binary form must reproduce the above copyright
11
notice, this list of conditions and the following disclaimer in
12
the documentation and/or other materials provided with the
14
* Neither the name of the copyright holders nor the names of
15
contributors may be used to endorse or promote products derived
16
from this software without specific prior written permission.
18
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
POSSIBILITY OF SUCH DAMAGE. */
30
/* $Id: exp.S 2191 2010-11-05 13:45:57Z arcanum $ */
32
#if !defined(__AVR_TINY__)
37
/* float exp (float x);
38
The exp() function returns the value of e (the base of natural
39
logarithms) raised to the power of x.
42
#define X2BIG 0x43000000 /* exp(-X2BIG) < 0x00000001 */
43
#define FL_1_LN2 0x3fb8aa3b /* 1 / ln(2) */
45
/* second arg for modf(), ldexp() functions. */
54
.L_zr: rjmp _U(__fp_zero)
55
.L_nan: rjmp _U(__fp_nan)
60
brcs .L_nf ; A is not a finite number
61
cpi rA3, hhi8(X2BIG << 1)
62
brsh .L_tb ; A is too big (in absolute value)
63
; save sign and jump to positive
68
ldi rB0, lo8(FL_1_LN2)
69
ldi rB1, hi8(FL_1_LN2)
70
ldi rB2, hlo8(FL_1_LN2 | 0x800000) ; hidden '1'
71
ldi rB3, hhi8(FL_1_LN2 << 1) ; exponent
72
rcall _U(__mulsf3_pse)
73
; split A into fraction and integral parts
77
in exp_lo, SPL_IO_ADDR
78
in exp_hi, SPH_IO_ADDR
81
; calculate 2**(-x) for 0 <= x < 1
106
; inverse for positive arg.
116
.byte 0x63,0x42,0x36,0xb7 ; -0.0000108635
117
.byte 0x9b,0xd8,0xa7,0x1a,0x39 ; 0.0001474911
118
.byte 0x68,0x56,0x18,0xae,0xba ; -0.0013282400
119
.byte 0xab,0x55,0x8c,0x1d,0x3c ; 0.0096159779
120
.byte 0xb7,0xcc,0x57,0x63,0xbd ; -0.0555036542
121
.byte 0x6d,0xed,0xfd,0x75,0x3e ; 0.2402264688
122
.byte 0xf6,0x17,0x72,0x31,0xbf ; -0.6931471802
123
.byte 0x00,0x00,0x00,0x80,0x3f ; 1.0000000000
126
#endif /* !defined(__AVR_TINY__) */