File: fold_pi4_single.m

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 (17 lines) | stat: -rw-r--r-- 616 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function x = fold_pi4_single(x)
  x = round_to_float(x);
  expected = round_to_float(x - floor(x / (pi/2) + .5)*(pi/2));
  y = round_to_float(floor(x * round_to_float(2/pi) + .5)) * 2;
  printf("y = %i = %s\n", y, hexfloat(y));
  while(y > 0)
    p2 = 2^floor(log2(y));
    y -= p2;
    diff = p2 * round_to_float(pi/4);
    x -= diff;
    printf("(x -= %s) -> %s\n", hexfloat(diff), hexfloat(x));
  endwhile
  diff = p2 * round_to_float(pi/4 - round_to_float(pi/4));
  x -= diff;
  printf("(x -= %s) -> %s\n", hexfloat(diff), hexfloat(x));
  printf("expected result:         %s\n", hexfloat(expected));
endfunction