January 12, 2018
On Monday, 8 January 2018 at 22:16:25 UTC, rumbu wrote:
> Source code: https://github.com/rumbu13/decimal/blob/master/src/decimal.d
>
> Documentation: http://rumbu13.github.io/decimal/doc/decimal.html

This looks really good. I think with a little work it would be ready for proposal into Phobos. I only wish I knew about it two months ago :/
January 13, 2018
On Friday, 12 January 2018 at 13:09:42 UTC, kdevel wrote:
>
> $ dmd nosine.d decimal.git/libdecimal.a
> decimal/package.d(10505): Error: undefined identifier decimalCapAngle

Sorry, broke some code when I made the split. Now it's working.
January 13, 2018
On Saturday, 13 January 2018 at 01:30:12 UTC, rumbu wrote:
> On Friday, 12 January 2018 at 13:09:42 UTC, kdevel wrote:
>>
>> $ dmd nosine.d decimal.git/libdecimal.a
>> decimal/package.d(10505): Error: undefined identifier decimalCapAngle
>
> Sorry, broke some code when I made the split. Now it's working.

$ dub
Performing "debug" build using dmd for x86_64.
decimal ~master: building configuration "library"...
src/test/test.d(4,5): Error: only one main allowed. Previously found main at src/benchmark/benchmark.d(143,5)
dmd failed with exit code 1.

January 13, 2018
On Saturday, 13 January 2018 at 13:44:20 UTC, kdevel wrote:
> $ dub
> Performing "debug" build using dmd for x86_64.
> decimal ~master: building configuration "library"...
> src/test/test.d(4,5): Error: only one main allowed. Previously found main at src/benchmark/benchmark.d(143,5)
> dmd failed with exit code 1.

diff --git a/dub.json b/dub.json
index c48899f..d8882c1 100644
--- a/dub.json
+++ b/dub.json
@@ -10,16 +10,16 @@
     "configurations": [
         {
             "name": "library",
-            "excludedSourceFiles": [ "src/benchmark.d", "src/test.d" ]
+            "excludedSourceFiles": [ "src/benchmark/benchmark.d", "src/test/test.d" ]
         },
         {
             "name": "unittest",
-            "excludedSourceFiles": [ "src/benchmark.d", "src/test.d" ]
+            "excludedSourceFiles": [ "src/benchmark/benchmark.d", "src/test/test.d" ]
         },
         {
             "name": "benchmark",
             "targetType": "executable",
-            "excludedSourceFiles": [ "src/test.d" ]
+            "excludedSourceFiles": [ "src/test/test.d" ]
         }
     ]
 }

