Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API

From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "signed integer"
-
The story of the $500,000,000 error.
In 1996, an unmanned Ariane 5 model rocket was launched by the European Space Agency.
Onboard was software written to analyze the horizontal velocity of the spacecraft. A conversion between a 64-bit floating point value and a 16-bit signed integer within this software ultimately caused an overflow error just forty seconds after launch, leading to a catastrophic failure of the spacecraft.
That day, $7 billion of development met it's match: a data type conversion.12 -
I hope devRant doesn't store ++ count as a signed 8-bit integer... Otherwise the next ++ this rant gets sets it to -128!2
-
I have not researched it so I'm not sure if this is a widely known thing but I figured out a sort of hacky way to get a max integer value:
-Declare an unsigned int.
-Subtract 1
-Divide 2
That is your max signed int value
int main(){
unsigned int a = 0;
a--;
std::cout << a / 2 << std::endl;
}7 -
The tons of undefined behaviour in C that ought to have been implementation defined instead, and increasingly sadistic compiler writers on the other side.
Like signed integer overflow that should just do what the underlying machine does, i.e. in practice, wrap around two's complement.
But the wierdest UB is when a C source code line has a non-matching ' or ". WTF, this should have been a compile time error!2 -
Why do io-interfaces usually use a signed integer to return the number of bytes processed?
Like seriously, you literally can't write/read less than 0 bytes.4 -
A bit longer rant, somehow triggered by the end of this rant:
https://devrant.com/rants/7145365/...
The discussion revolved around strpos returning false or a positive integer.
Instead of an Option or a Exception.
I said I'm a sucker for exception, but I'm also a sucker for typing.
Which is something most languages lack - except the lower level ones like C / C++.
I always loved languages which have unsigned and signed types.
There, I said it... :) I know that signed / unsigned is controversial, Google immediately leads to blog entries screaming bloody murder because unsigned can overflow – or underflow, if someone tries to use a -1on an unsigned integer.
Note that my love is only meant for numeric types, unsigned / signed char is ... a whole can of insanity on its own.
https://phoronix.com/news/...
If you wanna know more.
Back to the strpos problem, now with my secret love exposed:
strpos works on a single string, where a string is a sequence of chars starting with 0.
0 is a positive integer.
In case the needle (char that should be looked up in the string) cannot be found in the haystack (the string), PHP returns "false".
This leads to the necessity of explicitly checking the type as "0" (beginning of string, a string position)... So strpos !== false.
PHP interprets 0 as false, any other integer value is true.
In the discussion, the suggestion came up to return -1 if a value could not be found – which some languages do, for example Scala.
Now I said I have a love for unsigned & signed integers vs. just signed integers...
Can you guess why the -1 bothers me very much?
Because it's a value that's illogical.
A search in a sequence that is indexed by 0 can only have 0 or more elements, not less than zero elements.
-1 refers to a position in the sequence that *cannot* exist.
Which is - of course - the reason -1 was chosen as a return value for false, but it still annoys me.
An unsigned integer with an exception would be my love as a return value, mostly because an unsigned integer represents the return value *best*. After all, the sequence can only return a value of 0 ... X.
*sigh*
Yes, I know I'm weird.
I'm also missing unsigned in Postgres, which was more or less not implemented because it's not in the SQL standard...
*sob*29 -
!rant
So I decided to collab with a website's maker (who i wont name here) to create something like r/place. (not an exact copy.)
I decided to start by learning their API, and customizing the server later.
I asked the guy for some help, and HOLY SHIT.
Let's start off by this: I had to request a chunk. The response data was in binary. 4 bits meant 1 pixel, so right away, I had to deal with that in my code.
No problem, just decided to use C# instead of JS. (see https://www.devrant.io/rants/547013)
I was finally done after a couple of mental breakdowns, and decided to implement updates.
I needed to use webhooks, and that was completely fine. But when I got "C1FFFF0000CA06" as response (in hex), I seeked some help.
C1 is the operation type: it means that a pixel was updated.
FFFF and 0000 were the chunk coordinates. But remeber: it's a signed integer. Guess what, I had to use Two's compliment. I decided to be a lazy asshole and only check for "00000000" because I was only displaying chunk 0,0.
CA06: This is a weird one. It's 2 bytes, and CA0 contains the X and Y coordinate of the pixel (in the chunk), and 6 contains the new color of the pixel.
I was sent the following code to work with 0xCA06:
color = 0xF & buffer
x = buffer >> 10
y = (buffer >> 4) & 0x3F
So I tried to do it, and it didn't work. I'm not blaming the developer of the server (original dev is reddit) because maybe I screwed up, but which guy will have a night of frustration and debugging?
Me.
P.S.: Dev, if you see this, I'm sorry. This API is way too complicated. I know we need to save bandwith and stuff, but damn.1 -
@retoor I did it I FUCKING DID IT. I CRACKED THE COWDZ.
HAVEN'T SLEPT IN ALMOST THREE DAYS.
BUT I FED THIS TO A LOBOTOMIZED BOTII.
IT WAS ABLE TO RUN MY RULESET.
WELL, A VERY LIMITED VERSION.
BUT STILL.
PRO VIBES-ORIENTED PROGRAMMING.
IN MARKDOWN.
PSEUDOMARKDOWN.
what?
WHAT??!!!!
OH YEAH.
BEHOOOOOLLLD THE POWER OF CRACK:
```
# Definition of Basic Terms:
- Actor;
· * "An Actor is a character or entity actively or passively participating in the game";
- Action:
· * "An Action is whatever an Actor does during their turn";
· * **IMPORTANT: "In addition to taking an Action during their own turn, an Actor can opt to prepare a Re-Action to activate during another Actor's turn, *if* they have enough SP/MP to do so"**;
- Signa:
· * "A Signa is an in-game effect that describes an Actor's Actions and Re-Actions";
· * "In-game effects can only alter values within the Actor->Status dict";
· * Signa->Caster = the Actor that activated the Signa;
· * Signa->Target = the Actor that is affected by the Signa;
· * **IMPORTANT: "A Signa can be cast 'OnSelf', that is, the Caster can choose to cause the effect on themselves"**;
---
# Actor Attributes:
- Actor->ReadOnly:
· * **IMPORTANT: "ReadOnly attributes represent an Actor's natural advantages and cannot be changed through in-game effects"**;
· * **IMPORTANT: "The purpose of these immutable attributes is determining the base values for game formulas"**;
· * "Actor->ReadOnly is a (key=>value) dict that stores the Actor's innate and immutable attributes";
· * **IMPORTANT: "These bonuses are fixed and cannot be altered by in-game effects"**;
· * "Each key corresponds to a specific game formula";
· * "Each value is a constant signed integer that represents a modifier for the associated formula";
- Actor->Grit:
· * Actor->ReadOnly->{"HP->Max"} = 8+(Actor->Grit*2);
· * "Actor->HP->Regen is not affected by Grit";
· * Actor->ReadOnly->{"Strength"} = Actor->Grit*1;
· * Actor->ReadOnly->{"Resist"} = Actor->Grit*1;
- Actor->Wit:
· * Actor->ReadOnly->{"MP->Max"} = 4+(Actor->Wit*2);
· * "Actor->MP->Regen is not affected by Wit";
· * Actor->ReadOnly->{"Intelligence"} = Actor->Wit*1;
· * Actor->ReadOnly->{"Dexterity"} = Actor->Wit*1;
- Actor->Charm:
· * Actor->ReadOnly->{"SP->Max"} = 1+(Actor->Charm*1);
· * Actor->ReadOnly->{"Perception"} = Actor->Charm*2;
· * Actor->ReadOnly->{"Charisma"} = Actor->Charm*2;
- Actor->Spirit:
· * Actor->ReadOnly->{"Arcana"} = Actor->Spirit*2;
- Actor->Faith:
· * Actor->ReadOnly->{"Defend"} = Actor->Faith*1;
· * Actor->ReadOnly->{"Heal"} = Actor->Faith*1;
· * Actor->ReadOnly->{"Bless"} = Actor->Faith*1;
- Actor->Hatred:
· * Actor->ReadOnly->{"Damage"} = Actor->Hatred*1;
· * Actor->ReadOnly->{"Curse"} = Actor->Hatred*1;
---
# Diceroll Definition:
- rand:
· * "A pseudo-random number between 0 and 0.99";
- roll->dX:
· * roll->dX = truncate (rand*X);
---
# Basic Formulas:
- Actor->Status:
· * "Actor->Status is a (key=>value) dict that stores the Actor's current status effects";
· * "These bonuses are temporary and can be altered by in-game effects";
· * "Each key corresponds to a specific game formula";
· * "Each value is a signed integer that represents a modifier for the associated formula";
- Actor->Damage:
· * let base = roll->d4;
· * let X = Actor->ReadOnly->{"Damage"};
· * let Y = Actor->Status->{"Damage"};
· * Actor->Damage = base+(X+Y);
· * "Result can be negative if (X+Y) is less than -base";
---
# Regeneration Rates:
- Actor->HP->Regen:
· * const base = 0;
· * let X = Actor->Status->{"HP->Regen"};
· * Actor->HP->Regen = base+X;
· * "Result can be negative if X is less than 0";
- Actor->MP->Regen:
· * const base = 1;
· * let X = Actor->Status->{"MP->Regen"};
· * Actor->MP->Regen = base+X;
· * "Result can be negative if X is less than -1";
- Actor->SP->Regen:
· * let base = Actor->Status->{"SP->Max"};
· * let X = Actor->Status->{"SP->Regen"};
· * Actor->SP->Regen = base+X;
· * "Result can be negative if X is less than -base";
---
# Default Signas:
- Movement (Signa):
· * Movement->Cost->SP = 1;
· * Movement->Cost->MP = 0;
· * Movement->Duration = 1 turn;
· * Movement->AreaOfEffect = 4 tiles;
· * "Allows the Caster to move the target up to 4 tiles distance";
· * **IMPORTANT: "This Signa does not allow the Caster to avoid obstacles"**;
- Attack (Signa):
· * Attack->Cost->SP = 1;
· * Attack->Cost->MP = 0;
· * Attack->Duration = 1 turn;
· * Attack->AreaOfEffect = 1 tile;
· * let dst = Attack->Target;
· * let src = Attack->Caster;
· * dst->HP->Current -= src->Damage;
· * **IMPORTANT: "This Signa never misses"**;
```14