Package: ieee754
ieee754ieee754 is a Python module which finds the IEEE-754 representation of a floating point number. You can specify a precision given in the list below or you can even use your own custom precision.Half Precision (16 bit: 1 bit for sign + 5 bits for exponent + 10 bits for mantissa)Single Precision (32 bit: 1 bit for sign + 8 bits for exponent + 23 bits for mantissa)Double Precision (64 bit: 1 bit for sign + 11 bits for exponent + 52 bits for mantissa)Quadruple Precision (128 bit: 1 bit for sign + 15 bits for exponent + 112 bits for mantissa)Octuple Precision (256 bit: 1 bit for sign + 19 bits for exponent + 236 bits for mantissa)Prerequisitesieee754 does not require any external libraries or modules.InstallingTo download ieee754, either fork this github repo or simply use Pypi via pip.$pipinstallieee754UsingAfter installation, you can import ieee754 and use it in your projects.Simplest ExampleThe simplest example is to use the desired precision IEEE-754 representation of a floating point number. You can import the desired precision from ieee754 and use it like this. The available precisions arehalf,single,double,quadrupleandoctuple.fromieee754importdoubleprint(double(13.375))Default OptionsDefault precision is Double Precision and you can get the output by just calling the instance as a string.fromieee754importIEEE754x=13.375a=IEEE754(x)# you should call the instance as a stringprint(a)print(str(a))print(f"{a}")# you can get the hexadecimal presentation like thisprint(a.hex())# you can get more detailed information like thisprint(a.json())Select a PrecisionYou can use Half (p=0), Single (p=1), Double (p=2), Quadrupole (p=3) or Octuple precision (p=4).fromieee754importIEEE754forpinrange(5):a=IEEE754(x,p)print("x =%f| b =%s| h =%s"%(13.375,a,a.hex()))Use the Precision Name as an InterfaceYou can use the precision name as an interface to get the IEEE-754 representation of a floating point number. With this method you can get the IEEE-754 representation of a floating point number without creating an instance.fromieee754importhalf,single,double,quadruple,octuplex=13.375print(half(x))print(single(x))print(double(x))print(quadruple(x))print(octuple(x))Using a Custom PrecisionYou can force exponent, and mantissa size by usingforce_exponentandforce_mantissaparameters to create your own custom precision.a=IEEE754(x,force_exponent=6,force_mantissa=12)print(a)Finding the Error of a Floating Point NumberYou can find the error of a floating point number by using theconverted_numberanderrorproperties of the class.x=8.7a=IEEE754(x,1)print(f"{x}is converted as{a.converted_number}±{a.error}")LicenseMIT LicenseCopyright (c) 2021 Bora CanbulaPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.