@@ -237,33 +237,39 @@ We have been working on the automatic replacement of the primitive types
float/double (as well as their "standard wrapper" counterpart Float/Double) by
objects that realize richer number models.
COJAC illustrates this with an option `-BDP nDigits` that turns float/double into `BigDecimal` with a specific number of significant digits. There are still limitations, but... yes we did it!
Now our poor numbers can be enriched in various ways, that we only start to
study. There are still limitations, but... yes we did it!
Here is an example to show the idea:
## 3.1 Our wrapping mechanism
```
prompt> java HelloMrCojac
3.232315809405594
3.1425916543395442
3.1415936535887745
Our wrapping mechanism... is automatic! Just tell us which number model you want to
The magic methods are model-specific (see below), but every number wrapper will at least
provide those two methods:
```
public static String COJAC_MAGIC_wrapperName();
public static String COJAC_MAGIC_toString(double n); // internal representation
```
And the corresponding code:
## 3.2 Number model "BigDecimal"
COJAC illustrates this with an option `-BDP nDigits` that turns float/double into `BigDecimal` with a specific number of significant digits. There are still limitations, but... yes we did it!
Here is a small demo program:
```
public class HelloMrCojac {
public static String COJAC_MAGIC_DOUBLE_toStr(double n) { return ""; }
public static String COJAC_MAGIC_toString(double n) { return ""; }
public static void main(String[] args) {
double p1=approxPi(10);
...
...
@@ -286,6 +292,64 @@ public class HelloMrCojac {
}
}
```
A normal run will produce that output:
```
prompt> java HelloMrCojac
3.232315809405594
3.1425916543395442
3.1415936535887745
```
And now, let's compute with twice as much significant numbers: