generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: More Efficient Way?

Previous Thread :: Next Thread 
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Apr 2015 01:58 AM
I'm trying to convert 8 bytes of IEEE754 double-precision floating-point format into its decimal form.

So basically:
1100000001011110110000000000000000000000000000000000000000000000
Into: -123

My current method seems very inefficient (but it works, nonetheless) and it works like this:
- Create table to store bytes that were converted into their binary string in (a byte buffer essentially)
- Iterate backwards from 8 to 1 (because little-endian) and insert the next byte converted into a binary string
- Table.concat the byte buffer split by ""
(Giving us 1100000001011110110000000000000000000000000000000000000000000000)
- Get sign (buffer:sub(1, 1) == "1") [if negative]
- Get exponent (tonumber(buffer:sub(2, 12), 2) - 1023) [the 1023 is the bias]
- Get mantissa (buffer:sub(13))
(Gives us: 1 6 1110110000000000000000000000000000000000000000000000)
- For each bit in the mantissa, add (bit * (2 ^ (-bitIndex)))
(Gives us: 0.921875)
- Prepend the implied "1" to the fraction
(Gives us: 1.921875)
- Return the fraction * (2 ^ exponent) (if sign bit is true, return -1 * that)
(Gives us: -1 * (1.921875 * (2 ^ 6))

And finally, that evaluated will give us -123.

Due to all this string manipulation and tonumber/tostring I had to do, I'm led to believe this very inefficient (I guess that's what I get for doing this for the first time).

I've looked at math.frexp/math.ldexp and wonder if this could be so much more efficient.

Also, my reference for creating this inefficient poop:
http://en.wikipedia.org/wiki/Double-precision_floating-point_format#IEEE_754_double-precision_binary_floating-point_format:_binary64
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Apr 2015 02:06 AM
You think when I denormalize the mantissa:
"- For each bit in the mantissa, add (bit * (2 ^ (-bitIndex)))"
Would there be a significant average speed difference to NOT add if the current bit is 0?
Report Abuse
TehHolyOne is not online. TehHolyOne
Joined: 05 Jun 2012
Total Posts: 7
02 Apr 2015 02:15 AM
I would help with this but i suck at math and in all honesty i dont know how to simplify that in anyway...
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
02 Apr 2015 02:23 AM
I can't sleep tonight, so I am probably too tired to think much on this. I doubt I would be able to figure it out anyways.

But just a comment
Why are programmers cursed with knowledge of infinitesimal imperfections in efficiency, reasoning, logic, and cleanliness? It is annoying.

An example is how we obsess over the efficiency of code.
Another example is how I can't stand to use English, it is not precise enough.

An example of English that I don't like is
"I need to go to the store or Pizza Hut and pick up pizza."
Common sense tells you how it goes, right?
What if you grouped it like this though?
"I need to go to the store or (Pizza Hut and pick up pizza)"
"I need to go to the store or < Verb Absent > Pizza Hut and pick up pizza."
If I was to be correct and more perfect than anyone ever is:
"I need to go either (to the store or to Pizza Hut) and pick up pizza."

