<commit_before>/**
 * @file NumericsImpl.cpp
 * @author <NAME> (<EMAIL>)
 * @copyright 2006-2007 FLWOR Foundation (flworfound.org)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include "NumericsImpl.h"
#include "util/tracer.h"
#include <iostream>

using namespace std;
namespace xqp {


op_numeric_binary_iterator::op_numeric_binary_iterator(
	yy::location loc, 
	iterator_t _arg0,
	iterator_t _arg1)
:
	BasicIterator(loc),
	arg0(_arg0),
	arg1(_arg1)
{
}

void op_numeric_binary_iterator::_open()
{
	arg0->open();
	arg1->open();
}

void op_numeric_binary_iterator::_close()
{
	arg0->close();
	arg1->close();
}

bool op_numeric_binary_iterator::done() const
{
	return (arg0->done() || arg1->done());
}



/*______________________________________________________________________
|  
|	6.2.1 op:numeric-add
|	op:numeric-add($arg1 as numeric, $arg2 as numeric) as numeric
|	
|	Summary: Backs up the "+" operator and returns the arithmetic sum of 
|	its operands: ($arg1 + $arg2).
|	
|	Note:
|	For xs:float or xs:double values, if one of the operands is a zero or 
|	a finite number and the other is INF or -INF, INF or -INF is returned. 
|	If both operands are INF, INF is returned. If both operands are -INF, 
|	-INF is returned. If one of the operands is INF and the other is -INF, 
|	NaN is returned.
|_______________________________________________________________________*/

// op_numeric_add_iterator::op_numeric_add_iterator(
// 	yy::location loc, 
// 	iterator_t arg0,
// 	iterator_t arg1)
// :
// 	op_numeric_binary_iterator(loc,arg0,arg1)
// {
// }


/**
 * TODO FIXME This is not the GENERIC_ADD_ITERATOR!!!! No type checking is performend! 
 */
item_t op_numeric_add_iterator::nextImpl(){
	item_t n0_h = this->consumeNext(arg0);

	if(&*n0_h == NULL)
		return NULL;

	item_t n1_h = this->consumeNext(arg1);

	if(&*n1_h == NULL)
		return NULL;

	if (n0_h == NULL || n1_h == NULL) {
		return NULL;
	} else {
		const numericValue& n0 = dynamic_cast<const numericValue&>(*n0_h);
		const numericValue& n1 = dynamic_cast<const numericValue&>(*n1_h);
		return new numericValue(xs_decimal, n1.val() + n0.val());
	}
}
// void op_numeric_add_iterator::resetImpl(){
// 	this->resetChild(this->arg0);
// 	this->resetChild(this->arg1);
// }

// item_t op_numeric_add_iterator::_next()
// {
// 	item_t n0_h = arg0->next();
// 
// 	if(&*n0_h == NULL)
// 		return NULL;
// 
// 	item_t n1_h = arg1->next();
// 
// 	if(&*n1_h == NULL)<commit_msg>Changed the add_iter to use the duffs device<commit_after>/**
 * @file NumericsImpl.cpp
 * @author <NAME> (<EMAIL>)
 * @copyright 2006-2007 FLWOR Foundation (flworfound.org)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include "NumericsImpl.h"
#include "util/tracer.h"
#include <iostream>

using namespace std;
namespace xqp {


op_numeric_binary_iterator::op_numeric_binary_iterator(
	yy::location loc, 
	iterator_t _arg0,
	iterator_t _arg1)
:
	BasicIterator(loc),
	arg0(_arg0),
	arg1(_arg1)
{
}

void op_numeric_binary_iterator::_open()
{
	arg0->open();
	arg1->open();
}

void op_numeric_binary_iterator::_close()
{
	arg0->close();
	arg1->close();
}

bool op_numeric_binary_iterator::done() const
{
	return (arg0->done() || arg1->done());
}



/*______________________________________________________________________
|  
|	6.2.1 op:numeric-add
|	op:numeric-add($arg1 as numeric, $arg2 as numeric) as numeric
|	
|	Summary: Backs up the "+" operator and returns the arithmetic sum of 
|	its operands: ($arg1 + $arg2).
|	
|	Note:
|	For xs:float or xs:double values, if one of the operands is a zero or 
|	a finite number and the other is INF or -INF, INF or -INF is returned. 
|	If both operands are INF, INF is returned. If both operands are -INF, 
|	-INF is returned. If one of the operands is INF and the other is -INF, 
|	NaN is returned.
|_______________________________________________________________________*/

// op_numeric_add_iterator::op_numeric_add_iterator(
// 	yy::location loc, 
// 	iterator_t arg0,
// 	iterator_t arg1)
// :
// 	op_numeric_binary_iterator(loc,arg0,arg1)
// {
// }


/**
 * TODO FIXME This is not the GENERIC_ADD_ITERATOR!!!! No type checking is performend! 
 */
item_t op_numeric_add_iterator::nextImpl(){
	item_t n0_h;
	item_t n1_h;
	const numericValue* n0;
	const numericValue* n1;
	
	STACK_INIT();
	n0_h = this->consumeNext(arg0);
	if(&*n0_h == NULL)
		STACK_PUSH(NULL);
	n1_h = this->consumeNext(arg1);
	if(&*n1_h == NULL)
		STACK_PUSH(NULL);
	if (n0_h == NULL || n1_h == NULL) {
		STACK_PUSH(NULL);
	} else {
		n0 = dynamic_cast<const numericValue*>(&*n0_h);
		n1 = dynamic_cast<const numericValue*>(&*n1_h);
		STACK_PUSH(new numericValue(xs_decimal, n1->val() + n0->val()));
	}
	STACK_END();
}
// void op_numeric_add_iterator::resetImpl(){
// 	this->resetChild(this->arg0);
// 	this->resetChild(this->arg1);
// }

// item_t op_numeric_add_iterator::_next()
// {
// 	item_t n0_h = arg0->next();
// 
// 	if(&*n0_h == NULL)
// 		return NULL;
// 
// 	item_t n1_h = arg1->next();
// 
// 	if(&*n1_h == NULL)
{'fraction_non_alphanumeric': 0.1356382978723404, 'fraction_numerical': 0.01961436170212766, 'mean_word_length': 4.169243986254296, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6688005', 'n_tokens_mistral': 2213, 'n_tokens_neox': 2123, 'n_words': 582}