aboutsummaryrefslogtreecommitdiff
path: root/docs/notes/math.txt
blob: 3d92ade76c29ce9ee9f2ed8a46c0fb2421d686b2 (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

Imaginary type
--------------

Can be implemented with a suffix.

    1i
    1.2i
    3 - 1i
    1ie9
    
    // This should probably not be allowed
    2e3i // 2*10^(3i)

TOOD: how should complex arithmetic work?


Floating point exceptions
-------------------------

Problem 1: fp flags

    Solution 1a. Have a pop_exception function

        double z = (3*x-i) / y;
        fp:pop_exception();
        //  Problem: Any function might pop the fp flags!


    Solution 1b. Save and restore flags

        using (fp:flags) { // fp flags are saved
            
            double z = (3*x-i) / y;
            if (fp:flags.bad()) leave;
            
        } // fp flags are restored
    

Problem 2: fp traps

    Solution 2a. Change behaviour with a function
    
        fp:trap:make_abort();
        fp:trap:make_ignore();

    Solution 2a. Use "using"

        using (fp:trap) {
            // ...
            using (fp:notrap) {
                // ...
            }
        }

Integer exceptions
------------------

Same problems as with fp exceptions. The integer exceptions are:

  * Overfow/underflow
      - from aritmetic operations
      - from negation
      - from conversion from floating point
  * Division by zero
  * More?


Links
-----
  * http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf