HaikuDepot: notify work status from main window
[haiku.git] / src / libs / mapm / mapm_lg4.c
blob8b20d252e9c2296e5d7f74702545adbfd7f9224b
2 /*
3 * M_APM - mapm_lg4.c
5 * Copyright (C) 2003 - 2007 Michael C. Ring
7 * Permission to use, copy, and distribute this software and its
8 * documentation for any purpose with or without fee is hereby granted,
9 * provided that the above copyright notice appear in all copies and
10 * that both that copyright notice and this permission notice appear
11 * in supporting documentation.
13 * Permission to modify the software is granted. Permission to distribute
14 * the modified code is granted. Modifications are to be distributed by
15 * using the file 'license.txt' as a template to modify the file header.
16 * 'license.txt' is available in the official MAPM distribution.
18 * This software is provided "as is" without express or implied warranty.
22 * $Id: mapm_lg4.c,v 1.3 2007/12/03 01:43:32 mike Exp $
24 * This file contains the LOG_NEAR_1 function.
26 * $Log: mapm_lg4.c,v $
27 * Revision 1.3 2007/12/03 01:43:32 mike
28 * Update license
30 * Revision 1.2 2003/06/02 18:08:45 mike
31 * tweak decimal places and add comments
33 * Revision 1.1 2003/06/02 17:27:26 mike
34 * Initial revision
37 #include "m_apm_lc.h"
39 /****************************************************************************/
41 calculate log (1 + x) with the following series:
44 y = ----- ( |y| < 1 )
45 x + 2
48 [ 1 + y ] y^3 y^5 y^7
49 log [-------] = 2 * [ y + --- + --- + --- ... ]
50 [ 1 - y ] 3 5 7
53 void M_log_near_1(M_APM rr, int places, M_APM xx)
55 M_APM tmp0, tmp1, tmp2, tmpS, term;
56 int tolerance, dplaces, local_precision;
57 long m1;
59 tmp0 = M_get_stack_var();
60 tmp1 = M_get_stack_var();
61 tmp2 = M_get_stack_var();
62 tmpS = M_get_stack_var();
63 term = M_get_stack_var();
65 tolerance = xx->m_apm_exponent - (places + 6);
66 dplaces = (places + 12) - xx->m_apm_exponent;
68 m_apm_add(tmp0, xx, MM_Two);
69 m_apm_divide(tmpS, (dplaces + 6), xx, tmp0);
71 m_apm_copy(term, tmpS);
72 m_apm_multiply(tmp0, tmpS, tmpS);
73 m_apm_round(tmp2, (dplaces + 6), tmp0);
75 m1 = 3L;
77 while (TRUE)
79 m_apm_multiply(tmp0, term, tmp2);
81 if ((tmp0->m_apm_exponent < tolerance) || (tmp0->m_apm_sign == 0))
82 break;
84 local_precision = dplaces + tmp0->m_apm_exponent;
86 if (local_precision < 20)
87 local_precision = 20;
89 m_apm_set_long(tmp1, m1);
90 m_apm_round(term, local_precision, tmp0);
91 m_apm_divide(tmp0, local_precision, term, tmp1);
92 m_apm_add(tmp1, tmpS, tmp0);
93 m_apm_copy(tmpS, tmp1);
94 m1 += 2;
97 m_apm_multiply(tmp0, MM_Two, tmpS);
98 m_apm_round(rr, places, tmp0);
100 M_restore_stack(5); /* restore the 5 locals we used here */
102 /****************************************************************************/