Unsigned Long Native Type

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
grabiller
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Jun 01, 2011 9:38 am
Location: France - 89220 Rogny-Les-Septs-Ecluses
Contact:

Unsigned Long Native Type

Post by grabiller »

Hi,

I know this has been discussed extensively by the past and there is probably already one or several feature requests for this, but I recently stumbled on an issue directly related to the fact that PB does not have a native unsigned long type and using x64 compilation.

The issue happened when having several integers constants definition having values higher than signed long limit and by using a structure containing variables of long type (C u32int_t/PB.l to match the external library API). I believe PB internally store constant values as 64 bit integers (q). When reading the value of those variables back and comparing those values with the constants value, wrong results appeared.

When both values are internally the same (this can be verified by using StrU(value,#PB_LONG)), *comparison* fails!

For instance if you have a long variable mylongvariable.l and a constant of value higher than signed long limit, both with the same internal value:
If #SOME_CONSTANT = mylongvariable
; FAILED!!!!, code will never enter this section
EndIf

I'm not sure how others currently deal with this situation, but to me this lack of native unsigned long type in PB leads to this kind of bugs that can be extremely hard to detect.
Last edited by grabiller on Tue Jun 14, 2016 11:04 am, edited 1 time in total.
guy rabiller | radfac founder / ceo | raafal.org
fryquez
Enthusiast
Enthusiast
Posts: 391
Joined: Mon Dec 21, 2015 8:12 pm

Re: Unsigned Long Native Type

Post by fryquez »

You can use & $FFFFFFFF for comparison.

Code: Select all

#SOME_CONSTANT = $80000001
mylongvariable.l = $80000001

Debug #SOME_CONSTANT
Debug mylongvariable

If #SOME_CONSTANT = (mylongvariable & $FFFFFFFF)
  Debug 1
EndIf
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: Unsigned Long Native Type

Post by DontTalkToMe »

do you mean this ?

Code: Select all

#MAX_LONG =  1 << 31 - 1
#MIN_LONG = -#MAXLONG - 1

Debug #MAX_LONG
Debug #MIN_LONG

#SOME_CONSTANT = #MAX_LONG + 1 

; some C code stores a 32 bit unsigned int inside PB longvar
longvar.l = #MAX_LONG + 1 ; wraps to #MIN_LONG in PB because longvar is signed

Debug "#SOME_CONSTANT = "  + #SOME_CONSTANT ; it's treated as quad in PB apparently, at least when printed by debug
Debug "#SOME_CONSTANT = $"  + Hex(#SOME_CONSTANT)

Debug "longvar = " + longvar
Debug "longvar = $" + Hex(longvar)

If #SOME_CONSTANT = longvar ; it's TRUE on x86, FALSE on x64
 Debug "equal" 
Else 
 Debug "not equal" 
EndIf
Yes, it's a gigantic annoyance and source of bugs. But we already knew it, and the painful workarounds too (truncation of quads, promotion of longs, bitwise comparison, what works in a specific case).

I don't think asking for unsigned again will change anything.

They already answered about this and said ... you know what. :P
User avatar
grabiller
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Jun 01, 2011 9:38 am
Location: France - 89220 Rogny-Les-Septs-Ecluses
Contact:

Re: Unsigned Long Native Type

Post by grabiller »

DontTalkToMe wrote:../.. I don't think asking for unsigned again will change anything../..
Well, I think it is a good thing to remind this kind of issues from time to times, especially for PB newcomers.
And who knows, perhaps in a spark of illumination opinion may change..
guy rabiller | radfac founder / ceo | raafal.org
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Unsigned Long Native Type

Post by Keya »

unsigned dword is my only real wish, because I can't implement it myself. I want to get stuck on a deserted island with dwords, because i will thrive, there'll be no stopping me :) but the shackles are on in the meantime. I have faith it will come! there have been so many amazing features added to PB especially over recent years, so I refuse to believe it will never come :) glass of iced coffee half full here
User_Russian
Addict
Addict
Posts: 1520
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Unsigned Long Native Type

Post by User_Russian »

I longer no believe that in PB add unsigned variable types...

I have long offered simple ways http://www.purebasic.fr/english/viewtop ... 10#p485110
http://www.purebasic.fr/english/viewtop ... =3&t=52929
http://www.purebasic.fr/english/viewtop ... 79#p414979
but appear new versions of the PB, but this functions not added, but they really need!
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Unsigned Long Native Type

Post by Thunder93 »

Was it officially stated why unsigned variable types would not be added to PB? Like is it the kid-gloves treatment? Or very difficult procedure to offer support for?
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: Unsigned Long Native Type

Post by DontTalkToMe »

Thunder93 wrote:Was it officially stated why unsigned variable types would not be added to PB?
more or less
http://www.purebasic.fr/english/viewtop ... f=3&t=6896

there was also some mention of "Java and the fact it lacked unsigned too, so as you can see someone else think it's a good idea" or something like that

anyway there have always been a lot of people who thought it sucked
http://www.darksleep.com/player/JavaAnd ... Types.html

Java 8 finally introduced not new data types but at least ways to access the original signed data types as unsigned
http://stackoverflow.com/questions/2555 ... -in-java-8
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Unsigned Long Native Type

Post by Thunder93 »

Interesting reads DontTalkToMe, thanks.

I have never seen that 2003yr old PB topic before. :shock:
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
idle
Always Here
Always Here
Posts: 5840
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Unsigned Long Native Type

Post by idle »

in the mean time you can try this work around
http://www.purebasic.fr/english/viewtop ... 12&t=65312
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
grabiller
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Jun 01, 2011 9:38 am
Location: France - 89220 Rogny-Les-Septs-Ecluses
Contact:

Re: Unsigned Long Native Type

Post by grabiller »

DontTalkToMe wrote:
Thunder93 wrote:Was it officially stated why unsigned variable types would not be added to PB?
more or less
http://www.purebasic.fr/english/viewtop ... f=3&t=6896
Reading that post for the first time too.

Fred kind of ironically asked for a very interesting question:
"../..Do you want casts be introduced in a basic langage ?../.."

In fact, yes! That could be a very good idea, in fact, as right know - at least on my side - with EnableExplicit and all, I'm using PureBasic like a typed language anyway, always declaring the types of the variables I'm using. Having casts introduced in PureBasic would just feel natural at that point, and if it could solves the use of unsigned integers.. Yet this could potentially lead to performance improvement.

I'm in for it : )
guy rabiller | radfac founder / ceo | raafal.org
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: Unsigned Long Native Type

Post by DontTalkToMe »

I would like function overloading, unsigned, casts, real constants, but the odds are the only way I'll get them is by using another language.

The sooner you recognize that, the less you are going to suffer.
grabiller wrote:Reading that post for the first time too.
Then read this too :)
http://www.purebasic.fr/english/viewtop ... 782#p37782
Fred wrote:... it would include casts, like in C which I don't want
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Unsigned Long Native Type

