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


Groups > comp.lang.python > #38084

Re: Floating point calculation problem

Date 2013-02-02 11:19 -0700
From Michael Torrie <torriem@gmail.com>
Subject Re: Floating point calculation problem
References <keipl5$kif$1@dont-email.me><mailman.1289.1359801291.2939.python-list@python.org><keisev$7v1$1@dont-email.me><mailman.1291.1359804020.2939.python-list@python.org><keitk2$hln$1@dont-email.me><mailman.1292.1359805138.2939.python-list@python.org><keiujd$o71$1@dont-email.me> <mailman.1293.1359806334.2939.python-list@python.org> <kejcfi$s70$1@dont-email.me>
Newsgroups comp.lang.python
Message-ID <mailman.1298.1359829190.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 02/02/2013 08:48 AM, Schizoid Man wrote:
> Also, if the cast is necessary, then now exactly does the dynamic typing 
> work?

Dynamic typing isn't referring to numeric type coercion.  It refers to
the fact that a name can be bound to an object of any type.  So if you
made a function like this:

def add (num1, num2):
    return num1 + num2

num1 and num2 could be any type.  Even a custom type if you wanted.
This function would work properly on any type that had implemented the
__add__ method.  And whether or not num2 has to be the same type as num1
depends on whether the num1 type has implemented an __add__ method that
can deal with the type of num2.

Another case where dynamic typing comes into play is in a case know as
duck typing:

def squeeze_duck (duck):
	// return the quack
	return duck.squeeze()


duck can be of any type as well, but as long as it implements the
squeeze method, this function will work with an object of that type.

In a language like C#, duck-typing can only be emulated by using
interface classes.

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


Thread

Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 10:27 +0000
  Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-02 21:34 +1100
    Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 11:14 +0000
      Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-02 22:20 +1100
        Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 11:34 +0000
          Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-02 22:38 +1100
            Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 11:51 +0000
              Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-02 22:58 +1100
                Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 15:48 +0000
                Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 15:54 +0000
                Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-03 03:00 +1100
                Re: Floating point calculation problem Michael Torrie <torriem@gmail.com> - 2013-02-02 11:19 -0700
                Re: Floating point calculation problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-03 12:25 +1100
                Re: Floating point calculation problem Dave Angel <d@davea.name> - 2013-02-02 21:20 -0500
                Re: Floating point calculation problem Michael Torrie <torriem@gmail.com> - 2013-02-02 21:22 -0700
              Re: Floating point calculation problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-02 23:11 +1100
      Re: Floating point calculation problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-02 22:45 +1100
        Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 11:50 +0000
  Re: Floating point calculation problem Chris Rebert <clp2@rebertia.com> - 2013-02-02 02:47 -0800
  Re: Floating point calculation problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-02 23:05 +1100

csiph-web