Giter VIP home page Giter VIP logo

Comments (2)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 24, 2024
[deleted comment]

from libfixmath.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 24, 2024
Hi,

As far as I can tell, the problem also occurs in the Fix16(const fix16_t) 
constructor. So Fix16 myInteger(42); yields a fraction instead of a whole 
number. There is a solution, but it breaks the semantics of the existing 
interface.

- Add a signed and unsigned integer constructor that has whole number semantics 
(i.e. treats the value as an integer).
- Remove the Fix16(const fix16_t) constructor, or make it protected and add a 
dummy boolean second argument. Maybe making the constructor explicit has the 
same effect. That prevents unwanted automatic casts. It should then only be 
used to define internal constants, although this does not appear to be 
necessary in the current implementation. So removing the constructor altogether 
appears preferable.
- Remove all +, -, *, /, +=, -=, *=, and /= operators that do not take a Fix16 
argument as rvalue. The compiler will use the constructors to cast/transform 
the rvalue, so everything still works. The same applies to the sadd, ssub, smul 
and sdiv operations.
- Remove operator fix16_t(). It is dangerous when assigning a Fix16 to an 
integer.
- Ideally make the class attribute 'value' protected. Provide a raw() operation 
that returns the value if needed.

So yes, these changes affect the existing interface, but that is not 
necessarily a bad thing. The current interface leaves a thing or two to be 
desired in terms of preventing honest mistakes on the part of the user. 
Personally I value preventing such mistakes over maintaining the current 
interface.

Original comment by [email protected] on 25 Jul 2011 at 5:12

from libfixmath.

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.