[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Marshaling Decimal types from .NET

John Lam

3/30/2006 8:10:00 PM

Decimal numbers in .NET are 128 bit values that avoid the rounding errors
that can arise from floating point calcs:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html/vclrfcsharpspec...

My question is: when marshaling a .NET decimal type to Ruby, what should I
do? Should I marshal it to a bigdecimal?

Thanks
-John
http://www.iu...
28 Answers

Charles Mills

3/31/2006 12:31:00 AM

0

John Lam wrote:
> Decimal numbers in .NET are 128 bit values that avoid the rounding errors
> that can arise from floating point calcs:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html/vclrfcsharpspec...
>
> My question is: when marshaling a .NET decimal type to Ruby, what should I
> do? Should I marshal it to a bigdecimal?
>
> Thanks
> -John
> http://www.iu...
>
> ------=_Part_9810_19207910.1143749376557--

I would say yes. I expect you would have something like the following:
C# Ruby
---- ----
float Float
double Float
decimal BigDecimal

I imagine when a C# programmer uses decimal, they choose it instead of
double for a reason, making a conversion from decimal to Float (double)
all the more likely to cause rounding error.

-Charlie

John Lam

3/31/2006 1:08:00 AM

0

Thanks, Charlie I added the new marshaling code to RubyCLR this afternoon.
The only downside is that I have to convert the Decimal to a string first
before I can call BigDecimal's constructor, so this definitely impacts
performance when marshaling Decimals across the interop boundary.

-John
http://www.iu...



I would say yes. I expect you would have something like the following:
> C# Ruby
> ---- ----
> float Float
> double Float
> decimal BigDecimal
>
> I imagine when a C# programmer uses decimal, they choose it instead of
> double for a reason, making a conversion from decimal to Float (double)
> all the more likely to cause rounding error.
>
> -Charlie
>
>
>

Jeff

3/31/2006 1:27:00 AM

0

John Lam wrote:
> The only downside is that I have to convert the Decimal to a string
> first
> before I can call BigDecimal's constructor, so this definitely impacts
> performance when marshaling Decimals across the interop boundary.
>

I use decimal in C# for financial calculations, because we would get
round-off errors if we used floats.

I wasn't aware of BigDecimal before - it's not part of the core in 1.82,
is it?

Thanks
Jeff
www.softiesonrails.com



--
Posted via http://www.ruby-....


John Lam

3/31/2006 1:33:00 AM

0

I believe that BigDecimal has been included in the standard distribution
since 1.8.

I wasn't aware of BigDecimal before - it's not part of the core in 1.82,
> is it?
>
> Thanks
> Jeff
> www.softiesonrails.com
>

Jeff

3/31/2006 1:47:00 AM

0

John Lam wrote:
> I believe that BigDecimal has been included in the standard distribution
> since 1.8.
>

How do I specify a value to be of type BigDecimal instead of Float?

irb> 1.2.class
=> Float




--
Posted via http://www.ruby-....


Logan Capaldo

3/31/2006 1:50:00 AM

0


On Mar 30, 2006, at 8:27 PM, Jeff Cohen wrote:

> I wasn't aware of BigDecimal before - it's not part of the core in
> 1.82,
> is it?

I'm pretty sure it is:
logan:/Users/logan% /usr/bin/ruby -v
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]
logan:/Users/logan% /usr/bin/ruby -e 'require "bigdecimal"; puts
BigDecimal.new("1000022.0") + 2'
0.1000024E7

Jeff

3/31/2006 2:03:00 AM

0

Logan Capaldo wrote:
> On Mar 30, 2006, at 8:27 PM, Jeff Cohen wrote:
>
>> I wasn't aware of BigDecimal before - it's not part of the core in
>> 1.82,
>> is it?
>
> I'm pretty sure it is:
> logan:/Users/logan% /usr/bin/ruby -v
> ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]
> logan:/Users/logan% /usr/bin/ruby -e 'require "bigdecimal"; puts
> BigDecimal.new("1000022.0") + 2'
> 0.1000024E7

AH HA! I didn't realize I had to specifically require it (duh!).

Thanks Logan.


Jeff
www.softiesonrails.com

--
Posted via http://www.ruby-....


Jeff

3/31/2006 2:11:00 AM

0

I see now why I didn't know it was in 1.82. I had always been using
this url to look up things:

http://ruby-doc...

but BigDecimal is part of the "standard API", which is documented at:
http://ruby-doc.o...

and worse, BigDecimal is categorized as an under-documented class (it's
in italics in the alphabetical list), and they're not kidding! Most of
the methods are undocumented.

Maybe I'll try to figure out what all the methods of BigDecimal do, and
try to update the documentation on http://ruby-doc.o....

Thanks again,
Jeff

--
Posted via http://www.ruby-....


Tadashi Saito

3/31/2006 1:16:00 PM

0

Hi all,

On Fri, 31 Mar 2006 11:11:09 +0900
Jeff Cohen <cohen.jeff@gmail.com> wrote:

> in italics in the alphabetical list), and they're not kidding! Most of
> the methods are undocumented.

Oh, no. BigDecimal is (almost) fully documented in
ext/bigdecimal/bigdecimal_en.html.
But you know, it's not rdoc, so you and some people will be not satisfied.

--
Tadashi Saito

Morgoth Bauglir

1/19/2013 6:32:00 PM

0


> If a federal law violates the constitution then it is void!

Right.

> And by the tenth amendment the states are the entity with
> authority to declare a federal law unconstitutional.

Wrong.

As you should have learned in 5th grade civics.