WheretIB / nullc

Fast C-like programming language with advanced features
MIT License
163 stars 13 forks source link

incorrect logic #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
code:
import std.io;
char t = 0xd0;
if(t == char(0xd0))
{
 Print("ok");
}else{
 Print(char(0xd0));
 Print( "\r\n" );
 Print(t);
}

if(t == 0xd0) <-- false 
if(t == char(0xd0)) <-- false 
if(char(t) == char(0xd0)) <-- false 
if(t == int(0xd0)<-- false
if(int(t) == int(0xd0))<-- false 
if(int(t) == 0xd0)<-- false 

how to compare char with hex?
>>LanguageEN.html
1.1 Basic types
char 1 byte no alignment values: 0..255 

Original issue reported on code.google.com by TOLCli...@yandex.ru on 14 Jun 2013 at 12:32

GoogleCodeExporter commented 9 years ago
Thank you for the report.

There are two problems here:
- char is actually signed with a range -128..127, I have fixed the documentation
- char() and short() functions did not correctly handle negative values, this 
has also been fixed

Additionally, I have added an as_unsigned function to interpret signed char, 
short and int values as unsigned values placed in an int, int and long 
respectively.

After an update, you can write the check as either
if(t == char(0xd0)) or if(as_unsigned(t) == 0xd0)

Original comment by Where...@gmail.com on 16 Jun 2013 at 4:59