Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zweidenker/units
A simple package for units
https://github.com/zweidenker/units
Last synced: about 2 months ago
JSON representation
A simple package for units
- Host: GitHub
- URL: https://github.com/zweidenker/units
- Owner: zweidenker
- License: mit
- Created: 2018-06-21T13:38:41.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-08-09T11:11:45.000Z (over 1 year ago)
- Last Synced: 2024-08-03T17:10:18.936Z (5 months ago)
- Language: Smalltalk
- Size: 43.9 KB
- Stars: 16
- Watchers: 9
- Forks: 9
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Units
A simple package for Units management in Pharo.
## Installation
To install Units on your Pharo image you can just execute the following script:
```Smalltalk
Metacello new
githubUser: 'zweidenker' project: 'Units' commitish: 'master' path: 'src';
baseline: 'Units';
load
```To add Units to your baseline just add this:
```Smalltalk
spec
baseline: 'Units'
with: [ spec repository: 'github://zweidenker/Units:master/src' ]
```Note that you can replace the #master by another branch or a tag.
## Examples
### Create units
```Smalltalk
15 units: #gram. "15 grams"
15 units: #newton. "15 newtons"
15g. "15 grams"
(15 units: #mile) / (1 units: #second). "15 miles per second"
15mi/1 s. "15 miles per second"
3m * 3m. "9 square metres"
```
### Compare units
```Smalltalk
1cm > 2cm. "false"
1cm >= 1cm. "true"
15 cm = 150 mm. "true"
15cm > 1500mm. "false"
```
### Operations on units
```Smalltalk
1g + 1g. "2 grams"
1kg + 1g. "(1001/1000) kilograms"
1g + 1kg. "1001 grams"
14foot + 15m. "63.212598425196845 feet"
10g - 1g. "9 grams"
9 * 1g. "9 grams"
9g * 3. "27 grams"
100g / 2. "50 grams"
```
### Convertions
```Smalltalk
15mi/1h convertTo: (Unit m / Unit s). "6.7056 metres per second"
3kg factor: Unit g. "3000 grams"
(3 units: #newton) factor: Unit g. "3000 gram metres per square second"
```