Post by Thunder93 »

I don't see much difference now with casts already existing anyways. So I'm in also to see this enhancement, extended (much needed) support.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Unsigned Long Native Type

Post by Lunasole »

DontTalkToMe wrote:I would like function overloading, unsigned, casts, real constants, but the odds are the only way I'll get them is by using another language.
Hah, the problem is that other languages are even worst, at least for me ^^
For example if you take FreeBasic (which has enough nice stuff, including those unsigned types), you'll encounter that it doesn't has nice IDE, nice debugger and it's STL still is very poor and making something "more or less serious" with this language is extremely painful and full with workarounds and reinvented bicycles.

If you take C/C++ which offers everything, you probably soon get tired of it's "bureaucracy" which is good maybe for large teams (or if you working only with single or very few long-term projects for many years), but not for single programmer with limited resources.

.NET/python/delphi/go/rust and any_other_known_crap also having their "fatal injuries"

So Purebasic stupid (and often unexpected) limits, bugs and such things are often annoying, but at least for now I don't know something else which would in total have less props than PB and nicely replace it ^^ It might change in year or two (just look how fast languages are creating and evolving nowadays), but currently I don't see or didn't found any better replacement. For now getting pain with any other language makes sense for me only if going to work for someone and get fixed $ for this pain (the pain from PB is much lower so it can be used to code for myself, or without any payment).

In other and shorter words, PB looks like best of worst and terrible ones, and thus best of any existing :3



PS. There was many said about UINTS/ULONGS already, I just say that this is one of things that language must have to meet modern standarts and usefulness. It was good for MS VB5/6 to not have uints in 2000x, but not for VB.NET in 2016.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Unsigned Long Native Type

Post by Keya »

btw how does VB.Net handle conversions between Long<>Dword? like does it require casting or is it automatic or..?

I have a good friend who programs in Powerbasic, i havent looked into it much because unless im missing something it seems it's for Win32 only, but I got him to send me some examples which were quite interesting because Powerbasic also compiles into asm, and allows <quote>"seamless"</quote> use of longs and dwords without any casting! Im just waiting for another .exe from him with some custom requested calculations so I can look more closely into what "auto-cast assumptions" i'm guessing it's making, and assuming i get that soon i will post back some results hopefully later today if i can get my head around them lol :)

ps. Purebasic is able to automatically handle conversion between signed/unsigned BYTE (.a/.b) and WORD (.w/.u), no casting required, so if it can already do such seamless conversions with 8 and 16bit i dont understand why the same approach cant be extended to 32bit :( :)
Post Reply