Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.14)
project(rational_sulyma_horbunov C)

set(CMAKE_C_STANDARD 99)

add_executable(rational_sulyma_horbunov src/rational_sulyma_horbunov.c headers/rational_sulyma_horbunov.h headers/common.h tests/rational_tests_sulyma_horbunov.c)
1 change: 1 addition & 0 deletions file_input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
+(2/3)
3 changes: 3 additions & 0 deletions file_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
+(1/2)
+(1/4)
+(1/8)
3 changes: 3 additions & 0 deletions file_output_chain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
3.14159265358979311599796346854419 0.00000008491367876740610475614620
4
3 7 15 1
64 changes: 6 additions & 58 deletions headers/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@
The MIT License (MIT)
Copyright (c) 2014 Viktor Borodin (borodin@mail.univ.kiev.ua)
21.06.2014

* Basic types definitions and functions

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -23,64 +19,16 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
***/

#ifndef __COMMON__
#define __COMMON__

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <float.h>

#include <string.h>

typedef DType double; /* Double real type for application */

typedef IType int; /* Integer type for application */

typedef NType unsigned; /* Unsigned type for application */

//TODO: v.b.: correct it with limits and float
#define EQ_EPS 0.000001 // epsilon : presision of arithmetics

#define MAX((a),(b)) (a)<(b)?(a):(b)
#define MIN((a),(b)) (a)>(b)?(a):(b)

#define PD_EQL((a),(b)) fabs((a)-(b)) < EQ_EPS


/* Basic types definitions */

/* Point type as vector of two reals */
typedef struct DPoint_
{
union //classical and vector representation
{
struct
{
DType x;
DType y;
};
DType ptr[2];
};
} DPoint;


typedef struct DLine_
{
DType a;
DType b;
DType c;
} DLine;

typedef double DType; /* Double real type for application */

// real function R^1 -> R^1
typedef R1R_Finc (*DType)(Dtype);
typedef short HType; /* Short integer type for application */

typedef long long IType; /* Integer type for application */

void* memzero(void* ptr, size_t n)
{
memset(ptr, 0, n);
}
typedef unsigned long NType; /* Unsigned type for application */

#endif /* __COMMON__ end */
#endif
188 changes: 188 additions & 0 deletions headers/rational_sulyma_horbunov.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/*
The MIT License (MIT)
Copyright (c) 2019 Sulyma Mariia (marysulyma@gmail.com)
01.06.2019
This module is designed for equation solving to support basic math into the project.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

/*
* rational_sulyma_horbunov.h
* by Sulyma Mariia
* project: Rational #4
* email: marysulyma@gmail.com
*/

#ifndef RATIONAL_SULYMA_HORBUNOV_RATIONAL_SULYMA_HORBUNOV_H
#define RATIONAL_SULYMA_HORBUNOV_RATIONAL_SULYMA_HORBUNOV_H

#include <stdbool.h>
#include <stdio.h>
#include "common.h"

/*
* Defining Fraction structure
* type whether a normal fraction or represents infinity
* sign value defines if fraction value is positive or negative
* nominator and denominator declaration here is trivial
*/
typedef struct
{
bool type;
bool sign;
IType nominator;
IType denominator;
}
Fraction;

/*
* Defining FractionArray structure
* for easier use
* contains pointer and length of given array
*/
typedef struct
{
NType len;
Fraction *array;
}
FractionArray;

/*
* Defining ChainFraction structure
* x - given value for approximation using chain fraction
* eps - accuracy
* components - pointer to array of coefficients of chain fraction
* len - length of components array
*/
typedef struct
{
DType x;
DType eps;
NType *components;
NType len;
}
ChainFraction;

/*
* Defining ChainFractionArray structure
* for easier use
* contains pointer and length of given array
*/
typedef struct
{
NType len;
ChainFraction *array;
}
ChainFractionArray;

extern void free_FractionArray(FractionArray f);

extern void free_ChainFraction(ChainFraction f);

extern DType to_float(Fraction r);

extern Fraction fraction(IType a, IType b);

extern Fraction generate_random_fraction();

extern Fraction int_to_fraction(IType x);

extern Fraction binary_add(Fraction a, Fraction b);

extern Fraction binary_sub(Fraction a, Fraction b);

extern Fraction binary_mul(Fraction a, Fraction b);

extern Fraction binary_div(Fraction a, Fraction b);

extern void unary_add(Fraction *a, Fraction b);

extern void unary_sub(Fraction *a, Fraction b);

extern void unary_mul(Fraction *a, Fraction b);

extern void unary_div(Fraction *a, Fraction b);

extern Fraction scalar_binary_add(Fraction a, IType c);

extern Fraction scalar_binary_sub(Fraction a, IType c);

extern Fraction scalar_binary_mul(Fraction a, IType c);

extern Fraction scalar_binary_div(Fraction a, IType c);

extern void scalar_unary_add(Fraction *a, IType c);

extern void scalar_unary_sub(Fraction *a, IType c);

extern void scalar_unary_mul(Fraction *a, IType c);

extern void scalar_unary_div(Fraction *a, IType c);

extern IType binary_div_mod(Fraction r);

extern bool eq_fractions(Fraction a, Fraction b);

extern bool neq_fractions(Fraction a, Fraction b);

extern bool g_fractions(Fraction a, Fraction b);

extern bool ge_fractions(Fraction a, Fraction b);

extern bool l_fractions(Fraction a, Fraction b);

extern bool le_fractions(Fraction a, Fraction b);

extern Fraction fr_max(Fraction a, Fraction b);

extern Fraction fr_min(Fraction a, Fraction b);

extern void stream_print_fraction(FILE *stream, Fraction f);

extern void stream_print_fractions(FILE *stream, FractionArray f);

extern Fraction console_read_fraction();

extern FractionArray console_read_fractions();

extern Fraction stream_read_fraction(FILE *stream);

extern void create(FractionArray *array, NType len, ...);

extern void insert(FractionArray *array, NType len, ...);

extern DType calculate_chain_fraction(ChainFraction r);

extern ChainFraction create_N(DType x, NType n);

extern ChainFraction create_E(DType x, DType eps);

extern void stream_output_chain_fraction(FILE *stream, ChainFraction r);

extern void stream_input_chain_fraction(FILE *stream, ChainFraction *r);

extern void console_output_as_fraction(ChainFraction r);

extern DType get_value(ChainFraction r);

extern DType get_epsilon(ChainFraction r);

extern Fraction get_fraction(ChainFraction r);

extern DType gregory_formula(NType N);

#endif
Loading