January 13, 2018
On Saturday, 13 January 2018 at 13:49:59 UTC, kdevel wrote:
> diff --git a/dub.json b/dub.json
> index c48899f..d8882c1 100644
> --- a/dub.json
> +++ b/dub.json
> @@ -10,16 +10,16 @@
>      "configurations": [
>          {
>              "name": "library",
> -            "excludedSourceFiles": [ "src/benchmark.d", "src/test.d" ]
> +            "excludedSourceFiles": [ "src/benchmark/benchmark.d", "src/test/test.d" ]
>          },

Now my code does no longer compiles against the decimal package. This is my directory structure:

   dlang-decimal/
      decimal -> decimal.git/src
      decimal.git                        [created by git clone <url> decimal.git]
      nosine.d

$ dmd nosine decimal.git/libdecimal.a
nosine.d(3): Error: module decimal is in file 'decimal.d' which cannot be read
import path[0] = /.../dmd2/linux/bin64/../../src/phobos
import path[1] = /.../dmd2/linux/bin64/../../src/druntime/import
make: *** [nosine] Fehler 1

January 13, 2018
On Saturday, 13 January 2018 at 13:56:20 UTC, kdevel wrote:
>
>
> Now my code does no longer compiles against the decimal package. This is my directory structure:


I received a suggestion to reorganize the file structure because of some bug in dub (https://issues.dlang.org/show_bug.cgi?id=11847). The dub.json remained out of sync.

I changed it, but I am not 100% sure that it's working. I am not experienced with dub, If someone wants to maintain dub.json, I will be more than happy to accept any pull request.

Personally I hate dub because it's polluting my %APPDATA% folder and each time I connect my laptop to the company domain network, I must wait to sync zillions of files.


January 13, 2018
On Saturday, 13 January 2018 at 14:43:53 UTC, rumbu wrote:
> Personally I hate dub because it's polluting my %APPDATA% folder and each time I connect my laptop to the company domain network, I must wait to sync zillions of files.

Dub uses the roaming profile directory for its cache storage. This needs to be changed to the local profile directory. I'll submit a PR for this at some point in the near future.

I have the dub build working locally and will be submitting another PR for that shortly. Unless anyone has any valid complaints, I'd like to convert dub.json to SDL format so that I can add comments without trying to work around the JSON syntax limitations.
January 13, 2018
On Saturday, 13 January 2018 at 14:43:53 UTC, rumbu wrote:
> On Saturday, 13 January 2018 at 13:56:20 UTC, kdevel wrote:
>>
>> Now my code does no longer compiles against the decimal package. This is my directory structure:
>
> I received a suggestion to reorganize the file structure because of some bug in dub (https://issues.dlang.org/show_bug.cgi?id=11847). The dub.json remained out of sync.
>
> I changed it, but I am not 100% sure that it's working. I am not experienced with dub, If someone wants to maintain dub.json, I will be more than happy to accept any pull request.

I only invoked dub in order to generate libdecimal.a

> Personally I hate dub because it's polluting my %APPDATA% folder and each time I connect my laptop to the company domain network, I must wait to sync zillions of files.

I have now the following directory structure:

   dlang-decimal/
      decimal -> decimal.git/src/decimal/
      decimal.git/                             [git cloned <url> decimal.git]
         libdecimal.a
         src/
            decimal/
               floats.d
               floats.di
               integrals.d
               integrals.di
               package.d
               package.di
               ranges.d
               ranges.di
               sinks.d
               sinks.di
      nosine.d

I have generated the .di files with dmd -H *.d within the src/decimal directory. Now dmd in unwilling to compile:

$ dmd nosine.d decimal.git/libdecimal.a
decimal/integrals.di(537): Error: xadd cannot be interpreted at compile time, because it has no available source code
decimal/integrals.di(567):        called from here: xadd(result, z)
decimal/integrals.di(121):        called from here: fma(this, 10u, cast(uint)(cast(int)c - 48), ovf)
decimal/integrals.di(978):        called from here: unsigned(0LU, 0LU).this("100000000000000000000")
[the four lines repeat untill 77 lines are printed]

How come?
January 13, 2018
On Saturday, 13 January 2018 at 14:43:53 UTC, rumbu wrote:
> I received a suggestion to reorganize the file structure because of some bug in dub (https://issues.dlang.org/show_bug.cgi?id=11847). The dub.json remained out of sync.
>
> I changed it, but I am not 100% sure that it's working. I am not experienced with dub, If someone wants to maintain dub.json, I will be more than happy to accept any pull request.

I can compile/run the nosine.d now. But implicit conversion between decimalX and float/double/real does not seem to work. I came across this in

sinus.d
```
import std.stdio;
import std.math;
import decimal;

void main ()
{
   real r;
   for (r = 1; r < 6; r += .1L) {
      decimal128 d = r;
      auto dsin = sin (d);
      auto rsin = sin (r);
      real delta = dsin - rsin;
      writefln ("%9.2f %30.24f %12.4g", r, rsin, dsin, delta);
   }
}
```

$ dmd sinus.d decimal.git/libdecimal.a
sinus.d(12): Error: cannot implicitly convert expression dsin.opBinary(rsin) of type Decimal!128 to real

I tried to change the subtraction to

```
      real delta = dsin;
      delta -= rsin;
```

getting

sinus_e1.d(12): Error: cannot implicitly convert expression dsin of type Decimal!128 to real

Changes this into

```
      real delta = dsin.to!real;
      delta -= rsin;
```
sinus_e2.d(12): Error: template decimal.to cannot deduce function from argument types !(real)(Decimal!128), candidates are:
decimal/package.d(5814):        decimal.to(T, D)(auto ref const D x, const RoundingMode mode) if (isIntegral!T && isDecimal!D)
decimal/package.d(5832):        decimal.to(F, D)(auto ref const D x, const RoundingMode mode) if (isFloatingPoint!F && isDecimal!D)


to no avail. Also

```
      real delta = cast(real) dsin;
```

did not succeed:

decimal/package.d(933): Error: undefined identifier mode, did you mean template modf(D)(auto ref const D x, ref D y) if (isDecimal!D)?
sinus_e3.d(12): Error: template instance decimal.Decimal!128.Decimal.opCast!real error instantiating

Also

```
      real delta = dsin.to!(real, RoundingMode.tiesToEven);
```

ain't work:
sinus_e4.d(12): Error: template decimal.to cannot deduce function from argument types !(real, cast(RoundingMode)0)(Decimal!128), candidates are:
decimal/package.d(5814):        decimal.to(T, D)(auto ref const D x, const RoundingMode mode) if (isIntegral!T && isDecimal!D)
decimal/package.d(5832):        decimal.to(F, D)(auto ref const D x, const RoundingMode mode) if (isFloatingPoint!F && isDecimal!D)

How can I convert a decimalX to float/double/real?
January 13, 2018
On Saturday, 13 January 2018 at 17:19:31 UTC, kdevel wrote:

> How can I convert a decimalX to float/double/real?

Implicit conversion is not available at library level, D does not have an implicit conversion operator;

Subtracting decimalX - real will result in a decimalX. This was a design decision, but I'm open to suggestions.

The following code works:

    real r;
    for (r = 1; r < 6; r += .1L) {
        decimal128 d = r;
        auto dsin = sin (d);
        auto rsin = sin (r);
        auto delta = dsin - rsin; //delta is decimal128
        writefln ("%9.2f %30.24f %30.24f %12.4g", r, rsin, dsin, delta);
    }

if you really need to convert decimalX values to floating point counterparts, you'll need to cast them:

x = cast(real)somedecimalvalue;

(but update your files before this, I discovered a bug in opCast)