ChrisOS Research ProjectOperating systems · language systems · graphics · machine emulation
DOCUMENTATION ARCHIVEMAIN BRANCH
ChrisOS/Source reference: LIB/MATH.CC

Source reference: LIB/MATH.CC

Deterministic source record. The complete textual file is reproduced below; this page does not replace architectural interpretation in the authored chapters.

File identity

Field Value
Path LIB/MATH.CC
Lines 65
Bytes 1011
SHA-256 9b5df9c50730b98d417021840be072a72302ba94522ccef31a806adab8435494
ChrisOS revision da3df29cb397932c43d32373871fb9380e688ade

Detected syntactic dependencies

Line Include
1 LIB/MATH.H

Detected symbols

Line Symbol
3 fabsf
8 fabs
12 tan
24 atan
50 sqrt

Complete source

The following block is the complete textual file at the recorded revision. No lines are elided, abbreviated or paraphrased.

#include "LIB/MATH.H"

float fabsf(float x) {
    if (x < 0.0) return -x;
    return x;
}

float fabs(float x) {
    return fabsf(x);
}

float tan(float x) {
    float c;
    c = cos(x);
    if (c < 0.0001 && c > -0.0001) {
        if (c < 0.0)
            c = -0.0001;
        else
            c = 0.0001;
    }
    return sin(x) / c;
}

float atan(float x) {
    int sign;
    int inv;
    float z;
    float z2;
    float r;
    sign = 0;
    inv = 0;
    if (x < 0.0) {
        sign = 1;
        x = -x;
    }
    if (x > 1.0) {
        inv = 1;
        x = 1.0 / x;
    }
    z = x;
    z2 = z * z;
    r = z * (1.0 + z2 * (-0.3333333 + z2 * (0.2 + z2 * (-0.142857 + z2 * 0.10186))));
    if (inv)
        r = 1.57079633 - r;
    if (sign)
        r = -r;
    return r;
}

float sqrt(float x) {
    float g;
    int i;
    if (x <= 0.0)
        return 0.0;
    g = x;
    if (g < 1.0)
        g = 1.0;
    i = 0;
    while (i < 12) {
        g = 0.5 * (g + x / g);
        i = i + 1;
    }
    return g;
}

Role of this record

The atlas guarantees file-by-file traceability. Responsibility, invariants, ownership, concurrency, security, performance and subsystem interactions belong in authored chapters and must cite this file when applicable.

Document record ID: source-9b5df9c50730b98d Reviewed source: da3df29cb397 Class: generated-source-reference