Coder Social home page Coder Social logo

ba-st / aconcagua Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mtaborda/aconcagua

14.0 6.0 3.0 600 KB

Measures as first class objects, that is, an object that encapsulates a number with its unit.

License: MIT License

Smalltalk 100.00%
smalltalk pharo measures

aconcagua's Introduction

Aconcagua

Logo

This model represents measures as first class objects, that is, an object that encapsulates a number with its unit.

Unit Tests Coverage Status Group loading check Markdown Lint

GitHub release Pharo 8.0 Pharo 9.0 Pharo 10 Pharo 11

GS64 3.7.0 GS64 3.7.1

Named after Aconcagua, the highest mountain in both the southern and western hemispheres. It is located in the Andes, in the Mendoza Province, Argentina.

This representation allows the programmer to use measures in arithmetic expressions as if they were numbers, but with the advantage of providing explicit information to the system, specifically, the measures units. See Arithmetic with measurements on dynamically-typed object-oriented languages or download the article PDF for more about this.

Quick links

License

  • The code is licensed under MIT.
  • The documentation is licensed under CC BY-SA 4.0.

Quick Start

Installation

To load the project in a Pharo image, or declare it as a dependency of your own project follow these instructions.

Contributing

Check the Contribution Guidelines

aconcagua's People

Contributors

fedemiodo avatar fortizpenaloza avatar gcotelli avatar mtaborda avatar seandenigris avatar ytsejam78 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

aconcagua's Issues

Converting MeasureBag to Amount of Unit

I tried the following and got aMeasureBag back, but I expected 10.21

amount := 10.21.
dollarAmt := amount // 1.
centsAmt := (amount \\ 1 * 100) asInteger.
total := (AmDollar new * dollarAmt) +
(centsAmt * AmCent new).
total / (1 * AmDollar new).

Also I tried convertTo: but got a subclassResponsibility error...

where:

AmDollar class>>#new
	^ super new
		initializeBaseUnit: AmCent new
		conversionFactor: 100
		nameForOne: 'dollar'
		nameForMany: 'dollars'
		sign: 'USD'

and

AmCent class>>#new
	^ super new
		initializeNameFomOne: 'cent'
		nameForMany: 'cents'
		sign: 'c USD'

Money Documentation

I'd like to add some information to the docs about modeling money. This has come up many times on the MLs of the various Smalltalk flavors, and Aconcagua has been mentioned many times. However, even after reading and re-reading, I'm still not clear how Aconcagua addresses the float problem. Namely, by way of example:

result := 0.
interval := 10.21.
10000 timesRepeat: [ result := result + interval ].
result = 102100.00000001806 "(not 102100.0)"

At first, I thought that using ScaledDecimal might help, but there were various comments saying that Pharo's ScaledDecimal is ill-conceived and maybe FixedDecimal would be better.

Another solution I thought of would be to convert any decimal money to dollars and cents and only convert back for display. For example:

Float>>dollars
	^ (AmDollar uniqueInstance * self // 1) +
(self \\ 1 * 100) asInteger cents.

Any feedback or input would be appreciated...

@gcotelli @mtaborda @hernanwilkinson

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.