美文网首页
ginac库判断数字类型

ginac库判断数字类型

作者: 一路向后 | 来源:发表于2020-10-12 21:21 被阅读0次

    1.程序源码

    #include <iostream>
    #include <ginac/ginac.h>
    
    using namespace std;
    using namespace GiNaC;
    
    int main()
    {
            //定义整数
            numeric a = 20;
            numeric b = 30;
            numeric c = -20;
    
            //是不是零
            numeric d = a.is_zero();
    
            //是不是大于0
            numeric e = a.is_positive();
    
            //是不是小于0
            numeric f = c.is_negative();
    
            //是不是整数
            numeric g = b.is_integer();
    
            //是不是大于0的整数
            numeric h = c.is_pos_integer();
    
            //是不是大于或等于0的整数
            numeric i = b.is_nonneg_integer();
    
            //是不是偶数
            numeric j = a.is_even();
    
            //是不是奇数
            numeric k = a.is_odd();
    
            //是不是质数
            numeric l = b.is_prime();
    
            //是不是有理数
            numeric m = c.is_rational();
    
            //是不是实数
            numeric n = a.is_real();
    
            //是不是整复数
            numeric o = b.is_cinteger();
    
            //是不是有理复数
            numeric p = c.is_crational();
    
            //打印输出结果
            cout << d << endl;
            cout << e << endl;
            cout << f << endl;
            cout << g << endl;
            cout << h << endl;
            cout << i << endl;
            cout << j << endl;
            cout << k << endl;
            cout << l << endl;
            cout << m << endl;
            cout << n << endl;
            cout << o << endl;
            cout << p << endl;
    
            return 0;
    }
    

    2.编译源码

    $ g++ -o example example.c -lginac -lcln -I/usr/local/include -L/usr/local/lib64
    

    3.运行结果

    ./example
    0
    1
    1
    1
    0
    1
    1
    0
    0
    1
    1
    1
    1
    

    相关文章

      网友评论

          本文标题:ginac库判断数字类型

          本文链接:https://www.haomeiwen.com/subject/nbwppktx.html