FAQ Search Memberlist Usergroups
Jolt Country Forum Index
Register Profile Log in to check your private messages Log in
Log in Log in

What's the deal with negative numbers?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Jolt Country Forum Index -> Hugo's House of Horrors
View previous topic :: View next topic  
Author Message
RealNC



Joined: 07 Mar 2012
Posts: 914

PostPosted: Sat Mar 19, 2016 12:17 pm    Post subject: What's the deal with negative numbers? Reply with quote

I'm getting weirdness when writing negative numbers to disk:

Code:
writefile "test" {
    writeval (-1)
    writeval (-2)
}

readfile "test" {
    print number readval number readval
}


I'm getting 255 and 254 as output.

Can you guys please test on the official terp? Do you get the same result?
Back to top
View user's profile Send private message
Roody_Yogurt



Joined: 29 Apr 2002
Posts: 1993
Location: Milwaukee

PostPosted: Tue Mar 22, 2016 6:09 am    Post subject: Reply with quote

Whoops, I didn't see this thread, but yes, I can verify it gives those values with the official terp, too.
Back to top
View user's profile Send private message AIM Address
RealNC



Joined: 07 Mar 2012
Posts: 914

PostPosted: Tue Mar 22, 2016 8:31 am    Post subject: Reply with quote

Thanks. Good to know it's not just me. This is obviously going to affect opcodes that take negative values, so it needs fixing at some point.
Back to top
View user's profile Send private message
Roody_Yogurt



Joined: 29 Apr 2002
Posts: 1993
Location: Milwaukee

PostPosted: Tue Mar 22, 2016 8:37 am    Post subject: Reply with quote

I'm sure you already know all this, but here's what the manual says about negative numbers:

Quote:
VALUE (i.e., INTEGER CONSTANT):
<value> <2>
A value may range from -32768 to 32767; negative numbers follow signed-value
16-bit convention by being x + 65536 where x is a negative number.
For example, the values 10 ($0A), 16384 ($4000), and -2 would be written
as:
$4B 0A 00
$4B 00 40
$4B FE FF ($FFFE = 65534 = -2 + 65536)


Does writing to file use a different type of encoding so something is lost in translation?

(I have no idea how any of this works)
Back to top
View user's profile Send private message AIM Address
RealNC



Joined: 07 Mar 2012
Posts: 914

PostPosted: Tue Mar 22, 2016 8:59 am    Post subject: Reply with quote

The issue is that what actually happens when writing numbers to a file doesn't follow that description, as is apparent when trying to read the value back. You get something different than what you wrote.

The engine writes two bytes per value to files, in little-endian format. Except that for negative numbers between -1 and -255 it writes the same bytes as for the positive numbers between 255 and 1.

"writeval (-1)" writes "FF 00". "writeval 255" also writes "FF 00".

Looks like a bug.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Jolt Country Forum Index -> Hugo's House of Horrors All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001 phpBB Group

Theme by Kage Musha - RPG Garden

Copyrights and trademarks are all of the belonging company. No copyright Infringement intended