Why no Unsigned Integer or Unsigned Long?

BlitzMax Forums/BlitzMax Beginners Area/Why no Unsigned Integer or Unsigned Long?

Shortwind(Posted 2009) [#1]
Why does blitzmax not support Unsigned Integer or Long? Is it possible to modify the BRL source to have Unsigned Integer?


markcw(Posted 2009) [#2]
What do you need it for?


Ian Thompson(Posted 2009) [#3]
I've wondered about this too, seems a little silly to have it signed. when you don't need or require it sometimes.


ImaginaryHuman(Posted 2009) [#4]
Usually those numbers are so big you don't need to worry about the sign, but sometimes not ;-D

If you want an unsigned integer, store it in an unsigned long instead, do any math or whatever you need to do using the Long, and then when you need to do something like bitmasks or logic operations on the integer, you can always copy it into an int and copy it back to a long again - so long as you don't try to take its value as an integer.


Shortwind(Posted 2009) [#5]
Direct from the Blitz Source Code:

typedef unsigned char BBBYTE;
typedef unsigned short BBSHORT;
typedef signed int BBINT;

So... I guess I'll have to do this myself... ho. hum...


Shortwind(Posted 2009) [#6]
@ImaginaryHuman

Thanks for the advice but I'll make due with the unsigned Int for now. Blitz Longs are terribly slow.


Shortwind(Posted 2009) [#7]
@markcw

I need it for the ultimate, newest, bestest, most fantastic compression algorithm the world has ever seen! ha ha... Or were you just being snide? :)

Sorry, a little humor there. It just annoyes me that they would have a unsigned short and not unsigned int. This is 2009, not 1986. :)


markcw(Posted 2009) [#8]
No, not being snide. I was genuinely curious as to what you need unsigned int/long for.

I don't know if you can just add them in or if it's a job for BRL, but I'm fairly sure you could write a module in C to handle conversions and maths. I remember a similar thing was done with Blitz3D to add doubles support.


Shortwind(Posted 2009) [#9]
@markcw

:) I was more annoyed than anything. I can work around it for my project.

I really am working on a new compression technique, among other things. (I know, I know, impossible...)

I have started integrating into Blitzmax because of the cross-compiliation ease. Not to mention the speed. (I am not a C++ coder and never will be.)

I started out on a C64, Apple, etc... and have always concentrated on "basic" as a good language. I can program in C and C++, but I hate it. I'm not one that has ever went with the idea that "basic" is a toy language. If someone would have made a good compiler for "basic" back in the 80's C++ wouldn't exist. C was never meant to be a general purpose language, and to those programmers that think C and C++ are the "only" real programming languages... oh well.

I'm not a great programmer, nor the most logical at times, but that's part of the fun. To create a program, then rework it, optimize it, and learn from it. That's the whole point. I do not make my career from programming, nor will I ever. But that's not the point is it?


Nate the Great(Posted 2009) [#10]
sorry if this is noobish but what does signed and unsigned mean?


Zethrax(Posted 2009) [#11]
An unsigned value can only be positive. A signed value can be either positive or negative.

This subject has been discussed in the past, and the response from the Blitz developer was that mixing signed and unsigned values in math expressions is considered to be a very bad idea. I'm not sure of the specifics, but some research on Google should give the answers as to why.


markcw(Posted 2009) [#12]
The sign is stored in a bit, unsigned has twice the maximum value because it uses the sign bit as part of the number.


Dreamora(Posted 2009) [#13]
The range covered though is the same and so are the different unique values you can store.


Flemmonk(Posted 2009) [#14]
I also would like the convenience of having unsigned types.

Even if they were so: Short/UShort, Int/UInt etc...


Wings(Posted 2010) [#15]
Unsigned is realy missed too.. i try the long story instead :)


Gabriel(Posted 2010) [#16]
What Dreamora said. Unless you have very specific requirements, signed/unsigned will not matter.


Czar Flavius(Posted 2010) [#17]
Unless you have very specific requirements, signed/unsigned will not matter.
Sometimes, though, you may have those requirements.


Gabriel(Posted 2010) [#18]
Sometimes, though, you may have those requirements.

So far, no one has actually come up with any though. Randomly causing new problems to fix non-existant "existing" problems is probably not high on Mark's to-do list. If someone actually had a compelling reason, he might be inclined to listen. Certainly he did (eventually) listen to reasoned arguments in favour of threading.


xlsior(Posted 2010) [#19]
So far, no one has actually come up with any though


How about this one: There's plenty of 3rd party C libraries that use unsigned datatypes, and support for those in Blitz could make interfacing between the two languages easier?


Gabriel(Posted 2010) [#20]
There's plenty of 3rd party C libraries that use unsigned datatypes, and support for those in Blitz could make interfacing between the two languages easier?

It doesn't though. I've wrapped C libraries that use unsigned datatypes, and it just doesn't make any difference. Internally the values are identical, regardless of signed/unsigned. The only difference is how BlitzMax interprets them for operations like displaying them, and 99.9% of the time, that's irrelevant.


Arowx(Posted 2010) [#21]
Is a byte ptr signed or unsigned?


Floyd(Posted 2010) [#22]
Is a byte ptr signed or unsigned?

A pointer is not a numeric type. You can't do arithmetic with it, except for the special "pointer arithmetic".

Suppose p and q are both pointers to integers. An integer is 4 bytes.
We can do q = p + 1. Now q holds a value which is 4 larger than p, i.e. p increased by the size of 1 integer.

We can also take the difference q-p. Numerically this is 4, but will be treated as 1 because they differ by 1 integer.

Operations like p+q or p*q make no sense and are not defined.


BladeRunner(Posted 2010) [#23]
unsigned Int would for instance be very good at Millisecs(). If your pc is on for long enough (and hibernating adds to this!) millisecs()-based Timers will screw up as they mostly are not built to deal with negative values.


Czar Flavius(Posted 2010) [#24]
I'm dealing with very long arrays and an unsigned integer would allow me to double the size I can access without using slower longs.


Gabriel(Posted 2010) [#25]
unsigned Int would for instance be very good at Millisecs(). If your pc is on for long enough (and hibernating adds to this!) millisecs()-based Timers will screw up as they mostly are not built to deal with negative values.

No it wouldn't. You never need millisecs as an absolute, you should be using the delta, which is never affected by the sign, and thus will never be a problem so long as you use it correctly.

I'm dealing with very long arrays and an unsigned integer would allow me to double the size I can access without using slower longs.

I have a hard time believing you're actually doing this. If you think about it very carefully, you'll realize what gave you away.


Czar Flavius(Posted 2010) [#26]
I attempt many stupid things. Never underestimate my incompetence.


TaskMaster(Posted 2010) [#27]
It would take an enormous amount of memory to have an array that an signed Int could not handle. Even if the array was just integers, it would take about 8GB of memory.


Czar Flavius(Posted 2010) [#28]
It's a possibility if they play with infinate resource deposists!! They could build 8,000,000,000 ships over the course of several months of constant gameplay. My game will be that addictive.


TaskMaster(Posted 2010) [#29]
HAHAHA. I hope so.


Retimer(Posted 2010) [#30]
I also would like the convenience of having unsigned types.

Even if they were so: Short/UShort, Int/UInt etc...


God (blitzmax religiously) yes.

Would this not be pretty simple for mark to impliment officially?

I'm going to take a badly aimed stab in guessing that having such a thing would make porting libraries easier as well, instead of having to work around the var-types.


plash(Posted 2010) [#31]
Signed/unsigned numerical data types can be useful when dealing with C and C++ code.


Brucey(Posted 2010) [#32]
Signed/unsigned numerical data types can be useful when dealing with C and C++ code.

You can pass them back and forth okay. It's just that on the BlitzMax side, the number might be negative...


plash(Posted 2010) [#33]
You can pass them back and forth okay. It's just that on the BlitzMax side, the number might be negative...
Yup. Therein lies my quarrel.


Floyd(Posted 2010) [#34]
That's not much of a quarrel.

Here's the official word on why you shouldn't expect unsigned numbers.


Czar Flavius(Posted 2010) [#35]
Just don't document them very well, and then most people won't be aware of them whereas those who need it can use it.


plash(Posted 2010) [#36]
I would never bother using signed data types in a real project, but wrapping libraries and the such they could come in handy (if only for conversion).