123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?xml version="1.0" encoding="utf-8"?>
- <!--
-
- h t t :: / / t /
- h t t :: // // t //
- h ttttt ttttt ppppp sssss // // y y sssss ttttt //
- hhhh t t p p s // // y y s t //
- h hh t t ppppp sssss // // yyyyy sssss t //
- h h t t p s :: / / y .. s t .. /
- h h t t p sssss :: / / yyyyy .. sssss t .. /
-
- <https://y.st./>
- Copyright © 2017 Alex Yst <mailto:copyright@y.st>
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org./licenses/>.
- -->
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <base href="https://y.st./en/weblog/2017/06-June/04.xhtml" />
- <title>32-bit integers! <https://y.st./en/weblog/2017/06-June/04.xhtml></title>
- <link rel="icon" type="image/png" href="/link/CC_BY-SA_4.0/y.st./icon.png" />
- <link rel="stylesheet" type="text/css" href="/link/basic.css" />
- <link rel="stylesheet" type="text/css" href="/link/site-specific.css" />
- <script type="text/javascript" src="/script/javascript.js" />
- <meta name="viewport" content="width=device-width" />
- </head>
- <body>
- <nav>
- <p>
- <a href="/en/">Home</a> |
- <a href="/en/a/about.xhtml">About</a> |
- <a href="/en/a/contact.xhtml">Contact</a> |
- <a href="/a/canary.txt">Canary</a> |
- <a href="/en/URI_research/"><abbr title="Uniform Resource Identifier">URI</abbr> research</a> |
- <a href="/en/opinion/">Opinions</a> |
- <a href="/en/coursework/">Coursework</a> |
- <a href="/en/law/">Law</a> |
- <a href="/en/a/links.xhtml">Links</a> |
- <a href="/en/weblog/2017/06-June/04.xhtml.asc">{this page}.asc</a>
- </p>
- <hr/>
- <p>
- Weblog index:
- <a href="/en/weblog/"><abbr title="American Standard Code for Information Interchange">ASCII</abbr> calendars</a> |
- <a href="/en/weblog/index_ol_ascending.xhtml">Ascending list</a> |
- <a href="/en/weblog/index_ol_descending.xhtml">Descending list</a>
- </p>
- <hr/>
- <p>
- Jump to entry:
- <a href="/en/weblog/2015/03-March/07.xhtml"><<First</a>
- <a rel="prev" href="/en/weblog/2017/06-June/03.xhtml"><Previous</a>
- <a rel="next" href="/en/weblog/2017/06-June/05.xhtml">Next></a>
- <a href="/en/weblog/latest.xhtml">Latest>></a>
- </p>
- <hr/>
- </nav>
- <header>
- <h1>32-bit integers!</h1>
- <p>Day 00820: Sunday, 2017 June 04</p>
- </header>
- <section id="general">
- <h2>General news</h2>
- <p>
- I began the morning preparing to do laundry, but I quickly realised I wanted to clean the sinks with my dirty dish towel before washing it.
- The kitchen sink was full of dishes, and I'm kind of tired of washing them by hand.
- I took a trip to Fred Meyer to get dish washer soap, and found some nice, eco-friendly powder.
- With the dishes loaded up, I scrubbed out both sinks, then started laundry.
- </p>
- <p>
- While the laundry machines did their thing, I worked on programming the bug fix for <code>minestats</code>.
- While I was at it, I almost-entirely rewrote the mod.
- I needed some code to be run after all mods had loaded, but before any players acted, so I looked for an <abbr title="application programming interface">API</abbr> function I'm almost certain I saw used in a subgame.
- If I recall, it took a function as an argument, then ran that function right before the map generator was set up.
- I searched through the properties and functions contained in the <code>minetest</code> table, but I never could find that function.
- Instead though, I found a function for retrieving a mod-specific data storage object.
- I looked into the documentation on it, and it's got the option of storing integer data, not just strings like what I've been using.
- I tested it out with the numbers <code>99999999999999</code> and <code>-99999999999999</code>, the highest and lowest integers that Lua will correctly store as strings, along with the numbers just out of bounds, <code>100000000000000</code> and <code>-100000000000000</code>.
- I needed to know how the integer storage would handle these numbers.
- Would real integer storage allow me to transcend the limits of Lua number strings?
- As it turned out, no it did not.
- The results I got were kind of strange, too, and I didn't understand them at first.
- <code>99999999999999</code> got changed into a shorter number with seemingly-random digits.
- So the integer had less bits and it had hit its limit and stopped.
- There had to be dome sort of cap, right?
- Wrong!
- <code>100000000000000</code> had been translated into the number one higher than <code>99999999999999</code> had been.
- <code>-99999999999999</code> and <code>-100000000000000</code> had been translated to the negative versions of those same two numbers.
- I did some experimenting to try to find the threshold, and found that when the numbers I tried to store were in certain ranges, their signs flipped.
- The integers were looping!
- I decided to pull out my Galculator so find likely thresholds, and tried <code>2^32</code> and <code>-2^32</code>.
- Both were stored as zero.
- I'd found my boundaries!
- </p>
- <p>
- Or, I suppose, not my boundaries, but my loop size.
- There's no limit, it just goes on forever.
- It's awesome!
- In a few minutes of spare time one day, I'd already implemented that same sort of looping into my use of the Lua number strings, though I hadn't gotten a chance to commit that to the repo' yet.
- Now, I had that same looping, but in a more natural way in my code (simply allowing the integer to wrap itself instead of testing the value of the integer before deciding to either increment or send to the far negative).
- Additionally, 32-bit integers are just so much cooler and geekier than signed, 14-digit, base-10 numbers, even if the 32-bit numbers have less storage potential.
- This is absolutely fantastic!
- I'm so excited.
- The 32-bit integers are signed, but in cases where I need to know the value of the integer (as opposed to simply incriminating it), I unfold it to be unsigned, with a maximum value of <code>4294967295</code>.
- No one should reach the limit in my mod.
- </p>
- <p>
- As I said, I did a nearly-total rewrite of the mod.
- The mod now shows the player all minerals that can be collected before they've found them.
- This lets players know what to look for, and also lets mod developers and server administrators very quickly test to see if their mods are supported.
- Minerals are also displayed in alphabetical order (by internal name, not player-facing name), not in order of which minerals a player has the most of.
- This provides consistent ordering.
- When mineral-defining mods are removed, the minerals they defined are no longer displayed as unknown items on the stats page, either.
- They're immediately hidden (though their data isn't removed, in case the mod is reinstalled later).
- If no minerals are defined, the stats page becomes hidden from all players.
- Support for <code>unified_inventory</code> has been dropped.
- <code>unified_inventory</code> is too inflexible for full support, so I implemented partial support before.
- Partial support makes my mod look broken though, so I'm done with that.
- <code>unified_inventory</code> is an ugly mess, both in how it works and in how it looks.
- I'm done with it.
- Everything's in working order, with one exception.
- The old database format is no longer used.
- I need to build code to read the old files, then add their data to the new database.
- Until I do that, I can't commit to the repo', as it'll break stuff for people that used an old version of my mod.
- I can do that, then remove the data from the files, but there are a couple of problems.
- First, I can't get a list of the existing files, each of which is named after a player.
- I have to wait until that player logs in, check to see if they have an old database file, then read it and update the main database.
- The second issue is that I can't remove the old files or the old directory.
- If I was writing a program, I could do it, but instead, I'm working from within Minetest's sandbox.
- </p>
- <p>
- I forgot to change out of my work shoes until it was too late.
- The head manager was speeding things up, and brought my bike out from the back room.
- Normally, I'd go back there to get it, and switch back to my street shoes while I was back there.
- It threw me off a little, and I forgot to change shoes until the manager had set the alarm and locked us both out.
- Oh, well.
- I'll get my street shoes back tomorrow.
- </p>
- <p>
- My <a href="/a/canary.txt">canary</a> still sings the tune of freedom and transparency.
- </p>
- </section>
- <hr/>
- <p>
- Copyright © 2017 Alex Yst;
- You may modify and/or redistribute this document under the terms of the <a rel="license" href="/license/gpl-3.0-standalone.xhtml"><abbr title="GNU's Not Unix">GNU</abbr> <abbr title="General Public License version Three or later">GPLv3+</abbr></a>.
- If for some reason you would prefer to modify and/or distribute this document under other free copyleft terms, please ask me via email.
- My address is in the source comments near the top of this document.
- This license also applies to embedded content such as images.
- For more information on that, see <a href="/en/a/licensing.xhtml">licensing</a>.
- </p>
- <p>
- <abbr title="World Wide Web Consortium">W3C</abbr> standards are important.
- This document conforms to the <a href="https://validator.w3.org./nu/?doc=https%3A%2F%2Fy.st.%2Fen%2Fweblog%2F2017%2F06-June%2F04.xhtml"><abbr title="Extensible Hypertext Markup Language">XHTML</abbr> 5.1</a> specification and uses style sheets that conform to the <a href="http://jigsaw.w3.org./css-validator/validator?uri=https%3A%2F%2Fy.st.%2Fen%2Fweblog%2F2017%2F06-June%2F04.xhtml"><abbr title="Cascading Style Sheets">CSS</abbr>3</a> specification.
- </p>
- </body>
- </html>
|