@@ -22,7 +22,7 @@ Open for additions, including obscure weight metrics or
2222weight related math functions and constants.
2323
2424
25- #### Overview of conversions:
25+ ### Overview of conversions:
2626
2727```
2828 stone - lbs - ounce
@@ -34,7 +34,7 @@ weight related math functions and constants.
3434```
3535
3636
37- #### Related
37+ ### Related
3838
3939- https://github.com/RobTillaart/AtomicWeight
4040- https://github.com/RobTillaart/VolumeConverter
@@ -55,14 +55,14 @@ Functions are straightforward.
5555- ** float ounce2gram(float ounce)**
5656- ** float gram2ounce(float gram)**
5757- ** float gram2kilo(float gram)**
58- - ** float kilo2gram( float kilo)**
58+ - ** float kilo2gram(float kilo)**
5959- ** float lbs2ounce(float lbs)**
6060- ** float ounce2lbs(float ounce)**
6161- ** float stone2lbs(float stone)**
6262- ** float lbs2stone(float lbs)**
6363- ** float stone2kilo(float stone)**
6464- ** float kilo2stone(float kilo)**
65- - ** float US2metric(float stone, float lbs, float ounce)**
65+ - ** float US2metric(float stone, float lbs, float ounce)** returns kg.
6666- ** float metric2US(float kilo, float &stone, float &lbs, float &ounce)**
6767
6868
@@ -89,17 +89,58 @@ Internal representation is the gram as it the ISO standard.
8989Since version 0.3.0 the converter can also add different units.
9090
9191
92+ ### Example
93+
94+ To convert from one less known format to another just takes two calls, example:
95+
96+ ``` cpp
97+ weightConverter wc;
98+
99+ wc.setStone(24.2 );
100+ float x = wc.getRobie();
101+ ```
102+
103+ If you need to convert a lot of data between two formats, it is also possible to
104+ pre-calculate a factor so the conversion is faster.
105+ On an UNO R3 the gain goes up to 20%.
106+
107+
108+ ``` cpp
109+ weightConverter wc;
110+
111+ wc.setGram(1 ); // any non zero value will work.
112+ float factor = wc.getRobie() / wc.getStone();
113+ sum = 0 ;
114+ for (int i = 0 ; i < 1000 ; i++)
115+ {
116+ sum += i * factor;
117+ }
118+
119+ ```
120+
121+ or with the functions.
122+
123+ ```cpp
124+ float grams2stoneFactor = lbs2stone(ounce2lbs(gram2ounce(1)));
125+ sum = 0;
126+ for (int i = 0; i < 1000; i++)
127+ {
128+ sum += i * factor;
129+ }
130+ ```
131+
132+
92133## Interface
93134
94135``` cpp
95136#include " weight.h"
96137```
97138
98- #### Constructor
139+ ### Constructor
99140
100141- ** weightConverter()**
101142
102- #### Setters
143+ ### Setters
103144
104145- ** void setKilogram(float value = 0)**
105146- ** void setGram(float value = 0)**
@@ -120,7 +161,7 @@ Since version 0.3.0 the converter can also add different units.
120161- ** void setGrain(float value = 0)**
121162- ** void setCarat(float value = 0)**
122163
123- #### Adders
164+ ### Adders
124165
125166- ** void addKilogram(float value = 0)**
126167- ** void addGram(float value = 0)**
@@ -141,7 +182,7 @@ Since version 0.3.0 the converter can also add different units.
141182- ** void addGrain(float value = 0)**
142183- ** void addCarat(float value = 0)**
143184
144- #### Getters
185+ ### Getters
145186
146187- ** float getKilogram()**
147188- ** float getGram()**
0 commit comments