Professional Documents
Culture Documents
Submitted by-
Aakash Guwalani – 2021H1230235H
Arpit Goel– 2021H1230219H
Kalicheti Vishnuvardhan Reddy – 2021H1230221H
Mimanshu Singh – 2021H1230207H
Submitted to-
Mr. Karri Babu Ravi Teja (Assistant Prof. BITS Pilani)
ABSTRACT
In coordinate geometry, Euclidean distance is the distance between two points. To find the two points on a
plane, the length of a segment connecting the two points is measured. We derive the Euclidean distance
formula using the Pythagoras theorem.
The Euclidean distance formula, as its name suggests, gives the distance between two points (or) the straight
line distance. Let us assume that (x1,y1)(x1,y1) and (x2,y2)(x2,y2) are two points in a two-dimensional plane.
Here is the Euclidean distance formula.
where,
Here we are using half precision floating point notation for data point representation.
Applications:
o Determines the best value for K center points or centroids by an iterative process.
o Assigns each data point to its closest k-center. Those data points which are near to the particular k-
center, create a cluster.
(C LANGUAGE)
1. Algorithm-
Convert decimal number to binary representation.
Shifting binary number for mantissa calculation.
Exponent calculation by modulus division.
Inserting zero at remaining bits.
2. Code-
#include <stdio.h>
int
main (void)
{
float num,n1;
printf ("enter number=");
scanf ("%f", &n1);
if(n1<0)
num = -n1;
int i, j, bin, z, b[100], a[100];
j = 0;
bin = 0; //initial binary number =0
// binary calculation
for (i = 0; i < 4; i++)
{
num = num * 2;
j = num;
bin = bin * 10 + j;
if (bin == 0)
z = z + 1; //for shifting of bits.
if (j == 1)
num = num - 1;
}
// exponent part calculation.
z = 63 + z;
for (i = 0; i <= 5; i++)
{
a[i] = z % 2;
z = z / 2;
}
if (n1 >= 0) // for positive number represntation
{
printf ("0");
for (i = 0; i <= 5; i++)
{
printf ("%d", a[i]);
}
printf ("%d", bin);
for (int i = 0; i < 6 - j; i++)
printf ("%d", 0);
}
else //negative number
{
printf ("1");
for (i = 0; i <= 5; i++)
{
printf ("%d", a[i]);
}
printf ("%d", bin);
for (int i = 0; i < 6 - j; i++)
printf ("%d", 0);
}
3. Output: -
EUCLIDEAN DISTANCE CALCULATION
2. Code-
#include <stdio.h
#include <math.h>
int
main ()
{
int n;
printf ("Enter total number of input:");
scanf ("%d", &n); //user defined n inputs
float x[n], y[n], ed[n], sumx, sumy, t; //variable for point x,y ,euclidean distance, sum of all x,sum of all point
sumx = 0;
sumy = 0;
for (int i = 0; i < n; i++)
{
printf ("enter point x%d y%d \n", i, i);
scanf ("%f %f", &x[i], &y[i]);
}
for (int i = 0; i < n; i++)
{
sumx = sumx + x[i];
sumy = sumy + y[i];
}
sumx = sumx / n; // centroid calculation of all
sumy = sumy / n; // centroid calculation of all y
for (int i = 0; i < n; i++)
{
x[i] = x[i] - sumx;
y[i] = y[i] – sumy
ed[i] = sqrt (x[i] * x[i] + y[i] * y[i]); //Euclidean distance
}
// Sorting
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (ed[i] > ed[j])
{
t = ed[i];
ed[i] = ed[j];
ed[j] = t;
}
}
}
printf ("Sorted Euclidean Distance");
for (int i = 0; i < n; i++)
printf ("%f\t", ed[i]);
}
3. Output:
MODULE 1- FLOATING POINT ADDER
Architecture-
Note- This architecture is illustrated for 24 bits. We have implemented this for half precision floating point
numbers i.e., 16 bits.
Algorithm used-
RTL Synthesis-
MODULE 2- 16 BIT HALF PRECISION SQUARE ROOT
An easy-to-implement square root algorithm for an 16 bit positive integer. Before understanding the algorithm
please reassure yourself that the square root of an 8 bit integer can have at most 8 bits in its whole part (√255
= 15.9687). Thus the square root calculated by this algorithm has a fixed 8.8 format i.e. 8 bits are reserved for
whole part and 8 for decimal. In this algorithm, we guess a trial square root and check whether its square is
greater than the input, x. If it is, we decrease the trial square root and try again. The process takes as many
clock cycles as the number of bits in the input, hence 16 in this case.
Schematic
Simulation Output
MODULE 3- 16 BIT HALF PRECISION COMPARATOR
The architecture of this module is designed in such a manner that only the mantissa bits (bit 0 to bit 9) is
compared for the two inputs, while making the exponent bits (bit 10 to bit 14) same. The initial step is to
compare the exponents of A and B. This is achieved by subtracting the exponents of B from A. If the borrow
is generated it indicates that exponent of B is greater than exponent of A, otherwise exponent of A is greater
than exponent of B. In either case the exponent with greater value is assigned to both the exponents of A and
B. After the exponents of both inputs are same, we right shift the smaller number. The right shifting operation
is done as many times equal to the difference generated from the subtraction of exponents of A and B. Then
we compare the mantissa bits of A and B to generate the output.
Test Bench
Case 1:
A = 1.414 0 01111 0110101000 exp_A=15-15=0 man_A= 0.414
B = 0.8 0 01110 1001100110 exp_B=14-15= -1 man_B= 0.6
Case 2:
A = 1.8 0 01111 1100110011 exp_A=15-15=0 man_A= 0.8
B = 0.3 0 01101 0011001101 exp_B=13-15= -2 man_B= 0.2
Case 3:
A = 1.4 0 01111 0110011010 exp_A=15-15=0 man_A= 0.4
B = 1.3 0 01111 0100110011 exp_B=15-15=0 man_B= 0.3
Case 4:
A = 1.4 0 01111 0110011010 exp_A=15-15=0 man_A= 0.4
B = 1.4 0 01111 0110011010 exp_B=15-15= 0 man_B= 0.4
Case 5:
Case 6:
Schematic-
Module 4- SORTING 16BIT
Algorithm-
We are considering 5 values for sorting each of size 16 bits.
In the module we are giving inputs as clock, unsorted values and getting output as sorted output.
We have also declared a sorted_bus register from which we are taking our outputs.
Then we are implementing bubble sort algorithm on data to achieve sorted output.
SIMULATED OUTPUT-
Here we are giving random inputs- 3524, 5e01, d609, 5663, 7b0d
Getting sorted outputs after 10nsec as – 3524, 5663, 5e01, 7b0d, d609
RTL-Schematic-