By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,424 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,424 IT Pros & Developers. It's quick & easy.

Integer constants

P: n/a
I was experimenting with implicit typing of integer constants, and
found to my surprise that in MS C# 1.1 (VS.2003) you can write code
like

double Large = 18446744073709551615;

This is quite a bit bigger than ulong.MaxValue - in fact, it's
ulong.MaxValue * 2 + 1. I'm curious - could someone who has Mono
installed check to see if the Mono C# compiler can handle this line?

--

programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs
Nov 15 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Well... you're using a double there, not an int or a long. If you try a long
you'll probably get a compiler error along the lines of "can't do implicit
cast of 'ulong to long'. And if you cast it you'll still get an error and a
recommendation that you use unchecked code... which is not a good idea to
say the least =)
--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"Jon Shemitz" <jo*@midnightbeach.com> wrote in message
news:40***************@midnightbeach.com...
I was experimenting with implicit typing of integer constants, and
found to my surprise that in MS C# 1.1 (VS.2003) you can write code
like

double Large = 18446744073709551615;

This is quite a bit bigger than ulong.MaxValue - in fact, it's
ulong.MaxValue * 2 + 1. I'm curious - could someone who has Mono
installed check to see if the Mono C# compiler can handle this line?

--

programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs

Nov 15 '05 #2

P: n/a
"Klaus H. Probst" wrote:
Well... you're using a double there, not an int or a long.
Well, yes. Actually, I was expecting that the compiler wouldn't handle
any "double Large = <int constant>;" where <int constant> was any
greater than ulong.MaxValue. I was surprised to fin that that's not
true, that it can go all the way to "double Large =
18446744073709551615;" before demanding code like "double Large =
18446744073709551616d;".
If you try a long
you'll probably get a compiler error along the lines of "can't do implicit
cast of 'ulong to long'. And if you cast it you'll still get an error and a
recommendation that you use unchecked code... which is not a good idea to
say the least =)


Thanks, but not news, and not what I'm asking about ....
I was experimenting with implicit typing of integer constants, and
found to my surprise that in MS C# 1.1 (VS.2003) you can write code
like

double Large = 18446744073709551615;

This is quite a bit bigger than ulong.MaxValue - in fact, it's
ulong.MaxValue * 2 + 1. I'm curious - could someone who has Mono
installed check to see if the Mono C# compiler can handle this line?


--

programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs
Nov 15 '05 #3

P: n/a
Jon Shemitz <jo*@midnightbeach.com> wrote:
"Klaus H. Probst" wrote:
Well... you're using a double there, not an int or a long.


Well, yes. Actually, I was expecting that the compiler wouldn't handle
any "double Large = <int constant>;" where <int constant> was any
greater than ulong.MaxValue. I was surprised to fin that that's not
true, that it can go all the way to "double Large =
18446744073709551615;" before demanding code like "double Large =
18446744073709551616d;".


Indeed - according to the C# spec, I that it shouldn't compile.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4

P: n/a

"Jon Shemitz" <jo*@midnightbeach.com> wrote in message
news:40***************@midnightbeach.com...
I was experimenting with implicit typing of integer constants, and
found to my surprise that in MS C# 1.1 (VS.2003) you can write code
like

double Large = 18446744073709551615;

This is quite a bit bigger than ulong.MaxValue - in fact, it's
ulong.MaxValue * 2 + 1. I'm curious - could someone who has Mono
installed check to see if the Mono C# compiler can handle this line?

Mono's mcs 0.29 accepts this as well, didn't check to ensure it was correct,
but it does accept it.
--

programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs

Nov 15 '05 #5

P: n/a
"Daniel O'Connell [C# MVP]" wrote:
Mono's mcs 0.29 accepts this as well, didn't check to ensure it was correct,
but it does accept it.


Thanks! Didn't really want to install mono on my ancient Linux machine
just for a footnote (that might get canned anyway).

--

programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs
Nov 15 '05 #6

P: n/a

"Jon Shemitz" <jo*@midnightbeach.com> wrote in message
news:40***************@midnightbeach.com...
"Daniel O'Connell [C# MVP]" wrote:
Mono's mcs 0.29 accepts this as well, didn't check to ensure it was correct, but it does accept it.
Thanks! Didn't really want to install mono on my ancient Linux machine
just for a footnote (that might get canned anyway).

Hehe, ya, I run it on my windows machien actually; rotor, mono, and the
framework. Sometimes I have to be careful what compiler I'm actually
using, -_-.
--

programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs

Nov 15 '05 #7

P: n/a
> I was experimenting with implicit typing of integer constants, and
found to my surprise that in MS C# 1.1 (VS.2003) you can write code
like

double Large = 18446744073709551615;

This is quite a bit bigger than ulong.MaxValue - in fact, it's
ulong.MaxValue * 2 + 1. I'm curious - could someone who has Mono
installed check to see if the Mono C# compiler can handle this line?


I feel so very silly - this IS ulong.MaxValue.

I must have done a Console.WriteLine() of long.MaxValue, not
ulong.MaxValue, and copy/pasted THAT value to experiment with. Of
COURSE the ulong.MaxValue would be long.MaxValue * 2 + 1, and it makes
perfect sense that that would be the largest "integral constant".

So sorry.
--

programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs
Nov 15 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.