Code Monkey home page Code Monkey logo

fixed's Introduction

Fixed

Defines a fixed point type.

A fixed point number is a number with a fixed number of decimal places. The number of decimal places never varies, unlike floating point types, where the number of decimal places varies depending on the value.

Fixed point values are used wherever fractions are needed, but floating point values are undesirable or impractical, eg currencies.

Fixed point values are precise (no rounding issues) and are integral in behaviour (division and modulo work the same as they do for integers).

Documentation

See doc.html for reference documentation.

Usage

Import jaypha.fixed into your project. Instantiate with the desired scale.

Example:

auto v = Fixed!2(23); // Creates a value with 2 decimal places.

Fixed implements all the arithmetic, comparison and assignment operators, as well as casting to long and double types.

In addition the following methods are defined

pure nothrow auto conv(uint newScale)()

Converts to a different number of decimal places.

@property string asString()

Convert to a string. Includes the full number of decimal places.

fix1, fix2 and fix3 are defined as aliases of Fixed!1, Fixed!2 and Fixed!3 respectively.

Example

fix3 value = 21.44;
value += 12;
assert(value.asString == "33.440");

License

Distributed under the Boost License.

Contact

[email protected]

Todo

fixed's People

Contributors

jaypha avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.