sqrt_expr.cc

来自「由matlab开发的hybrid系统的描述语言」· CC 代码 · 共 72 行

CC
72
字号
#include "Sqrt_expr.h"#include "Affine_func.h"#include "Real_number.h"#include <stdio.h>#include "Globals.h"#include "Problem.h"#include "Problem_handler.h"Sqrt_expr::Sqrt_expr(Expr * c) : Unary_expr(c) {}void Sqrt_expr::semantic_checks() {	child->semantic_checks();	assert(child->is_real()); //fine}Affine_func * Sqrt_expr::compute_affine() const {	Affine_func * aff;	aff = new Affine_func(clone(), globals); // put this as constant	return aff;}bool Sqrt_expr::is_affine() const {	return child->is_const();}bool Sqrt_expr::is_number() const {	return child->is_number();}Number * Sqrt_expr::compute_number() const {	Real_number * num;	num = (Real_number *) child->compute_number();	num->sqrt();	return num;}string Sqrt_expr::arg_range_check_matlab() const {	string res;	string msg;	char buf[100];	res += Unary_expr::arg_range_check_matlab();	if (child->is_number()) { // warn if = 0 ???		if (((Real_number *) child->compute_number())->get_double() < 0.0) {			sprintf(buf, "line %d: ", get_source_line());			msg = buf;			msg += string("sqrt of negative (") +				child->get_source() + string(")");			globals->problem_handler->process(				new Problem(ERROR, msg));		}	} else if (child->is_const()) {		res += string("if ") + child->to_matlab() + string(" < 0.0") +			string(" then error(\'");		sprintf(buf, "line %d: ", get_source_line());		res += buf;		res += string("sqrt of negative (") +			child->get_source() + string(")");		res += string("\'); end\n");	}	return res;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?