Re: [gcj] problem printing the 256th ASCII character in C

2010-08-04 Thread Bharath Raghavendran
I don't think its reasonable to call something as a cyclic data type when it
is not intended to be. Its just that the data type shows cyclic behaviour
due to size limit. Its not a feature.

float does not show this behaviour because its probably unable to handle
more than 7 significant digits. So, when you add 1 to it, the binary form
remains the same. Lets say you have "float x = 2", and you keep doing x* =
2. Though I didn't try it, I am sure the exponent part of float will
overflow eventually and hence, this will show cyclic behaviour. On a side
note, the example you showed is a perfect example to why people should not
use float for integer calculations :).

-Bharath

On 4 August 2010 11:06, Bartholomew Furrow  wrote:

> There is no such thing as cyclic data type. Its just that every data type
>> has limited size (1 byte for unsigned char).
>
>
> I think it's reasonable to talk about a cyclic data type -- it isn't a
> standard term as far as I know, but certainly there are data types that
> cycle under incrementation (char, int, long long, short, etc.) and data
> types that don't (float, double).
>
> float x = 16777216.0
> if (x == x + 1) {
>   printf("What?\n");
> }
>
> ...will print "What?".
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-codejam" group.
> To post to this group, send email to google-c...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-code+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/google-code?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to google-c...@googlegroups.com.
To unsubscribe from this group, send email to 
google-code+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.



Re: [gcj] problem printing the 256th ASCII character in C

2010-08-04 Thread Soumyorup Dey
*try unsigned long char
*$ŎǕмџόЯטּρ  δεЎ




Connect with me on : [image:
Facebook][image:
Twitter] [image:
Orkut][image:
MySpace] 
Chat with me on : [image: Google Talk/]soumyorupdey [image: Google
Wave/]soumyorupdey
[image: Y! messenger/]soumyorup...@rocketmail.com


On Wed, Aug 4, 2010 at 11:27 PM, BABA SANUP @NITRKL wrote:

> thank you for enlightening mein this regard and clearing my notion
> but is there any data type which is an exception to this rule?
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-codejam" group.
> To post to this group, send email to google-c...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-code+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/google-code?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to google-c...@googlegroups.com.
To unsubscribe from this group, send email to 
google-code+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.



Re: [gcj] problem printing the 256th ASCII character in C

2010-08-04 Thread Bartholomew Furrow
>
> There is no such thing as cyclic data type. Its just that every data type
> has limited size (1 byte for unsigned char).


I think it's reasonable to talk about a cyclic data type -- it isn't a
standard term as far as I know, but certainly there are data types that
cycle under incrementation (char, int, long long, short, etc.) and data
types that don't (float, double).

float x = 16777216.0
if (x == x + 1) {
  printf("What?\n");
}

...will print "What?".

-- 
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to google-c...@googlegroups.com.
To unsubscribe from this group, send email to 
google-code+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.



Re: [gcj] problem printing the 256th ASCII character in C

2010-08-04 Thread Bharath Raghavendran
Fundamental datatypes like int, char, long, etc are limited by size and
hence, same thing will happen.
There may be some custom datatypes like BigInteger that adjusts its size
according to the value it stores and hence will be an exception to this. You
need to search from net and download those libraries for that, as it will
not be there in the compiler by default. Example of such a library :
http://sourceforge.net/projects/cpp-bigint/

-Bharath

On 4 August 2010 10:57, BABA SANUP @NITRKL  wrote:

> thank you for enlightening mein this regard and clearing my notion
> but is there any data type which is an exception to this rule?
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-codejam" group.
> To post to this group, send email to google-c...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-code+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/google-code?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to google-c...@googlegroups.com.
To unsubscribe from this group, send email to 
google-code+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.



Re: [gcj] problem printing the 256th ASCII character in C

2010-08-04 Thread BABA SANUP @NITRKL
thank you for enlightening mein this regard and clearing my notion
but is there any data type which is an exception to this rule?

-- 
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to google-c...@googlegroups.com.
To unsubscribe from this group, send email to 
google-code+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.



Re: [gcj] problem printing the 256th ASCII character in C

2010-08-04 Thread Bharath Raghavendran
There is no such thing as cyclic data type. Its just that every data type
has limited size (1 byte for unsigned char).

1 byte = 8 bits

When it is storing 255, its binary will be "".
When you increment it now, it tries to store "1", but since its
limited to 8 bits, it becomes "", which is 0.

-Bharath

On 4 August 2010 10:07, BABA SANUP @NITRKL  wrote:

> so u want to say that char is also a cyclic data type as integers, then it
> is perfect solution to the above riddle
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-codejam" group.
> To post to this group, send email to google-c...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-code+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/google-code?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to google-c...@googlegroups.com.
To unsubscribe from this group, send email to 
google-code+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.



Re: [gcj] problem printing the 256th ASCII character in C

2010-08-04 Thread ayman bs
Bharath, I think the same, and here is a proof.

http://ideone.com/jUcdS

On Wed, Aug 4, 2010 at 7:05 PM, Bharath Raghavendran
wrote:

> I think when you do c++ from 255, it will go to 0 and not 256 (bcoz its
> unsigned char).
> Hence, the condition c<=255 is always satisified and its an infinite loop
>
> -Bharath
>
>
> On 4 August 2010 10:02, Shoubhik  wrote:
>
>>
>> Hi,
>>
>> Here's a wierd situation..
>>
>> unsigned char c;
>> for(c=0;c<=255 ; c++)
>> printf("%c",c);
>>
>>
>> the above code gives an infinite loop in C !!!
>>
>> whereas, if i print
>>
>> unsigned char c=255;
>> prinf("%c",c);
>>
>>
>> the code works fine...
>>
>>
>> Somebody , help me get a work around,
>>
>> Thanks and Regards,
>> Shoubhik Bose.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "google-codejam" group.
>> To post to this group, send email to google-c...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> google-code+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/google-code?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "google-codejam" group.
> To post to this group, send email to google-c...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-code+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/google-code?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to google-c...@googlegroups.com.
To unsubscribe from this group, send email to 
google-code+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.



Re: [gcj] problem printing the 256th ASCII character in C

2010-08-04 Thread BABA SANUP @NITRKL
so u want to say that char is also a cyclic data type as integers, then it
is perfect solution to the above riddle

-- 
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to google-c...@googlegroups.com.
To unsubscribe from this group, send email to 
google-code+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.



Re: [gcj] problem printing the 256th ASCII character in C

2010-08-04 Thread Bharath Raghavendran
I think when you do c++ from 255, it will go to 0 and not 256 (bcoz its
unsigned char).
Hence, the condition c<=255 is always satisified and its an infinite loop

-Bharath

On 4 August 2010 10:02, Shoubhik  wrote:

>
> Hi,
>
> Here's a wierd situation..
>
> unsigned char c;
> for(c=0;c<=255 ; c++)
> printf("%c",c);
>
>
> the above code gives an infinite loop in C !!!
>
> whereas, if i print
>
> unsigned char c=255;
> prinf("%c",c);
>
>
> the code works fine...
>
>
> Somebody , help me get a work around,
>
> Thanks and Regards,
> Shoubhik Bose.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-codejam" group.
> To post to this group, send email to google-c...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-code+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/google-code?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to google-c...@googlegroups.com.
To unsubscribe from this group, send email to 
google-code+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.