Giter Site home page Giter Site logo

Comments (5)

CoryCharlton avatar CoryCharlton commented on June 12, 2024

This issue might be the similar to #1401 where the double is being cast to a float and that causes a loss of precision.

from home.

Ellerbach avatar Ellerbach commented on June 12, 2024

Duplicate with #1429
See that specific issue for the answer.
I will close this issue.

from home.

MateuszKlatecki avatar MateuszKlatecki commented on June 12, 2024

@Ellerbach I must disagree that this is not a bug.
While it is understood that floating-point arithmetic can introduce small errors due to the way numbers are represented in binary, the numbers 14 and 92 can be exactly represented in the IEEE 754 standard used for floating-point arithmetic. Therefore, when converted to a string, they should retain their exact integer representation without any introduced imprecision.

Even (as you wrote) less smart languages like Python can deal with the numbers 14 or 92 but nanoFramework not.

Another thing that makes something wrong is that this code

double d = 14d;
Console.WriteLine($"{d}");

will print 13.999999999999999 and the use of float, a less precise variable,

float f = 14f;
Console.WriteLine($"{f}");

already works properly

Additionally, I looked around the code and there is even a test that checks this https://github.com/nanoframework/CoreLibrary/blob/main/Tests/NFUnitTestArithmetic/UnitTestFormat.cs#L189 but the selected number in the test does not cause a problem. Replacing -1234 with -14 would cause this test to fail.

from home.

Ellerbach avatar Ellerbach commented on June 12, 2024

OK, reopening the issue. That say, it depends of the device precision. Double is always available, but if not natively supported, will automatically fall back to float.

from home.

josesimoes avatar josesimoes commented on June 12, 2024

Actually, that's the other way around: float is always available. Double is natively supported if the platform has DP hardware support (or emulated).
Rational for this is explained in our docs here

from home.

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.