IronScheme and decimal datatype

Dec 13, 2009 at 4:05 PM

Hi,

i'm using ironscheme as a script engine and i recognized that ironscheme is unable to process decimal datatypes. Here is a little example for the ironscheme console:

(+ (clr-static-call System.Double Parse "10") (clr-static-call System.Double Parse "20.5"))

 

> (+ (clr-static-call System.Double Parse "10") (clr-static-call System.Double P
arse "20.5"))

works just fine. But:

(+ (clr-static-call System.Decimal Parse "10") (clr-static-call System.Decimal Parse "20.5"))

runs into an exception:

Unhandled exception during evaluation:

&assertion

&who: +

&message: "not number"

&irritants: (#<clr-type System.Decimal "10">)

Is there a way to use the decimal datatype in scheme or are there plans to support it in the future?

 

 

Coordinator
Dec 14, 2009 at 4:40 PM
Edited Dec 14, 2009 at 4:40 PM
c0demonkey23 wrote:

 

Is there a way to use the decimal datatype in scheme or are there plans to support it in the future?

You can do that right now (well long ago too).

Either via (ironscheme conversions) using `->decimal` or calling `System.Convert.ToDecimal`.

See https://ironscheme.svn.codeplex.com/svn/IronScheme/IronScheme.Console/ironscheme/conversions.sls

Cheers

leppie

Coordinator
Dec 14, 2009 at 4:50 PM

Argg

That is not right what I said.

IronScheme does not need a decimal number as it has a more complete number stack than .NET provides.

That said, it is probably not optimized for 'decimal' usage.

What do you need decimal types for? Using rational numbers (aka fractions) you can achieve the same (and more) with any loss in precision.

There is even a handy notation you can use. Example:

(+ #e0.1 #e0.3) => 19471113219505603967277331424215/649037107316853453566312041152512

(inexact (* #e0.1 #e0.3)) => 0.03

Make any sense?

leppie

Dec 16, 2009 at 1:19 PM

Hi leppie,

thanks for your suggestion. It sounds better than using decimal.

I just wonder, how can i convert / cast a decimal into a rational number in scheme?