Skip to content

VSADX/true-binary-for-float64

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Converting true binary representation for float64


import { Binary } from "@vsadx/true-binary"

const some_num = 13

// `toString(2)` gives us the binary version of 13
some_num.toString(2) 

// this isn't how JavaScript sees numbers though, 
// it uses IEEE-754 floating point standard

// give it a try! 
Binary.stringify(13)

You can learn a lot about why some mathmatical operations are fast but other, even similar ones, are slower. In some cases, using the IEEE 754 format directly increased operation speeds for game developers at one time. This raw binary format lets you make speed vs accuracy tradeoffs more explicitly.

There are two methods so far; you can use stringify or parse. It is similar to the JSON object which also has those methods. In this case, there is no reviver parameter or much other configuration settings.


Convert a number to its binary

const string_binary = Binary.stringify(42)
console.log(string_binary)

Convert string binary back to the number

const num = Binary.parse(string_binary)
console.log(num) // 42, it's a match!

Using Binary

Live CDN link

<script src="https://cdn.jsdelivr.net/gh/VSADX/true-binary-for-float64@main/float-ieee.js" type="module"></script>

NPM Package
https://www.npmjs.com/package/@vsadx/true-binary

References
@\0kku

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published