Thoughts off the top of your head

Kick back and chat it up with other Jeeves Smackers.

Re: Thoughts off the top of your head

Postby Randumbz » January 13th, 2018, 11:38 pm

I change my hairstyle way too often. But I can't really help myself. I just get tired of having the same thing for too long.
Spoiler! :
Image
User avatar
Randumbz
 
Posts: 1314
Joined: November 10th, 2010, 4:31 pm
Location: Impel Down

Re: Thoughts off the top of your head

Postby HopelessSpirit » January 14th, 2018, 4:09 pm

Why is it so cute to me that raccoons wash their food???????????/ Like they do better than most people
User avatar
HopelessSpirit
 
Posts: 2
Joined: January 10th, 2018, 1:55 pm

Re: Thoughts off the top of your head

Postby UrbanMysticDee » January 19th, 2018, 7:06 pm

"Kills 99.9% of bacteria. The other 0.1% is just really pissed off."
Image Image
Image
Image Image
User avatar
UrbanMysticDee
 
Posts: 3857
Joined: March 13th, 2010, 12:33 am

Re: Thoughts off the top of your head

Postby mitchellbravo » January 19th, 2018, 8:43 pm

UrbanMysticDee wrote:"Kills 99.9% of bacteria. The other 0.1% is just really pissed off."

~the one that got away~
oly: we draw stories about imaginary people
Image
Do not feet infants to honey under one year of age.
me: Posh, Baby, Sporty, and Scary Ham
robybang: Together they're Spiced Ham
User avatar
mitchellbravo
 
Posts: 6336
Joined: October 11th, 2010, 1:31 pm
Location: too tired

Re: Thoughts off the top of your head

Postby kevansevans » January 22nd, 2018, 11:18 pm

One of the most frustrating things I've encountered as a programmer is when a framework takes the lazy way out when saving float (decimal) precision. This absolutely axes any possibility of completely deterministic physics engines if the engine rounds off the numbers when taken out of memory and saved into a file.
User avatar
kevansevans
 
Posts: 1492
Joined: October 17th, 2010, 11:59 pm

Re: Thoughts off the top of your head

Postby JoKeR » January 22nd, 2018, 11:36 pm

kevansevans wrote:One of the most frustrating things I've encountered as a programmer is when a framework takes the lazy way out when saving float (decimal) precision. This absolutely axes any possibility of completely deterministic physics engines if the engine rounds off the numbers when taken out of memory and saved into a file.

I don't even...
Image

-=: jokercologne.deviantart twitter.com/JoKeRcologne joker-cologne.tumblr :=-

Expect the unexpected. Never take anything for granted. Scrutinise everything. Be open-minded. Learn.
User avatar
JoKeR
 
Posts: 2503
Joined: June 10th, 2010, 3:42 am
Location: A City with a huge cathedral

Re: Thoughts off the top of your head

Postby kevansevans » January 22nd, 2018, 11:44 pm

JoKeR wrote:
kevansevans wrote:One of the most frustrating things I've encountered as a programmer is when a framework takes the lazy way out when saving float (decimal) precision. This absolutely axes any possibility of completely deterministic physics engines if the engine rounds off the numbers when taken out of memory and saved into a file.

I don't even...


Computer saves numbers wrong. I can't have them be wrong. I will punch a wall if I can't figure this out.
User avatar
kevansevans
 
Posts: 1492
Joined: October 17th, 2010, 11:59 pm

Re: Thoughts off the top of your head

Postby eishiya » January 23rd, 2018, 9:09 am

kevansevans wrote:One of the most frustrating things I've encountered as a programmer is when a framework takes the lazy way out when saving float (decimal) precision. This absolutely axes any possibility of completely deterministic physics engines if the engine rounds off the numbers when taken out of memory and saved into a file.

The lazy way is to just write the bytes out without converting to decimal or any other human-readable representation. They had to put in extra work to do it a different way that hurts the data representation.
See if the framework allows binary mode for saves or something like that. If not, you could save the data you need in a custom field as a string, converting the bytes of the float to character bytes. It'll give nonsense text, but it'll keep all the data, at least as long as you can guarantee that nothing will try to re-encode the save file.

What framework is this?
Image
User avatar
eishiya
 
Posts: 9362
Joined: December 5th, 2009, 11:17 am

Re: Thoughts off the top of your head

Postby kevansevans » January 23rd, 2018, 4:17 pm

Haxe. And believe me I’ve tried several billion solutions. The second a float gets told to be a string, it gets rounded to the thousandth place. I’ve even tried brute forcing my own float to string conversion, and it works fine until a local var in the function overflows.
User avatar
kevansevans
 
Posts: 1492
Joined: October 17th, 2010, 11:59 pm

Re: Thoughts off the top of your head

Postby eishiya » January 23rd, 2018, 4:38 pm

By saving it as a string, I meant dumping the var to string without doing any sort of conversion (i.e. dump the bytes to string as chars). JSON.stringify does a conversion, so it can't guarantee precision. Dumping the bytes to string is basically the only implementation-independent way to do it. I'm not sure that Haxe allows that, but I've not used it myself. (And hey, now I know to avoid it until they deal with your bug report xP)
Image
User avatar
eishiya
 
