/* Copyright 2016 Samsung Electronics Co., Ltd.
 *
 * 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.
 */
#if !defined(SUPERLONG_H)
#define SUPERLONG_H

#include "scl/arithmetic.h"

typedef struct {
	scl_umax_t low, high;
	int sign, overflow;
} superlong_t;

typedef struct {
	superlong_t min, max;
} sl_range_t;


extern superlong_t const sl_zero;

extern void sl_init(int verbose);

extern sl_range_t sl_limits[SCL_ITID_COUNT];

extern int sl_print(superlong_t s);

extern superlong_t sl_i(scl_imax_t i);
extern superlong_t sl_u(scl_umax_t i);

#define SL(i) ( \
	((SCL_GET_ITID_LEAST_INT(i) % 2) == 1) \
		? sl_u((scl_umax_t)(i)) \
		: sl_i((scl_imax_t)(i)) \
)


extern int sl_cmp(superlong_t a1, superlong_t a2);

extern int sl_in_range(superlong_t a, sl_range_t r);

extern superlong_t sl_add(superlong_t a1, superlong_t a2);
extern superlong_t sl_sub(superlong_t a1, superlong_t a2);
extern superlong_t sl_mult(superlong_t m1, superlong_t m2);
extern superlong_t sl_div(superlong_t a, superlong_t d);
extern superlong_t sl_mod(superlong_t a, superlong_t d);
extern superlong_t sl_neg(superlong_t a);
extern superlong_t sl_abs(superlong_t a);
extern sl_range_t sl_range(superlong_t min, superlong_t max);

#endif
