aboutsummaryrefslogblamecommitdiff
path: root/builtin.h
blob: 589e7a9ee51fa979b98afe991e3342ccdf423f1f (plain) (tree)
1
2
3
4
5
6
7
8
9




                  
                  


                  
                        


                                                
   
                                    
           











                                               
                                                  



                                                                   
                                         
 


                               
                               


                           


                          

                     
   
                                        
           







                                                                
                                         
 


                               
                               


                           
                          
 

  


                                          
   
                                  
           







                                     
                   


                                          



                                 
                                                 



                                                                    
                                        
 


                               
                               


                           







                                     
                   

                                  
                           
                    



                                  
                    
      




                                                            
                                        
 


                               
                               


                           













                                                                               
                                               




                                                                              
                                                    


                                   

                                                       
                                                                








                                              

                                                       

                                                                








                                              

                                                       
                                                                








                                           

                                                       
                                                                


                          





                                             

                                                       




                                                                







                                                                     

                                                       




                                                                




                                                      
                          





                          

                                 











                               


                            

                            
 

                         
                          
 
 
      
#ifndef BUILTIN_H
#define BUILTIN_H

#include "model.h"
#include <string>
#include <gmpxx.h>

using std::string;

bool is_list(Pair *ptr);

/** @class InexactNumObj
 * Inexact number implementation (using doubles)
 */
class InexactNumObj: public NumObj {
    public:
        InexactNumObj(NumLvl level);
};

/** @class CompNumObj
 * Complex numbers
 */
class CompNumObj: public InexactNumObj {
    public:
        double real, imag;

        /** Construct a complex number */
        CompNumObj(double _real, double _imag);
        /** Try to construct an CompNumObj object 
         * @return NULL if failed
         */
        static CompNumObj *from_string(string repr);
        /** Convert to a complex number from other numeric types */
        CompNumObj *convert(NumObj* obj);

        NumObj *add(NumObj *r);
        NumObj *sub(NumObj *r);
        NumObj *mul(NumObj *r);
        NumObj *div(NumObj *r);
        bool lt(NumObj *r);
        bool gt(NumObj *r);
        bool eq(NumObj *r);
        string ext_repr();
};

/** @class RealNumObj
 * Real numbers
 */
class RealNumObj: public InexactNumObj {
    public:
        double real;
        /** Construct a real number */
        RealNumObj(double _real);
        /** Try to construct an RealNumObj object 
         * @return NULL if failed
         */
        static RealNumObj *from_string(string repr);
        /** Convert to a real number from other numeric types */
        RealNumObj *convert(NumObj* obj);

        NumObj *add(NumObj *r);
        NumObj *sub(NumObj *r);
        NumObj *mul(NumObj *r);
        NumObj *div(NumObj *r);
        bool lt(NumObj *r);
        bool gt