GithubHelp home page GithubHelp logo

Comments (7)

oleg-nesterov avatar oleg-nesterov commented on June 14, 2024

It is clear why -single/-double makes a difference in this case,
but...

To be honest, I never really understood the purpose of ma.EPSILON.
And what is it? Say,

    doubleprecision EPSILON = 2.2204460492503131e-016;

is it DBL_MIN? Or DBL_TRUE_MIN?

Nevermind. In any case I'd say it should be used with care.

process = (1.0 + ma.EPSILON/2.0) > 1.0 correctly returns 0 when
compiled in -double

OK, lets suppose that "0" is correct in this case. Now consider

    import("stdfaust.lib");

    process =
            (0.0 + ma.EPSILON/2.0) > 0.0,
            (0.5 + ma.EPSILON/2.0) > 0.5,
            (1.0 + ma.EPSILON/2.0) > 1.0;

compiled in double, it outputs

    1, 1, 0

Doesn't look consistent but what can we do? and do we really care?

Oleg.

from faust.

sletz avatar sletz commented on June 14, 2024
#include <iostream>
#include <cfloat>

int main() {
    bool a = (0.0f + FLT_EPSILON / 2.0f) > 0.f;
    bool b = (0.5f + FLT_EPSILON / 2.0f) > 0.5f;
    bool c = (1.f + FLT_EPSILON / 2.0f) > 1.f;


    std::cout << "a: " << a << std::endl;
    std::cout << "b: " << b << std::endl;
    std::cout << "c: " << c << std::endl;
    
    bool d = (0.0f + DBL_EPSILON / 2.0f) > 0.f;
    bool e = (0.5f + DBL_EPSILON / 2.0f) > 0.5f;
    bool f = (1.f + DBL_EPSILON / 2.0f) > 1.f;

    std::cout << "d: " << d << std::endl;
    std::cout << "e: " << e << std::endl;
    std::cout << "f: " << f << std::endl;

    return 0;
}

from faust.

dariosanfilippo avatar dariosanfilippo commented on June 14, 2024

from faust.

oleg-nesterov avatar oleg-nesterov commented on June 14, 2024

Ah. Yes, yes, I know. And I too wrote the similar program to verify.

Sorry for confusion. When I said "Doesn't look consistent" I meant "Doesn't look consistent but in fact correct".

My only point was, again, in any case ma.EPSILON should be used with care.
It is not immediately clear that, again,

    process = (0.5 + ma.EPSILON/2.0) > 0.5;

and
process = (1.0 + ma.EPSILON/2.0) > 1.0;

do not output the same result.

And I think we do not really care.

But I agree that the fact it depends on -single/-double make the things worse.

from faust.

oleg-nesterov avatar oleg-nesterov commented on June 14, 2024

I think that it is defined as the smallest quantity, let's call it EPS, for
which (1.0 + EPS) > 1.0 returns true.

OK, quite possible, then ma.EPSILON == nextafter(1.0,2.0) - 1.0

And this means that even a more simple example can surprise the user:

    import("stdfaust.lib");

    process =
            (1.0 + ma.EPSILON) > 1.0,
            (2.0 + ma.EPSILON) > 2.0;

compiled with -double outputs

    output0[i0] = FAUSTFLOAT(1);
    output1[i0] = FAUSTFLOAT(0);

Again, this is correct in that this is how the FP math works.

But again, this means that ma.EPSILON should be used with care.
And "the smallest quantity" depends on the usage, while *.lib
blindly use ma.ma.EPSILON assuming it always fits the needs.

from faust.

sletz avatar sletz commented on June 14, 2024

I guess we want ma.EPSILON to exactly behave as the FP norm says, in -single and -double mode, no more no less (and which is not currently the case).

from faust.

sletz avatar sletz commented on June 14, 2024

Improved documentation: https://faustlibraries.grame.fr/libs/maths/#maepsilon

from faust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.