summaryrefslogtreecommitdiff
path: root/macros/generic/poormanlog/README
blob: fc5f096fdc52ea7e6c8773a795cdf4c29a03db66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
DOCUMENTATION OF POORMANLOG (v0.04, 2019/02/17)
===========================

(see License at bottom of this file)

The poormanlog.tex file has no dependencies. It provides (expandable)
macros for base 10 logarithms and powers of 10 with a bit less than 9
digits of precision (\PMLogZ and \PMPowTen), but its main use will be
in conjunction with xintexpr.sty, as it provides to the latter
functions log10() and pow10() and does on-demand modification of the
power operators ** or ^ to compute according to pow10(y*log10(x)).

This usage will become obsolete when xintexpr will natively implement
in arbitrary precision the log10() and pow10() functions.

The file can be used with Plain TeX (\input poormanlog) or as a
regular LaTeX package.


Example (with Plain TeX)
------------------------

    \input xintexpr.sty
    \input poormanlog.tex

    \xinteval{log10(3.14159265), pow10(2.71828183)}

    \poormanloghack{**}

    \xinteval{3.14159265**2.71828183}

    \poormanloghack{^}

    \xinteval{3.14159265^2.71828183}

    \bye


User interface
--------------

\PMLogZ{#1} expands in two steps.

input:  #1 is a mantissa ddddddddd (it may be an f-expandable macro)
        with exactly 9 digits (the first one must not be zero)
output: 9 digits xxxxxxxxx such that log10(d.dddddddd) is about 0.xxxxxxxxx

It seems from testing that absolute error is not much more than 1 unit in
the last place, and result differs from rounded mathematical value by at
most 1 unit in the 9th digit. (attention not rigorously proven).

\PMPowTen{#1} expands in two steps.

input:  #1 is (or expands to) exactly 9 digits ddddddddd representing
        0.ddddddddd
output: 9 digits xxxxxxxxx, first one not zero,
        such that 10^0.ddddddddd is about x.xxxxxxxx

It seems from testing that absolute error is less than 2 units in
the last place, and result differs from rounded mathematical value by at
most 2 units in the 9th digit. (attention not rigorously proven).

\PoorManLogBaseTen{#1}

  in presence of xintfrac this will accept input as recognized by xintfrac
  and produce the logarithm in base 10 with an error (believed to be at
  most) about 1 unit in the 9th (i.e. last) fractional digit.

  xintfrac may be loaded before or after.

\PoorManPowerOfTen{#1}

  in presence of package xintfrac this will accept input as recognized by
  xintfrac and produce the 10^#1 with 9 digits of float precision, with an
  error (believed to be) at most 2 units in the last place. Of course for
  this the input must be precise enough to have 9 fractional digits of
  **fixed point** precision.

  xintfrac may be loaded before or after.

\PoorManPower{#1}{#2}

  in presence of package xintfrac computes #1 to the power #2

  xintfrac may be loaded before or after.

log10()

  the log10() function is made available, if xintexpr.sty is loaded, for
  usage within \xinteval and \xintfloateval. If a log10() function is
  already defined in xintexpr it will not be overwritten

  xintexpr may be loaded before or after.

pow10()

  pow10() function is made available, if xintexpr.sty is loaded, for usage
  within \xinteval and \xintfloateval. If a pow10() function is already
  defined in xintexpr it will not be overwritten

  xintexpr may be loaded before or after.

modification of ** or ^ operators in \xintexpr and \xintfloatexpr

  \poormanloghack{**}
  \poormanloghack{^}

  They will now use pow10(y*log10(x)) formula to compute x to the power y

  Of course this means drop of precision, but allows non-integer exponents.
  (half-integer exponents are already accepted in \xintfloatexpr natively).

  ** xintexpr must have been loaded before **

Example with LaTeX :

    \documentclass{article}
    \usepackage{xintexpr}
    \usepackage{poormanlog}% makes log10() and pow10() available
    \poormanloghack{**}    %  modifies ** operator
    \begin{document}
    \xinteval{3.14159265**2.71828183, log10(3.14159265), pow10(2.71828)}
    \end{document}


LICENSE
-------

Copyright (C) 2019, Jean-Francois Burnol.

This Work may be distributed and/or modified under the conditions of the
LaTeX Project Public License version 1.3c. This version of this license
is in

    <http://www.latex-project.org/lppl/lppl-1-3c.txt>

and version 1.3 or later is part of all distributions of LaTeX version
2005/12/01 or later.

This Work has the LPPL maintenance status `author-maintained'.

The Author of this Work is Jean-Francois Burnol.

This Work consists of files poormanlog.tex, poormanlog.sty and the
README.