File: sinf_fit.gnuplot

package info (click to toggle)
vc 1.4.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,552 kB
  • sloc: cpp: 19,220; ansic: 15,669; sh: 453; xml: 186; makefile: 30
file content (31 lines) | stat: -rw-r--r-- 1,040 bytes parent folder | download | duplicates (2)
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
log2(x) = log(x)/log(2)
exponent(x) = floor(log2(abs(x)))
mantissa(x) = int(abs(x) * 2**(23-exponent(x)) + .5) * 2**-23
round_to_float(x) = sgn(x) * mantissa(x) * 2**exponent(x)
sqr(x) = round_to_float(x * x)
ulp(x) = x == 0 ? 0 : 2**(exponent(x)-23)

b = round_to_float(0.166667)
c = round_to_float(1/5!)
d = round_to_float(1/7!)
e = round_to_float(1/9!)

sinf_fit(x) = \
  round_to_float( \
    round_to_float( \
      round_to_float( \
        round_to_float( \
        round_to_float( \
          round_to_float(0 \
                       + round_to_float(e)) * sqr(x) \
                       - round_to_float(d)) * sqr(x) \
                       + round_to_float(c)) * sqr(x) \
                       - round_to_float(b)) * sqr(x) \
                       + 1) * x);

fit sinf_fit(x) 'sincosd.dat' using 1:2 via b,c,d,e
#plot 'sincosd.dat' using 1:($2-sinf_fit($1)),ulp(sin(x))
plot 'sincosd.dat' using 1:(sinf_fit($1)-$2) with dots, '' using 1:(.5*ulp($2)) with dots, '' using 1:(-.5*ulp($2)) with dots
#pause -1

# vim: ft=gnuplot