Math primitives on larger .net num representations. INT64...

Using (or providing) Microsoft.NET Classes

Math primitives on larger .net num representations. INT64...

Postby norbertjurkiewicz84 on Thu Jul 27, 2017 1:27 pm

What is the recommended way of dealing with simple math on these larger .NET values?

I.e. UInt64 / 12
I.e. Int64 * 12

Code: Select all
 ⎕using←'System' 'Dyalog'
 val←Convert.ToUInt64⊂ '23424234'


The interpreter does not extend the primitives to these larger values like Int32 and Floats.

As you see I get a DOMAIN ERROR.

Code: Select all

Converting the number to text and executing it is one dirty workaround.

Code: Select all
   (1⊃⎕vfi val.ToString ⍬)÷12

   (⍎ val.ToString ⍬)÷12

Using a class that contains Divide is one option

Code: Select all
    Decimal.Divide val 12

but is that the best way?

User avatar
Posts: 61
Joined: Mon Nov 01, 2010 7:26 pm

Re: Math primitives on larger .net num representations. INT6

Postby JohnD|Dyalog on Fri Jul 28, 2017 8:31 am

Int64s and UInt64s are returned as objects (aka namespaces) to the interpreter. To convert these to DECFs on which (if ⎕FR is set to 1287), Dyalog can perform arithmetic, I'd recommend something like:

Convert.ToDecimal val

This will work on all sort of "types" of val:


Note, that if you don't need the extra precision that DECFs give you over doubles (which only offer 53 bits of integer precision), you can Convert.ToDouble, and leave DR at 645.

Note also, that technically we could auto-convert all incoming Int64 and UInt64s to DECFs but that would be a breaking change from pre-DECF versions of the interpreter so we decided not to do that.
User avatar
Posts: 70
Joined: Wed Oct 01, 2008 9:35 am

Return to Microsoft.NET

Who is online

Users browsing this forum: No registered users and 1 guest