Posts: 9362
Joined: December 5th, 2009, 11:17 am

Re: Thoughts off the top of your head

Postby kevansevans » January 23rd, 2018, 8:23 pm

eishiya wrote: dumping the var to string without doing any sort of conversion


kevansevans wrote:And believe me I’ve tried several billion solutions.


Even something as basic as
Code: Select all
return "" + float;
does not work. I wouldn't be this frustrated if the solution was that easy.
User avatar
kevansevans
 
Posts: 1492
Joined: October 17th, 2010, 11:59 pm

Re: Thoughts off the top of your head

Postby eishiya » January 23rd, 2018, 9:23 pm

kevansevans wrote:
eishiya wrote: dumping the var to string without doing any sort of conversion


kevansevans wrote:And believe me I’ve tried several billion solutions.


Even something as basic as
Code: Select all
return "" + float;
does not work. I wouldn't be this frustrated if the solution was that easy.

Your example does a conversion in just about every language, it tries to make a string version of your float instead of using the bytes directly as if they're already a string. A dump would be something like
Code: Select all
return (string)myFloat;
(depending on how the language handles casting, some languages will do a conversion in this case), or
Code: Select all
string myString = memcpy(myFloat);
return myString;

Not all languages allow you to do this sort of stuff, though. If Haxe doesn't and you're compiling Haxe to C++ though, you can probably use an external C++ or C function to do this sort of thing instead of doing it in Haxe.
Image
User avatar
eishiya
 
Posts: 9362
Joined: December 5th, 2009, 11:17 am

Re: Thoughts off the top of your head

Postby kevansevans » January 24th, 2018, 2:22 am

Not even casting has worked, and I can't use external C++ libraries without modifying the main Haxe compiler, which is something I want to avoid for an open source project. I have however had a huge epiphany and found a god send of a solution, which I am equally annoyed at myself as I am proud of myself for figuring this out.

Spoiler! :
Code: Select all
private var cutOff:Int64 = 0;
   private var decimalOffSet:Int = 1;
   function getFloatStringWithPrecision(_v:Float):String {
      var _locIsNegative:Bool = false;
      if (_v % 1 == 0) {
         return "" + _v;
      }
        var _locFloat64:Float = _v;
      if (_locFloat64 < 0) {
         _locFloat64 *= -1;
         _locIsNegative = true;
      }
        var _locInt64:Int64 = Int64.fromFloat(_locFloat64);
      var _locBuildString:String = "" + _locInt64;
      this.cutOff = this.getCutOffValue(_locFloat64);
      while (true) {
         _locFloat64 *= 10;
         _locInt64 = Int64.fromFloat(_locFloat64);
         var tempString = "" + _locInt64;
         _locBuildString += tempString.substring(tempString.length - 1, tempString.length);
         if (_locFloat64 > this.cutOff.low) {
            var sub:Int64 = (Int64.fromFloat(_locFloat64) / cutOff) * cutOff;
            trace(_locFloat64, sub);
            _locFloat64 -= sub.low;
         }
         if (_locBuildString.length >= 17) {
            _locBuildString = this.truncate(_locBuildString);
            var forString:String = _locBuildString.substring(0, decimalOffSet);
            var latString:String = _locBuildString.substring(decimalOffSet, _locBuildString.length);
            var signString:String = "";
            if (_locIsNegative) {
               signString = "-";
            }
            var returnString:String = signString + forString + "." + latString;
            return returnString;
         }
      }
    }
   function truncate(_s:String):String {
      var _locString:String = _s;
      while (true) {
         if (_locString.substring(_locString.length - 1, _locString.length) == "0") {
            _locString = _locString.substring(0, _locString.length - 1);
         } else {
            return _locString;
         }
      }
   }
   function getCutOffValue(_v:Float):Int64 {
      var mod:Int = 1;
      this.decimalOffSet = 1;
      while (true) {
         if (_v / mod > 10) {
            ++decimalOffSet;
            mod *= 10;
            continue;
         } else {
            return mod;
         }
      }
   }


tl;dr, I keep multiplying the number by 10, add the number in the 1's place to the string, subtract an arbitrary value if the number gets too big to prevent overflow, then stick the decimal in when it's a string. Work so smoothly.
User avatar
kevansevans
 
Posts: 1492
Joined: October 17th, 2010, 11:59 pm

Re: Thoughts off the top of your head

Postby eishiya » January 24th, 2018, 8:43 am

Glad to see you found a method that works! All those "while(true)" bits hurt my soul though.
Image
User avatar
eishiya
 
Posts: 9362
Joined: December 5th, 2009, 11:17 am

Re: Thoughts off the top of your head

Postby UrbanMysticDee » January 25th, 2018, 3:27 pm

When people want to sound pretentious they pronounce Pulitzer as "Pyoolitzer". The official pulitzer.org website says right there on the front page the correct pronunciation is "Pull-it-sir". I think the organisation knows the correct pronunciation of their own name.
Image Image
Image
Image Image
User avatar
UrbanMysticDee
 
Posts: 3857
Joined: March 13th, 2010, 12:33 am

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 9 guests