Page 1 of 1
Converting 128 bit decimal to Float
Posted: Tue Oct 16, 2012 7:01 pm
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:
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
Re: Converting 128 bit decimal to Float
Posted: Tue Oct 16, 2012 7:26 pm
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.
Re: Converting 128 bit decimal to Float
Posted: Wed Oct 17, 2012 8:44 am
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.
Re: Converting 128 bit decimal to Float
Posted: Wed Oct 17, 2012 11:27 am
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.
Re: Converting 128 bit decimal to Float
Posted: Wed Oct 17, 2012 11:36 pm
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.
Re: Converting 128 bit decimal to Float
Posted: Thu Oct 18, 2012 1:56 pm
by paulmansour
Good point!