Python浮点数比较

时间:2019-07-11 19:04:23

标签: python

为什么在10.0000000000000008之后减少小数部分时比较返回True?

// declaration and groundcase with only mandatory type (other cases
// intecepted by specializations)
template <typename MandT, typename ...>
struct MyClass
 {
   virtual void hello () = 0;

   virtual ~MyClass () {}

   virtual char * goodmorning (MandT const &) = 0;
 };

// groundcase with a single optional type
template <typename MandT, typename OptT>
struct MyClass<MandT, OptT>
 {
   virtual void hello (OptT const &) = 0;

   virtual ~MyClass () {}

   virtual char * goodmorning (MandT const &) = 0;
 };

// recursive case
template <typename MandT, typename OptT, typename ... MoreOptTs>
struct MyClass<MandT, OptT, MoreOptTs...>
   : public MyClass<MandT, MoreOptTs...>
 {
   using MyClass<MandT, MoreOptTs...>::hello;

   virtual void hello (OptT const &) = 0;

   virtual ~MyClass () {}
 };


struct Derived0 : public MyClass<char>
 {
   void hello () override { }

   char * goodmorning (char const &) override
    { return nullptr; }
 };
struct Derived1 : public MyClass<char, double>
 {
   void hello (double const &) override { }

   char * goodmorning (char const &) override
    { return nullptr; }
 };

struct Derived2 : public MyClass<char, double, int>
 {
   void hello (double const &) override { }
   void hello (int const &) override { }

   char * goodmorning (char const &) override
    { return nullptr; }
 };



int main()
 {
   Derived0  d0;
   Derived1  d1;
   Derived2  d2;

   d0.hello();
   d0.goodmorning('a');

   d1.hello(1.2);
   d1.goodmorning('b');

   d2.hello(3.4);
   d2.hello(5);
   d2.goodmorning('c');
 }

0 个答案:

没有答案