the process used to attack networks and the devices on networks. APA FORMAT
In: Computer Science
Implement synchronous send and receive of one word messages (also known as Ada-style rendezvous), using condition variables (don't use semaphores!). Implement the Communicator class with operations, void speak(int word) and int listen().
speak() atomically waits until listen() is called on the same Communicator object, and then transfers the word over to listen(). Once the transfer is made, both can return. Similarly, listen() waits until speak() is called, at which point the transfer is made, and both can return (listen() returns the word). Your solution should work even if there are multiple speakers and listeners for the same Communicator (note: this is equivalent to a zero-length bounded buffer; since the buffer has no room, the producer and consumer must interact directly, requiring that they wait for one another). Each communicator should only use exactly one lock. If you're using more than one lock, you're making things too complicated.
In: Computer Science
What are some of the common types of attacks against networks and devices on networks? apa format
In: Computer Science
In C++, I have 3 files (Main.cpp, Point.cpp, Point.h). When Compiled and run, it produces 2 errors, in Main.cpp "cannot convert from double to point" and in Point.cpp "name followed by :: must be a class or namespace name". How do you go about fixing these errors without editing Main.cpp? Thanks in advance.
//main.cpp
#include <iostream>
#include <cmath>
#include "Point.h"
using namespace std;
const double PI = 3.14159265359;
const double TOL = .0000001; //allows us to do a comparison for
double value equality
int main()
{
int toTest = 0;
//TEST AS YOU DEVELOP COMMENT OUT EVERYTHING BUT WHAT
YOU HAVE IMPLEMENTED
//AND UNCOMMENT AS YOU CREATE.
//(you can look below to see what I make this variable
to test given things)
cout << "MUST IMPLEMENT GETTERS BEFORE TESTING
\n";
cout << "What would you like to test? \n";
cout << "1-value constructor \n";
cout << "2-copy constructor \n";
cout << "3-setters test \n";
cout << "4-translation test \n";
cout << "5-scaling test \n";
cout << "6-reflect over x-axis test \n";
cout << "7-reflect over y-axis test \n";
cout << "8-rotation \n";
cout << "9-assignment operator \n";
cout << "10-operator equals equals \n";
cout << "11-cin overload \n";
cout << "12-cout overload \n";
cin >> toTest;
Point a; // a should be at (0,0)
Point b(5.0); //b should be at (5.0,0)
/* incremental test line
Point c(-15.3, -32.22); //c should be at (-15.3,
-32.33)
if(toTest==1)
{
cout<<"**Value Constructor
Test: \n";
if(abs(a.get_x())<TOL &&
abs(a.get_y())<TOL &&
abs(b.get_x()-5)<TOL && abs(b.get_y())<TOL
&&
abs(-15.3-c.get_x())<TOL &&
abs(-32.22-c.get_y())<TOL)
{
cout<<"
Value Constructor Works\n" <<endl;
}
else
{
cout<<"
Value Constructor Failed\n"<<endl;
}
}
/* Point d(c);
if(toTest==2)
{
cout<<"\n**Copy Constructor
Test: \n";
if(abs(d.get_x()-c.get_x())<TOL
&& abs(d.get_y()-c.get_y())<TOL)
{
cout<<"
Copy Constructor Works\n"<<endl;
}
else
{
cout<<"
Copy Constructor Failed\n"<<endl;
}
}
if(toTest==3)
{
cout<<"\n**Setters Test:
\n";
a.set_x(5.3); a.set_y(-3.2);
if(abs(a.get_x()-5.3)<TOL
&& abs(a.get_y()+3.2)<TOL)
{
cout<<"
Setters Work\n"<<endl;
}
else
{
cout<<"
Setters Failed\n"<<endl;
}
}
if(toTest==4)
{
cout<<"\n**Translation Test:
\n";
a.translate(5.3,-3.2);
if(abs(a.get_x()-5.3)<TOL
&& abs(a.get_y()+3.2)<TOL)
{
cout<<"
Translate Works\n"<<endl;
}
else
{
cout<<"
Translate Failed\n"<<endl;
}
}
if(toTest==5)
{
cout<<"\n**Scale Test:
\n";
c.scale(-3);
if(abs(c.get_x()-45.9)<TOL
&& (abs(c.get_y()-96.66)<TOL))
{
cout<<"
Scale Works\n"<<endl;
}
else
{
cout<<"
Scale Failed\n"<<endl;
}
}
if(toTest==6)
{
cout<<"\n**Reflect Over
X-Axis Test: ";
c.reflect_x();
if(abs(c.get_y()-32.22)<TOL)
{
cout<<"
Reflect Over X-axis Works\n"<<endl;
}
else
{
cout<<"
Reflect Over X-Axis Failed\n"<<endl;
}
}
if(toTest==7)
{
cout<<"\n**Reflect Over
Y-Axis Test: ";
c.reflect_y();
if(abs(c.get_x()-15.3)<TOL)
{
cout<<"
Reflect Over Y-Axis Works\n"<<endl;
}
else
{
cout<<"
Reflect Over Y-Axis Failed\n"<<endl;
}
}
if(toTest==8)
{
Point e(-1,0); //e shoule be at
(-1, 0)
cout<<"\n**Rotation of Point
Test: ";
e.rotate(PI/2);
if(abs(e.get_x())<TOL &&
abs(e.get_y()+1)<TOL)
{
cout<<"
Rotation Of PI/2 (90 deg CCW) Worked\n"<<endl;
}
else
{
cout<<"
Rotation Of PI/2 (90 deg CCW) Failed\n"<<endl;
}
}
if(toTest==9)
{
cout<<"\n**Operator equals
Test: ";
d=b;
if((abs(d.get_x()-b.get_x())<TOL) &&
(abs(d.get_y()-b.get_y())<TOL))
{
cout<<"
Operator Equals Test Passed\n"<<endl;
}
else
{
cout<<"
Operator Equals Test Failed\n"<<endl;
}
}
if(toTest==10)
{
cout<<"\n**Operator equals
equals Test: ";
Point e(-15.3, -32.22);
if(e==c)
{
cout<<"
Operator equals equals Test Passed \n"<<endl;
}
else
{
cout<<"
Operator equals equals Test Failed \n"<<endl;
}
}
if(toTest==11)
{
cout<<"\n**CIN Test: \ncin
the values 10 and 20 to test this with (10,20): ";
cin>>d;
if(abs(d.get_x()-10)<TOL
&& abs(d.get_y()-20)<TOL)
{
cout<<"CIN
Test Passed\n"<<endl;
}
else
{
cout<<"CIN
Test Failed\n"<<endl;
}
}
if(toTest==12)
{
cout<<"**COUT Test: coutting
Points a,b,c: \n";
cout<<a;
cout<<b;
cout<<c;
}*/
}
//Point.cpp
#include "Point.h"
#include <iostream>
#include <cstdlib>
using namespace std;
double x = 0;
double y = 0;
void Point::point()
{
x = 0;
y = 0;
}
void Point::point(double inX)
{
x = inX;
y = 0;
}
void Point::point(double inX, double inY)
{
x = inX;
y = inY;
}
double getX()
{
return x;
}
double getY()
{
return y;
}
void setPoint(double a, double b)
{
}
//Point.h
#include <iostream>
#ifndef Point_H;
using namespace std;
class Point
{
public:
static double x;
static double y;
void point();
void point(double x);
void point(double x, double y);
double getX();
double getY();
void setPoint(double a, double b);
};
#endif
In: Computer Science
l = [0 1 -2 1 1];
d = [2 -2 4 2 2];
r = [-1 1 -1 -2 0];
b = [2 0 -6 1 4];
n = length(d);
x= zeros(n,1);
for i = 2:n
factor = l(i)/d(i-1);
d(i) = d(i) - factor*r(i-1);
b(i) = b(i) - factor*b(i-1);
end
x(n) = b(n)/d(n);
for i = n-1:-1:1
x(i) = b(i)-r(i)*x(i+1) / d(i);
end
x1 = x(1);
x2 = x(2);
x3 = x(3);
x4 = x(4);
fprintf('\nx1 = %f\nx2 = %f\nx3 = %f\nx4 = %f\n',x1,x2,x3,x4);
this is matlab code!
It's a question of getting answers using the Thomas method.
The answer should be x1=1, x2=0, x3=-1, x4=2, x5=1.
Please fix what's wrong.
In: Computer Science
Using jGRASP, write a Java program named LastnameFirstname11.java, using your last name and your first name, that does the following:
In: Computer Science
Please fllll this out thank you
/**
*
* Creates a six-sided die and rolls it 20 times. It outputs the
face values and also
* the number of times the die lands on 6.
*
* Creates 2 eight-sided dice and rolls the pair 10 times. It prints
out a sequence
* of pairs representing the face values as well as the number of
doubles.
*
* Allows the user to repeat the above steps as often as (s)he
wishes.
*
* @author (put your name here!!!)
* @version (3-20-19)
*/
import java.util.*;
public class TestDie
{
public static void main (String [] args)
{
Scanner keyIn = new Scanner(System.in);
// display output heading
System.out.println ("Programmer: put your name here!!");
System.out.println ("Course: COSC 111, Winter '19");
System.out.println ("Lab: Exam 2, part 2");
System.out.println ("Due date: 3-20-19\n");
// create a six-sided die
// create a Die object and then call the method setSides to set the
number of sides to 6
// roll the die 20 times, output the face value of each roll (4 per
line), and the
// number of times the die lands on 6.
// set up a loop that iterates exactly 20 times, and each time
through the loop do the following:
// roll the die by calling the method 'roll'; output the face value
of the die; check the face
// value to keep track of 6s, and check to see if you have printed
4 numbers already, if yes,
// then advance to the next line.
System.out.println("Rolling a 6-sided die 20 times:" );
// create two eight-sided dice
// create two 'Die' objects and then use the method 'setSides' with
each object to set its number of sides to 8
System.out.println("\nRolling a pair of 8-sided dice 10 times:");
// throw a pair of eight-sided dice 10 times, output the face
values of each throw as a pair
// and also the number of doubles (both dice land on the same face
value)
// set up a loop that iterates exactly 10 times, and each time
through the loop do the following:
// roll both die by calling the method 'roll' twice; print out
their face values as a pair;
// and check to see if both face values are the same, if yes, keep
track of it.
// add a do-while loop to repeat the above code as often as the user wishes
}
}
In: Computer Science
CPU Company, AMD vs Intel vs ARM
which CPU model that compete between these 3 companies? What's their specification?
In: Computer Science
CPU Company, AMD vs Intel vs ARM
For tablet or Laptop. or any devices that this CPU is equipped
with,
Which one is the BEST, BALANCE, & the WORST? Need Reasons
why
In: Computer Science
In: Computer Science
CPU Company, AMD vs Intel vs ARM
Choose product from each company and give recommendations what the companies should do to make them better in future upgrades.
In: Computer Science
Please do this in visual studio C++. Overview In this programming challenge, you will create an Employee Tree application. Instructions Begin this assignment by writing your own version of a class template that will create a binary tree that can hold values of any data type. Design an EmployeeInfo class that holds the following employee information: Employee ID Number (int) Employee Name (string) Next, use the template you designed to implement a binary tree whose nodes hold an instance of the EmployeeInfo class. The nodes should be sorted on the Employee ID number. Test the binary tree by inserting nodes with the following information: Employee ID Number Name 1021 John Williams 1057 Bill Witherspoon 2487 Jennifer Twain 3769 Sophia Lancaster 1017 Debbie Reece 1275 George McMullen 1899 Ashley Smith 4218 Josh Plemmons Your program should allow the user to enter an ID number, then search the tree for the number. If the number is found, it should display the employee’s name. If the node is not found, it should display a message indicating so.
In: Computer Science
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file.
Name your output file “output.txt”.
Build your program using a main function and at least one other function.
Give your input and output file names as command line arguments.
Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:
This is mod7.txt
I do not come here as an advocate, because whatever position the suffrage movement may occupy in the United States of America, in England it has passed beyond the realm of advocacy and it has entered into the sphere of practical politics. It has become the subject of revolution and civil war, and so tonight I am not here to advocate woman suffrage. American suffragists can do that very well for themselves. I am here as a soldier who has temporarily left the field of battle in order to explain - it seems strange it should have to be explained, what civil war is like when civil war is waged by women. I am not only here as a soldier temporarily absent from the field at battle; I am here, and that, I think, is the strangest part of my coming, I am here as a person who, according to the law courts of my country, it has been decided, is of no value to the community at all; and I am adjudged because of my life to be a dangerous person, under sentence of penal servitude in a convict prison. It is not at all difficult if revolutionaries come to you from Russia, if they come to you from China, or from any other part of the world, if they are men. But since I am a woman it is necessary to explain why women have adopted revolutionary methods in order to win the rights of citizenship. We women, in trying to make our case clear, always have to make as part of our argument, and urge upon men in our audience the fact, a very simple fact, that women are human beings. Suppose the men of Hartford had a grievance, and they laid that grievance before their legislature, and the legislature obstinately refused to listen to them, or to remove their grievance, what would be the proper and the constitutional and the practical way of getting their grievance removed? Well, it is perfectly obvious at the next general election the men of Hartford would turn out that legislature and elect a new one. But let the men of Hartford imagine that they were not in the position of being voters at all, that they were governed without their consent being obtained, that the legislature turned an absolutely deaf ear to their demands, what would the men of Hartford do then? They couldn't vote the legislature out. They would have to choose; they would have to make a choice of two evils: they would either have to submit indefinitely to an unjust state of affairs, or they would have to rise up and adopt some of the antiquated means by which men in the past got their grievances remedied. Your forefathers decided that they must have representation for taxation, many, many years ago. When they felt they couldn't wait any longer, when they laid all the arguments before an obstinate British government that they could think of, and when their arguments were absolutely disregarded, when every other means had failed, they began by the tea party at Boston, and they went on until they had won the independence of the United States of America. It is about eight years since the word militant was first used to describe what we were doing. It was not militant at all, except that it provoked militancy on the part of those who were opposed to it. When women asked questions in political meetings and failed to get answers, they were not doing anything militant. In Great Britain it is a custom, a time-honoured one, to ask questions of candidates for parliament and ask questions of members of the government. No man was ever put out of a public meeting for asking a question. The first people who were put out of a political meeting for asking questions, were women; they were brutally ill-used; they found themselves in jail before 24 hours had expired. We were called militant, and we were quite willing to accept the name. We were determined to press this question of the enfranchisement of women to the point where we were no longer to be ignored by the politicians. You have two babies very hungry and wanting to be fed. One baby is a patient baby, and waits indefinitely until its mother is ready to feed it. The other baby is an impatient baby and cries lustily, screams and kicks and makes everybody unpleasant until it is fed. Well, we know perfectly well which baby is attended to first. That is the whole history of politics. You have to make more noise than anybody else, you have to make yourself more obtrusive than anybody else, you have to fill all the papers more than anybody else, in fact you have to be there all the time and see that they do not snow you under. When you have warfare things happen; people suffer; the noncombatants suffer as well as the combatants. And so it happens in civil war. When your forefathers threw the tea into Boston Harbour, a good many women had to go without their tea. It has always seemed to me an extraordinary thing that you did not follow it up by throwing the whiskey overboard; you sacrificed the women; and there is a good deal of warfare for which men take a great deal of glorification which has involved more practical sacrifice on women than it has on any man. It always has been so. The grievances of those who have got power, the influence of those who have got power commands a great deal of attention; but the wrongs and the grievances of those people who have no power at all are apt to be absolutely ignored. That is the history of humanity right from the beginning. Well, in our civil war people have suffered, but you cannot make omelettes without breaking eggs; you cannot have civil war without damage to something. The great thing is to see that no more damage is done than is absolutely necessary, that you do just as much as will arouse enough feeling to bring about peace, to bring about an honourable peace for the combatants; and that is what we have been doing. We entirely prevented stockbrokers in London from telegraphing to stockbrokers in Glasgow and vice versa: for one whole day telegraphic communication was entirely stopped. I am not going to tell you how it was done. I am not going to tell you how the women got to the mains and cut the wires; but it was done. It was done, and it was proved to the authorities that weak women, suffrage women, as we are supposed to be, had enough ingenuity to create a situation of that kind. Now, I ask you, if women can do that, is there any limit to what we can do except the limit we put upon ourselves? If you are dealing with an industrial revolution, if you get the men and women of one class rising up against the men and women of another class, you can locate the difficulty; if there is a great industrial strike, you know exactly where the violence is and how the warfare is going to be waged; but in our war against the government you can't locate it. We wear no mark; we belong to every class; we permeate every class of the community from the highest to the lowest; and so you see in the woman's civil war the dear men of my country are discovering it is absolutely impossible to deal with it: you cannot locate it, and you cannot stop it. "Put them in prison," they said, "that will stop it." But it didn't stop it at all: instead of the women giving it up, more women did it, and more and more and more women did it until there were 300 women at a time, who had not broken a single law, only "made a nuisance of themselves" as the politicians say. Then they began to legislate. The British government has passed more stringent laws to deal with this agitation than it ever found necessary during all the history of political agitation in my country. They were able to deal with the revolutionaries of the Chartists' time; they were able to deal with the trades union agitation; they were able to deal with the revolutionaries later on when the Reform Acts were passed: but the ordinary law has not sufficed to curb insurgent women. They had to dip back into the middle ages to find a means of repressing the women in revolt. They have said to us, government rests upon force, the women haven't force, so they must submit. Well, we are showing them that government does not rest upon force at all: it rests upon consent. As long as women consent to be unjustly governed, they can be, but directly women say: "We withhold our consent, we will not be governed any longer so long as that government is unjust." Not by the forces of civil war can you govern the very weakest woman. You can kill that woman, but she escapes you then; you cannot govern her. No power on earth can govern a human being, however feeble, who withholds his or her consent. When they put us in prison at first, simply for taking petitions, we submitted; we allowed them to dress us in prison clothes; we allowed them to put us in solitary confinement; we allowed them to put us amongst the most degraded of criminals; we learned of some of the appalling evils of our so-called civilisation that we could not have learned in any other way. It was valuable experience, and we were glad to get it. I have seen men smile when they heard the words "hunger strike", and yet I think there are very few men today who would be prepared to adopt a "hunger strike" for any cause. It is only people who feel an intolerable sense of oppression who would adopt a means of that kind. It means you refuse food until you are at death's door, and then the authorities have to choose between letting you die, and letting you go; and then they let the women go. Now, that went on so long that the government felt that they were unable to cope. It was [then] that, to the shame of the British government, they set the example to authorities all over the world of feeding sane, resisting human beings by force. There may be doctors in this meeting: if so, they know it is one thing to feed by force an insane person; but it is quite another thing to feed a sane, resisting human being who resists with every nerve and with every fibre of her body the indignity and the outrage of forcible feeding. Now, that was done in England, and the government thought they had crushed us. But they found that it did not quell the agitation, that more and more women came in and even passed that terrible ordeal, and they were obliged to let them go. Then came the legislation - the "Cat and Mouse Act". The home secretary said: "Give me the power to let these women go when they are at death's door, and leave them at liberty under license until they have recovered their health again and then bring them back." It was passed to repress the agitation, to make the women yield - because that is what it has really come to, ladies and gentlemen. It has come to a battle between the women and the government as to who shall yield first, whether they will yield and give us the vote, or whether we will give up our agitation. Well, they little know what women are. Women are very slow to rouse, but once they are aroused, once they are determined, nothing on earth and nothing in heaven will make women give way; it is impossible. And so this "Cat and Mouse Act" which is being used against women today has failed. There are women lying at death's door, recovering enough strength to undergo operations who have not given in and won't give in, and who will be prepared, as soon as they get up from their sick beds, to go on as before. There are women who are being carried from their sick beds on stretchers into meetings. They are too weak to speak, but they go amongst their fellow workers just to show that their spirits are unquenched, and that their spirit is alive, and they mean to go on as long as life lasts. Now, I want to say to you who think women cannot succeed, we have brought the government of England to this position, that it has to face this alternative: either women are to be killed or women are to have the vote. I ask American men in this meeting, what would you say if in your state you were faced with that alternative, that you must either kill them or give them their citizenship? Well, there is only one answer to that alternative, there is only one way out - you must give those women the vote. You won your freedom in America when you had the revolution, by bloodshed, by sacrificing human life. You won the civil war by the sacrifice of human life when you decided to emancipate the negro. You have left it to women in your land, the men of all civilised countries have left it to women, to work out their own salvation. That is the way in which we women of England are doing. Human life for us is sacred, but we say if any life is to be sacrificed it shall be ours; we won't do it ourselves, but we will put the enemy in the position where they will have to choose between giving us freedom or giving us death. So here am I. I come in the intervals of prison appearance. I come after having been four times imprisoned under the "Cat and Mouse Act", probably going back to be rearrested as soon as I set my foot on British soil. I come to ask you to help to win this fight. If we win it, this hardest of all fights, then, to be sure, in the future it is going to be made easier for women all over the world to win their fight when their time comes.
In: Computer Science
20. Assume you have a Java Interface with a method has this signature:
public double min(double... grades);
Write the implementation of this method so that it returns the smallest of the grades. Show example on calling the method when you are done with the implementation.
In: Computer Science
COMPUTER SCIENCE- FLOATING POINT REPRESENTATION:
Hello, I completed a program for floating point representation (it can add and multiply floating point values in IEEE format). I already completed it, but I came back with 3 small errors. Can someone please fix them? I posted them at the bottom, here is the code:
__________________________________________________________________________________________________________________________________
fp.java:
// fp class
public class fp {
// add function
public int add(int a, int b) {
FPNumber fa = new FPNumber(a);
FPNumber fb = new FPNumber(b);
FPNumber result = new FPNumber(0);
//***************************************************************************************************
// addition- handle exceptions
if (fa.isNaN() || fb.isNaN()) {
return (fa.isNaN() ? fa : fb).asInt();
}
if (fa.isZero()) {
return fb.asInt();
} else if (fb.isZero()) {
return fa.asInt();
}
if (fa.isInfinity() && fb.isInfinity()) {
if (fa.s() == fb.s()) {
return fa.asInt();
} else {
result.setE(255);
result.setF(1);
return fa.asInt();
}
}
if (fa.isInfinity()) {
return fa.asInt();
} else if (fb.isInfinity()) {
return fb.asInt();
}
//***************************************************************************************************
// addition- sort numbers
FPNumber fa2 = new FPNumber(a);
FPNumber fb2 = new FPNumber(b);
if (fa._e != fb._e) {
fa2 = (fa.e() > fb.e()) ? fa : fb;
fb2 = (fa.e() < fb.e()) ? fa : fb;
} else {
fa2 = (fa.f() > fb.f()) ? fa : fb;
fb2 = (fa.f() < fb.f()) ? fa : fb;
}
//***************************************************************************************************
// addition- align exponents
if (fa2.e() != fb2.e()) {
int shift = fa2._e - fb2._e;
// if the difference between A-B's exponent > 24, return A's
value
if (shift > 24) {
return fa2.asInt();
}
long temp = fb2._f >> shift;
fb2.setE(fa2._e);
fb2.setF(temp);
}
//***************************************************************************************************
// addition- add or subtract
long mantissaMod;
// if Asign = Bsign, we add the mantissas
// if Asign ≠ Bsign, we subtract B from A
if (fa2.s() == fb2.s()) {
mantissaMod = fa2.f() + fb2.f();
} else {
mantissaMod = fa2.f() - fb2.f();
if (mantissaMod == 0) {
fa2.setE(0);
fa2.setF(0);
return fa2.asInt();
}
}
result.setS(fa2._s);
//***************************************************************************************************
// addition- normalize
do {
if (((1 << 26) & mantissaMod) != 0) {
mantissaMod >>= 1;
fa2._e++;
}
if (fa2._e >= 255) {
result.setE(255);
result.setF(0);
return result.asInt();
}
while (((1 << 25) & mantissaMod) == 0) {
mantissaMod <<= 1;
fa2._e--;
if (fa2._e <= 0) {
result.setF(mantissaMod >> 1);
result.setE(0);
return result.asInt();
}
}
long low2bit = mantissaMod & 3;
if (low2bit != 0) {
mantissaMod += 4;
}
} while (((1 << 25) & mantissaMod) == 0);
result.setF(mantissaMod);
result.setE(fa2._e);
return result.asInt();
}
//***************************************************************************************************
// multiply function
public int mul(int a, int b){
FPNumber fa = new FPNumber(a);
FPNumber fb = new FPNumber(b);
FPNumber result = new FPNumber(0);
//***************************************************************************************************
// multiply- handle exceptions
if (fa.isNaN() || fb.isNaN()) {
return (fa.isNaN() ? fa : fb).asInt();
}
if(fa.isZero() && fb.isInfinity()){
result.setE(255);
result.setF(1);
return result.asInt();
} else if(fb.isZero() && fa.isInfinity()){
result.setE(255);
result.setF(1);
return result.asInt();
}
result.setS((fa.s() != fb.s()) ? -1 : 1);
if(fa.isZero() || fb.isZero()){
return result.asInt();
}
if(fa.isInfinity() || fb.isInfinity()){
result.setE(255);
return result.asInt();
}
//***************************************************************************************************
// multiply- add the exponents
// temp exponent value
int temp_e = fa.e() + fb.e() - 127;
if(temp_e > 254) {
result.setE(255);
return result.asInt();
}else if(temp_e < 0) {
return result.asInt();
}
//***************************************************************************************************
// multiply- muliply mantissas
long mantissaMod = fa.f() * fb.f();
mantissaMod >>= 26;
temp_e+=1;
//***************************************************************************************************
// multiplication- normalize
do {
if (((1 << 26) & mantissaMod) != 0) {
mantissaMod >>= 1;
temp_e++;
}
if (temp_e >= 255) {
result.setE(255);
result.setF(0);
return result.asInt();
}
while (((1 << 25) & mantissaMod) == 0) {
mantissaMod <<= 1;
temp_e--;
if (temp_e <= 0) {
result.setF(mantissaMod >> 1);
result.setE(0);
return result.asInt();
}
}
long low2bit = mantissaMod & 3;
if (low2bit != 0) {
mantissaMod += 4;
}
} while (((1 << 25) & mantissaMod) == 0);
result.setF(mantissaMod);
result.setE(temp_e);
return result.asInt();
}
//***************************************************************************************************
// driver class
public static void main(String[] args) {
fp m = new fp();
//***************************************************************************************************
// TESTING THAT LED TO ERRORS
// ERROR 1: add same pos and neg number, result zero (EXPECTED 0, GOT -259.25)
int v129_625 = 0x4301A000; // 129.625
int v_129625 = 0xC301A000; // -129.625
System.out.println(Float.intBitsToFloat(m.add(v129_625, v_129625)) + " should be 0");
// ERROR 2: add plus and minus infinity (EXPECTED NaN, GOT minus infinity)
int vINF = 0x7F800000;
int _vINF = 0xFF800000;
System.out.println(Float.intBitsToFloat(m.add(vINF, _vINF)) + " should be NaN");
// ERROR 3: mul infinity and zero (EXPECTED NaN, GOT zero)
int zero = 0x00000000;
System.out.println(Float.intBitsToFloat(m.add(vINF, zero)) + "
should be NaN");
}
}
____________________________________________________________________________________________________
FPNumber.java
public class FPNumber{
int _s, _e;
long _f;
public FPNumber(int a){
_s = (((a >> 31) & 1) ==
1) ? -1 : 1;
_e = (a >> 23) &
0xFF;
_f = a & 0x7FFFFF;
if (_e != 0 && _e != 255){
_f |= 0x0800000;
}
_f <<= 2;
}
// setters and getters
public int s(){
return _s;
}
public int e(){
return _e;
}
public long f(){
return _f;
}
public void setS(int val){
_s = val;
}
public void setE(int val){
_e = val;
}
public void setF(long val){
_f = val;
}
public boolean isNaN(){
return _e == 255 && _f > 0;
}
public boolean isInfinity(){
return _e == 5 && _f == 0;
}
public boolean isZero(){
return _e == 0 && _f == 0;
}
public int asInt(){
return ((_s == -1) ? 0x80000000 : 0) | (_e <<
23) | (((int) _f >> 2) & 0x07FFFFF);
}
}
In: Computer Science