Converting 128 bit decimal to Float

General APL language issues
Post Reply
paulmansour
Posts: 431
Joined: Fri Oct 03, 2008 4:14 pm

Converting 128 bit decimal to Float

Post by paulmansour »

In V13 we have 128 bit decimal numbers. These can show up regardless of the setting of []FR. You can get them back when dealing with .NET or ADO.

I don't really want to deal with them at the moment, and want to just convert them from type 1287 to type 645.

The documentation suggests that one just uses format and execute, but does not offer an example.

Does this mean that:

Code: Select all

⍎⍕Values


is the proper idiom for converting a vector of 1278's to 645's? It seems to work, but I'm not sure if it only works in the particular case I have or if the solution is universal.

Thanks,

Paul
paulmansour
Posts: 431
Joined: Fri Oct 03, 2008 4:14 pm

Re: Converting 128 bit decimal to Float

Post by paulmansour »

Also, this addition of 1287 breaks a fair amount of existing code. For example, in ADO, the enumerated type adCurrency used to come back as a two item integer vec. Not any more. But I guess in the long run that's a good thing.
Roger|Dyalog
Posts: 238
Joined: Thu Jul 28, 2011 10:53 am

Re: Converting 128 bit decimal to Float

Post by Roger|Dyalog »

You are supposed to be able to convert from 1287 to 645 using ⎕dr:

      1287 645 ⎕DR x

but ⎕dr has not yet been extended as it should have. An error report had been previously filed about this. Meanwhile, you can use the following:

      ⎕fr←1287
x←○⍳12
⎕dr x
1287
t←{⎕fr←645 ⋄ 0+⍵} x
⎕dr t
645

The dfn exploits the fact that arithmetics are done WRT the current value of ⎕fr.
paulmansour
Posts: 431
Joined: Fri Oct 03, 2008 4:14 pm

Re: Converting 128 bit decimal to Float

Post by paulmansour »

Roger,

Thanks. The current documentation actually states that []DR does not support 1287, which is why I initially went the format-execute route.

Your workaround looks much better. Thanks.

Paul

PS. I just tried it, works fine. I didn't initially realize that the braces were needed in your example only because you used []FR the line above to generate the 1287 data. All I need to do is add 0, as I'm using the default value of []FR which is 645. So it is completely trivial.
Roger|Dyalog
Posts: 238
Joined: Thu Jul 28, 2011 10:53 am

Re: Converting 128 bit decimal to Float

Post by Roger|Dyalog »

Stylistically, I'd prefer cvt645←{⎕fr←645 ⋄ 0+⍵} (with or without the naming) to ensure that when I come back to it 6 months later I'd remember what the mysterious 0+⍵ is doing.
paulmansour
Posts: 431
Joined: Fri Oct 03, 2008 4:14 pm

Re: Converting 128 bit decimal to Float

Post by paulmansour »

Good point!
Post Reply