I hate this. I hate everything that isn't perfect.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Apr 2015 02:29 AM
10/10, the English language is for losers like me :(

Anyways, I'm mainly cursed with "the need for efficiency" because I can't stand leaving my code how it is if I know there is a much better way. Although I could really make what I'm doing much cleaner if I decided to use modules (instead of packing all libraries into a do-end block).
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
02 Apr 2015 02:32 AM
Wow. I need to do that just for the fun of it - make a massive script with hundreds of do-end blocks, all nested inside each other, all the way down to a depth of maybe 15 nested blocks.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Apr 2015 02:43 AM
I have probably like 3 or 4 do-ends but no do-end in a do-end (yet):
http://prntscr.com/6ohjap

But I do plan on rewritting this when I'm done to make it shorter and less cluttered I guess.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Apr 2015 02:47 AM
Also please don't make fun of me because waterfox (I love this browser) and MSE (because I'm too lazy to disable it) and command prompts (how I'm actually running my ugly code :( )
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
02 Apr 2015 02:48 AM
Wow. How can you stand having that many open windows? I can barely stand three open windows, even if one or two of them are pinned to the taskbar!
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Apr 2015 02:51 AM
Well Roblox itself was open because I left it open on accident.
VS is the Lua 5.1 source as my refeerence
2 calculators (1 in scientific mode, 1 in programmer mode) to double check my stuff
HxD (hex editor) to manually check if my output makes sense
2 Command prompts (1 which I use to run my program and other to run luac)
2 Notepads (a reference of mine and the script I'm running)
Sublime text (obv.)
2 Windows Explorer windows (folder of my program and folder of Lua binaries)
Waterfox (obv.)

I never could stand having this much open but I am actually using all of it, a lot :(
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Apr 2015 02:52 AM
Well, this quickly derailed into a "why are you so dumb CntKillMe" :((
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
02 Apr 2015 02:55 AM
"Waterfox"?
I have never heard of it. I assumed it was Firefox Nightly, because I had heard about that in my programming class a year or two ago. Never mind explaining, I'll just search it after posting.

Wow, I am far too OCD for my liking, as this thread clearly shows. Then again, I also appear to have OCPD traits too. Not good.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
02 Apr 2015 03:06 AM
This isn't a "why are you so dumb, cntkillme", this is a rant about how cursed I am with this stuff.

Oh, and by the way, I did it :D

pastebin
/x5B7JraD
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Apr 2015 03:11 AM
Oh god, this is true efficiency
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Apr 2015 03:21 AM
Well, my method just flat out doesn't work with non-integer it seems. GOD DAMNIT OMG

Well, now I have no clue of a better way.................................
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
02 Apr 2015 03:26 AM
D:
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Apr 2015 03:31 AM
qq
http://prntscr.com/6ohvtz

h3lp m3 g0d
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
02 Apr 2015 03:39 AM
Don't get a rope. Hey, you seem to know what you're doing a whole lot more than I do.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Apr 2015 03:39 AM
WAIT LOL
I didn't make a mistake, my idiot self just did
'return (inf and (sign .. ".#INF")) or (sign * (mantissa * (2 ^ exponent)))'
Instead of
'return (inf and (sign .. ".#INF")) or (sign * (fraction * (2 ^ exponent)))'
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Apr 2015 03:40 AM
What a great birthday present, to actually have something working as it should (just not as efficiently) :)
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
02 Apr 2015 04:07 AM
Just for the fun of it, I checked who posted most here.
Teh posted 1.7975% of the characters,
you posted 63.3373% of the characters,
and I posted 34.8652% of the characters.
This data includes the characters from this post.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Apr 2015 04:10 AM
lol.

Anyways, I'm going to do all the functions using recursion (since function inside functions exist and I gotta make sure to get those). And I hate recursion but oh well. Actually I should first probably clean up my horrible code :(
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
02 Apr 2015 04:21 AM
If this was me doing it:
"I need to make a change to this code. Oh wait! I understand it much more now, so I can re-write the entirety of it loads better in half the time!"
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
02 Apr 2015 04:24 AM
Yup, pretty much. Although I lied, I am basically done (all I really need to do now is print out a user-friendly way to read it and completely test it [although it should be fine, and Lua chunks could be so much smaller if the developers put a byte whether 'debug information' was stripped and not waste about a trillion bytes).
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
02 Apr 2015 04:32 AM
So what is this you're making? If it is a bytecode parser, I will be upset. Everyone knows how to make those but me. (Oh well, I have the resources to make it if I wanted to (In fact, it's pretty much given to me (Nested parentheses in English is cool. I wish I was still in school so I could use them on essays to make the teacher freak out)))
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image