From: Caleb Clausen Date: 2009-08-05T06:37:30+09:00 Subject: [ruby-core:24766] Re: About An Imaginary Number Literal (Translation) ujihisa wrote: > * Imaginary numbers and Complex numbers are fundamentally different, > so 1+2i should be Complex(1, 2) rather than 1.+(Complex(0, 2)) > * see also: C++0x current draft has User-defined literals It isn't clear to me if the above encompassed this point or not. There should be a separate Imaginary class, distinct from Complex. I can't find anymore the article by a mathematician where he explains it in detail, but part of the problem is that the wrong thing happens (in most languages, not just ruby) when you do this: Infinity=1.0/0 p Complex::I*Infinity #should be Complex(0,Infinity), not Complex(NaN,Infinity) #or really, should be Imaginary(Infinity) I believe the c++ standard referenced above was informed by this article that I can't find. I'm intrigued by the possibility of having numeric literals like: 3/4r #=>Rational 667.71d #=>BigDecimal 3+4i #=>Complex 2-1i #=>Complex 42i #=>Imaginary 1/3.0i #=>Imaginary 1/3ri #=>Imaginary Rational Here's the best way I can see that will let that happen; allow the characters + - and / in numeric literals provided that they are followed by a digit. Also allow any number of type characters to follow the end of the numeric literal. If type characters are present, send the method(s) with the same name to the numeric literal AS A STRING. In other words, the following should hold: 3/4r equivalent to "3/4".r 667.71d equivalent to "667.71".d 3+4i equivalent to "3+4".i 2-1i equivalent to "2-1".i 42i equivalent to "42".i 1/3ri equivalent to "1/3".r.i 1/3.0i equivalent to "1/3.0".i It's important that the type character methods get the literal as a string in order to avoid loss of information and prevent rounding errors with BigDecimal or strange sign errors with 1/3ri. Also see that this system allows more than one type character to be chained together. + - and / in a numeric literal without any type characters at the end are treated as normal operators.