Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #112084

Re: Float

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Newsgroups comp.lang.python
Subject Re: Float
Date 2016-07-30 12:03 -0400
Organization IISS Elusive Unicorn
Message-ID <mailman.54.1469895489.6033.python-list@python.org> (permalink)
References (2 earlier) <367666cb-224f-4b16-88bb-cd1ada13a13b@googlegroups.com> <579c82a6$0$1619$c3e8da3$5496439d@news.astraweb.com> <e5d77dc3-2fe4-4352-9582-8a259f3c4f9d@googlegroups.com> <CAPTjJmri1uAicp_VnZ+b3+goWASGkW4yaAKJdLqcbs2N72Sz_Q@mail.gmail.com> <apjppbtocn2vs6v581clq8470on5b14sce@4ax.com>

Show all headers | View raw


On Sat, 30 Jul 2016 21:51:29 +1000, Chris Angelico <rosuav@gmail.com>
declaimed the following:


>In a computing context, data types are incredibly significant. So yes,
>3.0 *is* a floating-point number. It's equal to the integer 3, because
>they represent the same number, but it's not identical to it. You can
>convert from one to the other with the built-ins int and float:
>
>>>> 3.0 == 3
>True
>>>> int(3.0)
>3
>>>> float(3)
>3.0

	And in a rather convoluted route, one can get to the underlying
representation...

>>> import struct
>>> f = struct.pack(">f", 3.0)
>>> i = struct.pack(">i", 3)
>>> fi = struct.unpack(">i", f)
>>> ii = struct.unpack(">i", i)	#really a waste of time
>>> "0x%8.8X 0x%8.8X" % (fi[0], ii[0])
'0x40400000 0x00000003'
>>> 
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Float Cai Gengyang <gengyangcai@gmail.com> - 2016-07-29 02:44 -0700
  Re: Float Lutz Horn <lutz.horn@posteo.de> - 2016-07-29 11:56 +0200
  Re: Float Ben Finney <ben+python@benfinney.id.au> - 2016-07-29 20:25 +1000
  Re: Float Steven D'Aprano <steve@pearwood.info> - 2016-07-30 00:26 +1000
    Re: Float Cai Gengyang <gengyangcai@gmail.com> - 2016-07-30 03:21 -0700
      Re: Float Steven D'Aprano <steve@pearwood.info> - 2016-07-30 20:34 +1000
        Re: Float Cai Gengyang <gengyangcai@gmail.com> - 2016-07-30 04:44 -0700
          Re: Float Chris Angelico <rosuav@gmail.com> - 2016-07-30 21:51 +1000
            Re: Float Rustom Mody <rustompmody@gmail.com> - 2016-07-30 20:20 -0700
              Re: Float Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-08-04 00:28 -0700
          Re: Float Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-07-30 12:03 -0400
          Re: Float eryk sun <eryksun@gmail.com> - 2016-07-30 18:19 +0000

csiph-web