Пример #1
0
/*
 * Test inputs very close to 0.
 */
static void
test_tiny(void)
{
	float tiny = 0x1.23456p-120f;

	testall(asin, tiny, tiny, FE_INEXACT);
	testall(acos, tiny, pi / 2, FE_INEXACT);
	testall(atan, tiny, tiny, FE_INEXACT);

	testall(asin, -tiny, -tiny, FE_INEXACT);
	testall(acos, -tiny, pi / 2, FE_INEXACT);
	testall(atan, -tiny, -tiny, FE_INEXACT);

	/* Test inputs to atan2() that would cause y/x to underflow. */
	test2(atan2f, 0x1.0p-100, 0x1.0p100, 0.0, FE_INEXACT | FE_UNDERFLOW);
	test2(atan2, 0x1.0p-1000, 0x1.0p1000, 0.0, FE_INEXACT | FE_UNDERFLOW);
	test2(atan2l, ldexpl(1.0, 100 - LDBL_MAX_EXP),
	      ldexpl(1.0, LDBL_MAX_EXP - 100), 0.0, FE_INEXACT | FE_UNDERFLOW);
	test2(atan2f, -0x1.0p-100, 0x1.0p100, -0.0, FE_INEXACT | FE_UNDERFLOW);
	test2(atan2, -0x1.0p-1000, 0x1.0p1000, -0.0, FE_INEXACT | FE_UNDERFLOW);
	test2(atan2l, -ldexpl(1.0, 100 - LDBL_MAX_EXP),
	      ldexpl(1.0, LDBL_MAX_EXP - 100), -0.0, FE_INEXACT | FE_UNDERFLOW);
	test2(atan2f, 0x1.0p-100, -0x1.0p100, (float)pi, FE_INEXACT);
	test2(atan2, 0x1.0p-1000, -0x1.0p1000, (double)pi, FE_INEXACT);
	test2(atan2l, ldexpl(1.0, 100 - LDBL_MAX_EXP),
	      -ldexpl(1.0, LDBL_MAX_EXP - 100), pi, FE_INEXACT);
	test2(atan2f, -0x1.0p-100, -0x1.0p100, (float)-pi, FE_INEXACT);
	test2(atan2, -0x1.0p-1000, -0x1.0p1000, (double)-pi, FE_INEXACT);
	test2(atan2l, -ldexpl(1.0, 100 - LDBL_MAX_EXP),
	      -ldexpl(1.0, LDBL_MAX_EXP - 100), -pi, FE_INEXACT);
}
Пример #2
0
/*
 * Test various inputs to asin(), acos() and atan() and verify that the
 * results are accurate to within 1 ulp.
 */
static void
test_accuracy(void)
{

	/* We expect correctly rounded results for these basic cases. */
	testall(asin, 1.0, pi / 2, FE_INEXACT);
	testall(acos, 1.0, 0, 0);
	testall(atan, 1.0, pi / 4, FE_INEXACT);
	testall(asin, -1.0, -pi / 2, FE_INEXACT);
	testall(acos, -1.0, pi, FE_INEXACT);
	testall(atan, -1.0, -pi / 4, FE_INEXACT);

	/*
	 * Here we expect answers to be within 1 ulp, although inexactness
	 * in the input, combined with double rounding, could cause larger
	 * errors.
	 */

	testall_tol(asin, sqrtl(2) / 2, pi / 4, 1, FE_INEXACT);
	testall_tol(acos, sqrtl(2) / 2, pi / 4, 1, FE_INEXACT);
	testall_tol(asin, -sqrtl(2) / 2, -pi / 4, 1, FE_INEXACT);
	testall_tol(acos, -sqrtl(2) / 2, c3pi / 4, 1, FE_INEXACT);

	testall_tol(asin, sqrtl(3) / 2, pio3, 1, FE_INEXACT);
	testall_tol(acos, sqrtl(3) / 2, pio3 / 2, 1, FE_INEXACT);
	testall_tol(atan, sqrtl(3), pio3, 1, FE_INEXACT);
	testall_tol(asin, -sqrtl(3) / 2, -pio3, 1, FE_INEXACT);
	testall_tol(acos, -sqrtl(3) / 2, c5pio3 / 2, 1, FE_INEXACT);
	testall_tol(atan, -sqrtl(3), -pio3, 1, FE_INEXACT);

	testall_tol(atan, sqrt2m1, pi / 8, 1, FE_INEXACT);
	testall_tol(atan, -sqrt2m1, -pi / 8, 1, FE_INEXACT);
}
Пример #3
0
/*
 * Authors: Weiyan Lin
 * Purpose: It checks the arguments and run the program or
 *	    test 
 * 
 * Expected input: 1)[port number]
 *		     enter transaction mode and input command
 *		     using keyboard
 *		   2)[port number] < [file]
 *	             enter transaction mode and use file as
 *	             input command
 *
 e* Implementation details: Check the arguments are provided.
 * Run the corresponding mode.
 */
int main(int argc, char *argv[])
{

		if (argc >= 2 && strcmp(argv[1], "test") == 0)
		{
				testall();
				return 0;
		}
		machine *p_machine=malloc(sizeof(machine));
		memset(p_machine,0,sizeof(machine));
		mode_startup(p_machine);
		register_tcp_handlers();
		prepare_generic_socket(argc, argv, AF_INET, AI_PASSIVE, SOCK_STREAM, IPPROTO_TCP);
		if (listen(sock, 1) < 0)
		{
				vending_exit_with_error("listen failed",p_machine);
		}
		while(!stop)
		{

				struct ser_tran *torecv=malloc(sizeof(struct ser_tran));
				exit_torecv = torecv;
				memset(torecv,0,sizeof(struct ser_tran));
				receive_center(p_machine, torecv);
				connect_user(p_machine, torecv,argc,argv);
				sleep(2);
				free(torecv);		
		}

		//	free all the p_machine information
		int i;
		for (i=0; i <99; i++)
		{
				if ( p_machine->ptr_bg[i] != NULL)
				{       
						//if seq_num exists, get the address from pointer array
						free(p_machine->ptr_bg[i]);
				}

		}

		for(i=0;i<p_machine->item_num;i++)
		{
				free(p_machine->item[i].label);
		}	
		free(p_machine->item);	
		fclose(p_machine->log);	
		free(p_machine);
		cleanup();
		return 0;
}
Пример #4
0
/*
 * Test very large inputs to atan().
 */
static void
test_atan_huge(void)
{
	float huge = 0x1.23456p120;

#if !__APPLE__ && !__gnu_linux__
	testall(atan, huge, pi / 2, FE_INEXACT);
	testall(atan, -huge, -pi / 2, FE_INEXACT);
#endif /* !__APPLE__ && !__gnu_linux__ */

	/* Test inputs to atan2() that would cause y/x to overflow. */
	test2(atan2f, 0x1.0p100, 0x1.0p-100, (float)pi / 2, FE_INEXACT);
#if !__gnu_linux__
	test2(atan2, 0x1.0p1000, 0x1.0p-1000, (double)pi / 2, FE_INEXACT);
#endif /* !__gnu_linux__ */
	test2(atan2l, ldexpl(1.0, LDBL_MAX_EXP - 100),
	      ldexpl(1.0, 100 - LDBL_MAX_EXP), pi / 2, FE_INEXACT);
	test2(atan2f, -0x1.0p100, 0x1.0p-100, (float)-pi / 2, FE_INEXACT);
#if !__gnu_linux__
	test2(atan2, -0x1.0p1000, 0x1.0p-1000, (double)-pi / 2, FE_INEXACT);
#endif /* !__gnu_linux__ */
	test2(atan2l, -ldexpl(1.0, LDBL_MAX_EXP - 100),
	      ldexpl(1.0, 100 - LDBL_MAX_EXP), -pi / 2, FE_INEXACT);

#if !__gnu_linux__
	test2(atan2f, 0x1.0p100, -0x1.0p-100, (float)pi / 2, FE_INEXACT);
	test2(atan2, 0x1.0p1000, -0x1.0p-1000, (double)pi / 2, FE_INEXACT);
#endif /* !__gnu_linux__ */
	test2(atan2l, ldexpl(1.0, LDBL_MAX_EXP - 100),
	      -ldexpl(1.0, 100 - LDBL_MAX_EXP), pi / 2, FE_INEXACT);
#if !__gnu_linux__
	test2(atan2f, -0x1.0p100, -0x1.0p-100, (float)-pi / 2, FE_INEXACT);
	test2(atan2, -0x1.0p1000, -0x1.0p-1000, (double)-pi / 2, FE_INEXACT);
#endif /* !__gnu_linux__ */
	test2(atan2l, -ldexpl(1.0, LDBL_MAX_EXP - 100),
	      -ldexpl(1.0, 100 - LDBL_MAX_EXP), -pi / 2, FE_INEXACT);
}
Пример #5
0
void
umain(int argc, char **argv) {
  Heap heap;
  init_heap(&heap, &heapBuffer, 4*PGSIZE);
  set_heap(&heap);

  printall();
  cprintf("\n\nSTARTING TESTS\n\n");
  cprintf("should be empty\n\n");
  testall();
  cprintf("FINISHED tests\n\n");

  cprintf("\n\nSTARTING FAILURES\n\n");
  proof_check_expected_failures();
  cprintf("FINISHED failures\n\n");
}
Пример #6
0
static void
test_nans(void)
{

    testall(NAN, 0.0, 0.0, NAN, ALL_STD_EXCEPT, 0);
    testall(1.0, NAN, 1.0, NAN, ALL_STD_EXCEPT, 0);
    testall(1.0, -1.0, NAN, NAN, ALL_STD_EXCEPT, 0);
    testall(0.0, 0.0, NAN, NAN, ALL_STD_EXCEPT, 0);
    testall(NAN, NAN, NAN, NAN, ALL_STD_EXCEPT, 0);

    /* x*y should not raise an inexact/overflow/underflow if z is NaN. */
    testall(M_PI, M_PI, NAN, NAN, ALL_STD_EXCEPT, 0);
    test(fmaf, FLT_MIN, FLT_MIN, NAN, NAN, ALL_STD_EXCEPT, 0);
    test(fma, DBL_MIN, DBL_MIN, NAN, NAN, ALL_STD_EXCEPT, 0);
    test(fmal, LDBL_MIN, LDBL_MIN, NAN, NAN, ALL_STD_EXCEPT, 0);
    test(fmaf, FLT_MAX, FLT_MAX, NAN, NAN, ALL_STD_EXCEPT, 0);
    test(fma, DBL_MAX, DBL_MAX, NAN, NAN, ALL_STD_EXCEPT, 0);
    test(fmal, LDBL_MAX, LDBL_MAX, NAN, NAN, ALL_STD_EXCEPT, 0);
}
Пример #7
0
int
main(int argc, char *argv[])
{

	printf("1..12\n");

	testall(1, 1.0, 0.0);
	testall(2, 42.0, nextafterf(42.0, -INFINITY));
	testall(3, nextafterf(42.0, INFINITY), 42.0);
	testall(4, -5.0, -5.0);
	testall(5, -3.0, -4.0);
	testall(6, 1.0, NAN);
	testall(7, INFINITY, NAN);
	testall(8, INFINITY, 1.0);
	testall(9, -3.0, -INFINITY);
	testall(10, 3.0, -INFINITY);
	testall(11, NAN, NAN);

	/* This test isn't strictly required to work by C99. */
	testall(12, 0.0, -0.0);

	return (0);
}
Пример #8
0
/*
 * Test special case inputs in asin(), acos() and atan(): signed
 * zeroes, infinities, and NaNs.
 */
static void
test_special(void)
{

	testall(asin, 0.0, 0.0, 0);
	testall(acos, 0.0, pi / 2, FE_INEXACT);
	testall(atan, 0.0, 0.0, 0);
	testall(asin, -0.0, -0.0, 0);
	testall(acos, -0.0, pi / 2, FE_INEXACT);
	testall(atan, -0.0, -0.0, 0);

	testall(asin, INFINITY, NAN, FE_INVALID);
	testall(acos, INFINITY, NAN, FE_INVALID);
	testall(atan, INFINITY, pi / 2, FE_INEXACT);
	testall(asin, -INFINITY, NAN, FE_INVALID);
	testall(acos, -INFINITY, NAN, FE_INVALID);
	testall(atan, -INFINITY, -pi / 2, FE_INEXACT);

	testall(asin, NAN, NAN, 0);
	testall(acos, NAN, NAN, 0);
	testall(atan, NAN, NAN, 0);
}
Пример #9
0
// `J` Totally new method for image handling for .06.02.00
void cInterfaceWindow::PrepareImage(int id, sGirl* girl, int imagetype, bool rand, int ImageNum, bool gallery, string ImageName)
{
	if (!girl)	return;	// no girl, no images
	if (m_Images[id] &&
		m_Images[id]->m_AnimatedImage &&
		m_Images[id]->m_AnimatedImage->getNumFrames() > 0)
	{
		AG_FreeSurfaces(m_Images[id]->m_AnimatedImage->getAFrames(), m_Images[id]->m_AnimatedImage->getNumFrames());
		m_Images[id]->m_AnimatedImage->m_Gif = false;
		m_Images[id]->m_AnimatedImage = 0;
	}
	string girlName = girl->m_Name;

	int dir = 0; DirPath usedir = "";
	DirPath imagedirCc = DirPath(cfg.folders.characters().c_str()) << girlName;	// usedir = 1
	DirPath imagedirCo = DirPath() << "Resources" << "Characters" << girlName;	// usedir = 2
	DirPath imagedirDc = DirPath(cfg.folders.defaultimageloc().c_str());		// usedir = -1
	DirPath imagedirDo = DirPath() << "Resources" << "DefaultImages";			// usedir = -2
	FileList tiCc(imagedirCc, "*.*");
	FileList tiCo(imagedirCo, "*.*");
	FileList tiDc(imagedirDc, "*.*");
	FileList tiDo(imagedirDo, "*.*");
	int totalimagesCc = tiCc.size();
	int totalimagesCo = tiCo.size();
	int totalimagesDc = tiDc.size();
	int totalimagesDo = tiDo.size();
	if (totalimagesCc + totalimagesCo + totalimagesDc + totalimagesDo < 1)	// no images at all so return a blank image
	{
		m_Images[id]->m_Image = new CSurface(ImagePath("blank.png"));
		m_Images[id]->m_AnimatedImage = 0;
		m_Images[id]->m_Image->m_Message = "No image found.";
		return;
	}

	int tries = 40;
	if (gallery) tries = 0;
	else	// try some corrections
	{
		if (cfg.folders.preferdefault() || totalimagesCc + totalimagesCo < 1)	tries = 10;
		if (imagetype < 0 || imagetype > NUM_IMGTYPES)				imagetype = IMGTYPE_PROFILE;
		if (girl->is_pregnant() && imagetype < IMGTYPE_PREGNANT)	imagetype += PREG_OFFSET;
		if (!girl->is_pregnant() && imagetype == IMGTYPE_PREGNANT)	imagetype = IMGTYPE_PROFILE;
		if (!girl->is_pregnant() && imagetype > IMGTYPE_PREGNANT)	imagetype -= PREG_OFFSET;
	}

	string file = "";
	string filename = "";
	string ext = "";
	
	bool imagechosen = false;
	do
	{
		int tryimagetype = TryImageType(imagetype, tries);

		// choose an image folder
		dir = 0; usedir = "";
		string checkfor = pic_types[tryimagetype] + "*";
		if (tryimagetype == IMGTYPE_PREGNANT) checkfor = "pregnant*.*";

		if (totalimagesCc > 0)
		{
			FileList testall(imagedirCc, checkfor.c_str());
			if (tryimagetype == IMGTYPE_PREGNANT)
			{
				for (u_int i = 0; i < numeric.size(); i++)
				{
					string t = ("preg" + numeric.substr(i, 1) + "*.*");
					testall.add(t.c_str());
				}
			}
			if (testall.size() > 0)
			{
				usedir = imagedirCc;
				dir = 1;
			}
		}
		if (dir == 0 && totalimagesCo > 0)	// if config is not found, check for images in the original folder
		{
			FileList testall(imagedirCo, checkfor.c_str());
			if (tryimagetype == IMGTYPE_PREGNANT)
			{
				for (u_int i = 0; i < numeric.size(); i++)
				{
					string t = ("preg" + numeric.substr(i, 1) + "*.*");
					testall.add(t.c_str());
				}
			}
			if (testall.size() > 0)
			{
				usedir = imagedirCo;
				dir = 2;
			}
		}
		if (dir == 0 && gallery)	// gallery stops here if there are no images
		{
			m_Images[id]->m_Image = new CSurface(ImagePath("blank.png"));
			m_Images[id]->m_AnimatedImage = 0;
			m_Images[id]->m_Image->m_Message = "No images found.";
			break;
		}

		// if neither character folder has what we are looking for try the defaults
		if (totalimagesDc > 0 && dir == 0 && tries < 10)
		{
			FileList testall(imagedirDc, checkfor.c_str());
			if (tryimagetype == IMGTYPE_PREGNANT)
			{
				for (u_int i = 0; i < numeric.size(); i++)
				{
					string t = ("preg" + numeric.substr(i, 1) + "*.*");
					testall.add(t.c_str());
				}
			}
			if (testall.size() > 0)
			{
				usedir = imagedirDc;
				dir = -1;
			}
		}
		if (totalimagesDo > 0 && dir == 0 && tries < 10)
		{
			FileList testall(imagedirDo, checkfor.c_str());
			if (tryimagetype == IMGTYPE_PREGNANT)
			{
				for (u_int i = 0; i < numeric.size(); i++)
				{
					string t = ("preg" + numeric.substr(i, 1) + "*.*");
					testall.add(t.c_str());
				}
			}
			if (testall.size() > 0)
			{
				usedir = imagedirDo;
				dir = -2;
			}
		}
		if (dir == 0)
		{
			m_Images[id]->m_Image = new CSurface(ImagePath("blank.png"));
			m_Images[id]->m_AnimatedImage = 0;
			m_Images[id]->m_Image->m_Message = "No images found.";
			continue;
		}

		FileList testall(usedir, checkfor.c_str());
		if (tryimagetype == IMGTYPE_PREGNANT)
		{
			for (u_int i = 0; i < numeric.size(); i++)
			{
				string t = ("preg" + numeric.substr(i, 1) + "*.*");
				testall.add(t.c_str());
			}
		}
		if (testall.size() <= 0) continue;
		int num = ImageNum;
		if (rand || ImageNum < 0 || ImageNum >= testall.size()) num = g_Dice%testall.size();
		file = testall[num].full();
		filename = testall[num].leaf();
		ext = stringtolowerj(filename.substr(filename.find_last_of('.') + 1, filename.size()));

		if (ext == "ani")
		{
			DirPath anidir = usedir; anidir << "ani";
			string name = filename;
			name.erase(name.size() - 4, 4);
			name += ".jpg";
			FileList testani(anidir, name.c_str());
			if (testani.size() <= 0)
			{
				if (gallery)
				{
					m_Images[id]->m_Image = new CSurface(ImagePath("blank.png"));
					m_Images[id]->m_AnimatedImage = 0;
					m_Images[id]->m_Image->m_Message = "Bad ani file: Missing its matching jpg file: " + file;
					return;
				}
				continue;
			}
			anidir << name;
			cImage* newImage = new cImage();
			newImage->m_Surface = new CSurface();
			newImage->m_Surface->LoadImage(anidir.c_str());
			newImage->m_AniSurface = new cAnimatedSurface();
			int numFrames, speed, aniwidth, aniheight;
			ifstream input;
			input.open(file.c_str());
			if (!input)
			{
				g_LogFile.ss() << "Incorrect data file given for animation - " << file; g_LogFile.ssend();
				if (gallery)
				{
					m_Images[id]->m_Image = new CSurface(ImagePath("blank.png"));
					m_Images[id]->m_AnimatedImage = 0;
					m_Images[id]->m_Image->m_Message = "Bad ani file: Incorrect data file given for animation: " + file;
					return;
				}
			}
			else
			{
				input >> numFrames >> speed >> aniwidth >> aniheight;
				m_Images[id]->m_AnimatedImage = new cAnimatedSurface();
				m_Images[id]->m_AnimatedImage->SetData(0, 0, numFrames, speed, aniwidth, aniheight, newImage->m_Surface);
				imagechosen = true;
				m_Images[id]->m_Image->m_Message = file;
			}
			input.close();
		}
		else if (ext == "gif")
		{
 			const char* n = file.c_str();
			int frames = AG_LoadGIF(n, NULL, 0);
			if (frames)
			{
				cImage* newImage = new cImage();
				newImage->m_Surface = new CSurface();
				newImage->m_Surface->LoadImage(file);
				newImage->m_AniSurface = new cAnimatedSurface();
				AG_Frame* gpAG = new AG_Frame[frames];
				AG_LoadGIF(n, gpAG, frames);
				m_Images[id]->m_Image = newImage->m_Surface;
				m_Images[id]->m_Image->m_Message = file;
				m_Images[id]->m_AnimatedImage = new cAnimatedSurface();
				m_Images[id]->m_AnimatedImage->SetGifData(0, 0, frames, gpAG, newImage->m_Surface);
				imagechosen = true;
			}
			else	// if it does not read as a gif, just load it as a normal image
			{
				m_Images[id]->m_Image = new CSurface(file);
				m_Images[id]->m_AnimatedImage = 0;
				imagechosen = true;
			}
		}
		else
		{
			m_Images[id]->m_Image = new CSurface(file);
			m_Images[id]->m_AnimatedImage = 0;
			imagechosen = true;
		}
	}	while (!imagechosen && --tries > 0);
Пример #10
0
static void
run_tests(void)
{

	assert(fesetround(FE_DOWNWARD) == 0);
	testall(0.75, 0, FE_INEXACT);
	testall(-0.5, -1, FE_INEXACT);

	assert(fesetround(FE_TONEAREST) == 0);
	testall(0.0, 0, 0);
	testall(0.25, 0, FE_INEXACT);
	testall(0.5, 0, FE_INEXACT);
	testall(-2.5, -2, FE_INEXACT);
	testall(1.0, 1, 0);
	testall(0x12345000p0, 0x12345000, 0);
	testall(0x1234.fp0, 0x1235, FE_INEXACT);
	testall(INFINITY, IGNORE, FE_INVALID);
	testall(NAN, IGNORE, FE_INVALID);

#if (LONG_MAX == 0x7fffffffl)
	assert(fesetround(FE_UPWARD) == 0);
	test(lrint, 0x7fffffff.8p0, IGNORE, FE_INVALID);
	test(lrint, -0x80000000.4p0, -0x80000000l, FE_INEXACT);

	assert(fesetround(FE_DOWNWARD) == 0);
	test(lrint, -0x80000000.8p0, IGNORE, FE_INVALID);
	test(lrint, 0x80000000.0p0, IGNORE, FE_INVALID);
	test(lrint, 0x7fffffff.4p0, 0x7fffffffl, FE_INEXACT);
	test(lrintf, 0x80000000.0p0f, IGNORE, FE_INVALID);
	test(lrintf, 0x7fffff80.0p0f, 0x7fffff80l, 0);

	assert(fesetround(FE_TOWARDZERO) == 0);
	test(lrint, 0x7fffffff.8p0,  0x7fffffffl, FE_INEXACT);
	test(lrint, -0x80000000.8p0, -0x80000000l, FE_INEXACT);
	test(lrint, 0x80000000.0p0, IGNORE, FE_INVALID);
	test(lrintf, 0x80000000.0p0f, IGNORE, FE_INVALID);
	test(lrintf, 0x7fffff80.0p0f, 0x7fffff80l, 0);
#elif (LONG_MAX == 0x7fffffffffffffffll)
	assert(fesetround(FE_TONEAREST) == 0);
	test(lrint, 0x8000000000000000.0p0, IGNORE, FE_INVALID);
	test(lrintf, 0x8000000000000000.0p0f, IGNORE, FE_INVALID);
	test(lrint, 0x7ffffffffffffc00.0p0, 0x7ffffffffffffc00l, 0);
	test(lrintf, 0x7fffff8000000000.0p0f, 0x7fffff8000000000l, 0);
	test(lrint, -0x8000000000000800.0p0, IGNORE, FE_INVALID);
	test(lrintf, -0x8000010000000000.0p0f, IGNORE, FE_INVALID);
	test(lrint, -0x8000000000000000.0p0, -0x8000000000000000l, 0);
	test(lrintf, -0x8000000000000000.0p0f, -0x8000000000000000l, 0);
#else
#error "Unsupported long size"
#endif

#if (LLONG_MAX == 0x7fffffffffffffffLL)
	assert(fesetround(FE_TONEAREST) == 0);
	test(llrint, 0x8000000000000000.0p0, IGNORE, FE_INVALID);
	test(llrintf, 0x8000000000000000.0p0f, IGNORE, FE_INVALID);
	test(llrint, 0x7ffffffffffffc00.0p0, 0x7ffffffffffffc00ll, 0);
	test(llrintf, 0x7fffff8000000000.0p0f, 0x7fffff8000000000ll, 0);
	test(llrint, -0x8000000000000800.0p0, IGNORE, FE_INVALID);
	test(llrintf, -0x8000010000000000.0p0f, IGNORE, FE_INVALID);
	test(llrint, -0x8000000000000000.0p0, -0x8000000000000000ll, 0);
	test(llrintf, -0x8000000000000000.0p0f, -0x8000000000000000ll, 0);
#else
#error "Unsupported long long size"
#endif
}
Пример #11
0
/*
 * Tests for NaN inputs.
 */
void
test_nan()
{
	long double complex nan_nan = CMPLXL(NAN, NAN);
	long double complex z;

	/*
	 * IN		CACOSH	    CACOS	CASINH	    CATANH
	 * NaN,NaN	NaN,NaN	    NaN,NaN	NaN,NaN	    NaN,NaN
	 * finite,NaN	NaN,NaN*    NaN,NaN*	NaN,NaN*    NaN,NaN*
	 * NaN,finite   NaN,NaN*    NaN,NaN*	NaN,NaN*    NaN,NaN*
	 * NaN,Inf	Inf,NaN     NaN,-Inf	?Inf,NaN    ?0,pi/2	
	 * +-Inf,NaN	Inf,NaN     NaN,?Inf	+-Inf,NaN   +-0,NaN
	 * +-0,NaN	NaN,NaN*    pi/2,NaN	NaN,NaN*    +-0,NaN
	 * NaN,0	NaN,NaN*    NaN,NaN*	NaN,0	    NaN,NaN*
	 *
	 *  * = raise invalid
	 */
	z = nan_nan;
	testall(cacosh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
	testall(cacos, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
	testall(casinh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
	testall(casin, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
	testall(catanh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
	testall(catan, z, nan_nan, ALL_STD_EXCEPT, 0, 0);

	z = CMPLXL(0.5, NAN);
	testall(cacosh, z, nan_nan, OPT_INVALID, 0, 0);
	testall(cacos, z, nan_nan, OPT_INVALID, 0, 0);
	testall(casinh, z, nan_nan, OPT_INVALID, 0, 0);
	testall(casin, z, nan_nan, OPT_INVALID, 0, 0);
	testall(catanh, z, nan_nan, OPT_INVALID, 0, 0);
	testall(catan, z, nan_nan, OPT_INVALID, 0, 0);

	z = CMPLXL(NAN, 0.5);
	testall(cacosh, z, nan_nan, OPT_INVALID, 0, 0);
	testall(cacos, z, nan_nan, OPT_INVALID, 0, 0);
	testall(casinh, z, nan_nan, OPT_INVALID, 0, 0);
	testall(casin, z, nan_nan, OPT_INVALID, 0, 0);
	testall(catanh, z, nan_nan, OPT_INVALID, 0, 0);
	testall(catan, z, nan_nan, OPT_INVALID, 0, 0);

	z = CMPLXL(NAN, INFINITY);
	testall(cacosh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
	testall(cacosh, -z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
	testall(cacos, z, CMPLXL(NAN, -INFINITY), ALL_STD_EXCEPT, 0, CS_IMAG);
	testall(casinh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0, 0);
	testall(casin, z, CMPLXL(NAN, INFINITY), ALL_STD_EXCEPT, 0, CS_IMAG);
	testall_tol(catanh, z, CMPLXL(0.0, pi / 2), 1);
	testall(catan, z, CMPLXL(NAN, 0.0), ALL_STD_EXCEPT, 0, CS_IMAG);

	z = CMPLXL(INFINITY, NAN);
	testall_even(cacosh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0,
		     CS_REAL);
	testall_even(cacos, z, CMPLXL(NAN, INFINITY), ALL_STD_EXCEPT, 0, 0);
	testall_odd(casinh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0,
		    CS_REAL);
	testall_odd(casin, z, CMPLXL(NAN, INFINITY), ALL_STD_EXCEPT, 0, 0);
	testall_odd(catanh, z, CMPLXL(0.0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
	testall_odd_tol(catan, z, CMPLXL(pi / 2, 0.0), 1);

	z = CMPLXL(0.0, NAN);
        /* XXX We allow a spurious inexact exception here. */
	testall_even(cacosh, z, nan_nan, OPT_INVALID & ~FE_INEXACT, 0, 0);
	testall_even_tol(cacos, z, CMPLXL(pi / 2, NAN), 1);
	testall_odd(casinh, z, nan_nan, OPT_INVALID, 0, 0);
	testall_odd(casin, z, CMPLXL(0.0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
	testall_odd(catanh, z, CMPLXL(0.0, NAN), OPT_INVALID, 0, CS_REAL);
	testall_odd(catan, z, nan_nan, OPT_INVALID, 0, 0);

	z = CMPLXL(NAN, 0.0);
	testall(cacosh, z, nan_nan, OPT_INVALID, 0, 0);
	testall(cacos, z, nan_nan, OPT_INVALID, 0, 0);
	testall(casinh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, CS_IMAG);
	testall(casin, z, nan_nan, OPT_INVALID, 0, 0);
	testall(catanh, z, nan_nan, OPT_INVALID, 0, CS_IMAG);
	testall(catan, z, CMPLXL(NAN, 0.0), ALL_STD_EXCEPT, 0, 0);
}
Пример #12
0
/*
 * Check access.
 *
 * This method check a file or recursively scan directories and verify
 * the file access modes are enforced.
 */
void
check_access (char *pathname, uid_t uid, gid_t gid)
{
  int count = 0;
  int i = 0;
  int rc = 0;
  char entry[MAXPATHLEN];
  struct dirent **entries;
  struct stat statbuf;

  /* Start with clean buffers */
  memset (&statbuf, '\0', sizeof (statbuf));

  /* Test System V Message Queue - IPC */
  if ((strcmp (pathname, "ipc_obj")) == 0)
    {
      printf ("Testing IPC objects\n");
      if (check_ipc (uid, gid) == -1)
        {
          printf ("\nERROR: %s. Could not obtain ipc "
                  "status. errno = %d\n", pathname, errno);
          goto EXIT;
        }
      goto EXIT;
    }
  /* Get file stat info. */
  if ((rc = lstat (pathname, &statbuf)) == -1)
    {
      printf ("\nERROR: %s. Could not obtain file status. errno = %d\n",
              pathname, errno);
      goto EXIT;
    }

  /* If link, skip it. */
  if (S_ISLNK (statbuf.st_mode))
    {
      printf ("Link: skipping %s\n", entry);
      goto EXIT;
    }

  /* If not a directory, check it and leave. */
  if (!(S_ISDIR (statbuf.st_mode)))
    {
      testall (&statbuf, pathname, uid, gid);
      goto EXIT;
    }

  /*
   *If directory, recurse through all subdirectories,
   * checking all files.
   */
  if ((count = scandir (pathname, &entries, file_select, alphasort)) == -1)
    {
      printf ("\nERROR: %s. Could not scandir. errno = %d\n",
              pathname, errno);
      goto EXIT;
    }
  for (i = 0; i < count; i++)
    {
      sprintf (entry, "%s/%s", pathname, entries[i]->d_name);
      /*
       * If link, skip it
       * Else if directory, call check_access() recursively
       */
      if (entries[i]->d_type == DT_LNK)
        {
          printf ("Link: skipping %s\n", entry);
          continue;
        }
      else if (entries[i]->d_type == DT_DIR)
        {
          check_access (entry, uid, gid);
          continue;
        }

      /* Clean the buffer */
      memset (&statbuf, '\0', sizeof (statbuf));

      /* Get file stat info. */
      if ((rc = lstat (entry, &statbuf)) == -1)
        {
          printf ("\nERROR: %s. Could not obtain file status. errno = %d\n",
                  pathname, errno);
          continue;
        }

      /* The directory entry doesn't always seem to have the
       * right info. So we check again after the stat().
       *
       * If link, skip it
       * Else if directory, call check_access() recursively
       * Else check access
       */
      if (S_ISLNK (statbuf.st_mode))
        {
          printf ("Link: (2) skipping %s\n", entry);
          continue;
        }
      else if (S_ISDIR (statbuf.st_mode))
        {
          check_access (entry, uid, gid);
          continue;
        }
      else
        {
          testall (&statbuf, entry, uid, gid);
          continue;
        }
    }
EXIT:
  return;
}
Пример #13
0
void
test_inf(void)
{
	int i;

	/* cexp(x + inf i) = NaN + NaNi and raises invalid */
	for (i = 0; i < N(finites); i++) {
		printf("# Run %d..\n", i);
		testall(CMPLXL(finites[i], INFINITY), CMPLXL(NAN, NAN),
			ALL_STD_EXCEPT, FE_INVALID, 1);
	}
	/* cexp(-inf + yi) = 0 * (cos(y) + sin(y)i) */
	/* XXX shouldn't raise an inexact exception */
	testall(CMPLXL(-INFINITY, M_PI_4), CMPLXL(0.0, 0.0),
		ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
	testall(CMPLXL(-INFINITY, 3 * M_PI_4), CMPLXL(-0.0, 0.0),
		ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
	testall(CMPLXL(-INFINITY, 5 * M_PI_4), CMPLXL(-0.0, -0.0),
		ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
	testall(CMPLXL(-INFINITY, 7 * M_PI_4), CMPLXL(0.0, -0.0),
		ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
	testall(CMPLXL(-INFINITY, 0.0), CMPLXL(0.0, 0.0),
		ALL_STD_EXCEPT, 0, 1);
	testall(CMPLXL(-INFINITY, -0.0), CMPLXL(0.0, -0.0),
		ALL_STD_EXCEPT, 0, 1);
	/* cexp(inf + yi) = inf * (cos(y) + sin(y)i) (except y=0) */
	/* XXX shouldn't raise an inexact exception */
	testall(CMPLXL(INFINITY, M_PI_4), CMPLXL(INFINITY, INFINITY),
		ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
	testall(CMPLXL(INFINITY, 3 * M_PI_4), CMPLXL(-INFINITY, INFINITY),
		ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
	testall(CMPLXL(INFINITY, 5 * M_PI_4), CMPLXL(-INFINITY, -INFINITY),
		ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
	testall(CMPLXL(INFINITY, 7 * M_PI_4), CMPLXL(INFINITY, -INFINITY),
		ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
	/* cexp(inf + 0i) = inf + 0i */
	testall(CMPLXL(INFINITY, 0.0), CMPLXL(INFINITY, 0.0),
		ALL_STD_EXCEPT, 0, 1);
	testall(CMPLXL(INFINITY, -0.0), CMPLXL(INFINITY, -0.0),
		ALL_STD_EXCEPT, 0, 1);
}
Пример #14
0
/*
 * Test special case inputs in asin(), acos() and atan(): signed
 * zeroes, infinities, and NaNs.
 */
static void
test_special(void)
{

#if !__APPLE__
	testall(asin, 0.0, 0.0, 0);
#endif /* !__APPLE__ */
#if !__gnu_linux__
	testall(acos, 0.0, pi / 2, FE_INEXACT);
#endif /* !__gnu_linux__ */
#if !__APPLE__
	testall(atan, 0.0, 0.0, 0);
	testall(asin, -0.0, -0.0, 0);
#endif /* !__APPLE__ */
#if !__gnu_linux__
	testall(acos, -0.0, pi / 2, FE_INEXACT);
#endif /* !__gnu_linux__ */
#if !__APPLE__
	testall(atan, -0.0, -0.0, 0);
#endif /* !__APPLE__ */

	testall(asin, INFINITY, NAN, FE_INVALID);
	testall(acos, INFINITY, NAN, FE_INVALID);
#if !__APPLE__ && !__gnu_linux__
	testall(atan, INFINITY, pi / 2, FE_INEXACT);
#endif /* !__APPLE__ && !__gnu_linux__ */
	testall(asin, -INFINITY, NAN, FE_INVALID);
	testall(acos, -INFINITY, NAN, FE_INVALID);
#if !__APPLE__ && !__gnu_linux__
	testall(atan, -INFINITY, -pi / 2, FE_INEXACT);
#endif /* !__APPLE__ && !__gnu_linux__ */

	testall(asin, NAN, NAN, 0);
	testall(acos, NAN, NAN, 0);
	testall(atan, NAN, NAN, 0);
}
Пример #15
0
int
main(int argc, char *argv[])
{
	static const int ex_under = FE_UNDERFLOW | FE_INEXACT;	/* shorthand */
	static const int ex_over = FE_OVERFLOW | FE_INEXACT;
	long double ldbl_small, ldbl_eps, ldbl_max;

	printf("1..5\n");

#ifdef	__i386__
	fpsetprec(FP_PE);
#endif
	/*
	 * We can't use a compile-time constant here because gcc on
	 * FreeBSD/i386 assumes long doubles are truncated to the
	 * double format.
	 */
	ldbl_small = ldexpl(1.0, LDBL_MIN_EXP - LDBL_MANT_DIG);
	ldbl_eps = LDBL_EPSILON;
	ldbl_max = ldexpl(1.0 - ldbl_eps / 2, LDBL_MAX_EXP);

	/*
	 * Special cases involving zeroes.
	 */
#define	ztest(prec)							      \
	test##prec(copysign##prec(1.0, nextafter##prec(0.0, -0.0)), -1.0, 0); \
	test##prec(copysign##prec(1.0, nextafter##prec(-0.0, 0.0)), 1.0, 0);  \
	test##prec(copysign##prec(1.0, nexttoward##prec(0.0, -0.0)), -1.0, 0);\
	test##prec(copysign##prec(1.0, nexttoward##prec(-0.0, 0.0)), 1.0, 0)

	ztest();
	ztest(f);
	ztest(l);
#undef	ztest

#define	stest(next, eps, prec)					\
	test##prec(next(-0.0, 42.0), eps, ex_under);		\
	test##prec(next(0.0, -42.0), -eps, ex_under);		\
	test##prec(next(0.0, INFINITY), eps, ex_under);		\
	test##prec(next(-0.0, -INFINITY), -eps, ex_under)

	stest(nextafter, 0x1p-1074, );
	stest(nextafterf, 0x1p-149f, f);
	stest(nextafterl, ldbl_small, l);
	stest(nexttoward, 0x1p-1074, );
	stest(nexttowardf, 0x1p-149f, f);
	stest(nexttowardl, ldbl_small, l);
#undef	stest

	printf("ok 1 - next\n");

	/*
	 * `x == y' and NaN tests
	 */
	testall(42.0, 42.0, 42.0, 0);
	testall(-42.0, -42.0, -42.0, 0);
	testall(INFINITY, INFINITY, INFINITY, 0);
	testall(-INFINITY, -INFINITY, -INFINITY, 0);
	testall(NAN, 42.0, NAN, 0);
	testall(42.0, NAN, NAN, 0);
	testall(NAN, NAN, NAN, 0);

	printf("ok 2 - next\n");

	/*
	 * Tests where x is an ordinary normalized number
	 */
	testboth(1.0, 2.0, 1.0 + DBL_EPSILON, 0, );
	testboth(1.0, -INFINITY, 1.0 - DBL_EPSILON/2, 0, );
	testboth(1.0, 2.0, 1.0 + FLT_EPSILON, 0, f);
	testboth(1.0, -INFINITY, 1.0 - FLT_EPSILON/2, 0, f);
	testboth(1.0, 2.0, 1.0 + ldbl_eps, 0, l);
	testboth(1.0, -INFINITY, 1.0 - ldbl_eps/2, 0, l);

	testboth(-1.0, 2.0, -1.0 + DBL_EPSILON/2, 0, );
	testboth(-1.0, -INFINITY, -1.0 - DBL_EPSILON, 0, );
	testboth(-1.0, 2.0, -1.0 + FLT_EPSILON/2, 0, f);
	testboth(-1.0, -INFINITY, -1.0 - FLT_EPSILON, 0, f);
	testboth(-1.0, 2.0, -1.0 + ldbl_eps/2, 0, l);
	testboth(-1.0, -INFINITY, -1.0 - ldbl_eps, 0, l);

	/* Cases where nextafter(...) != nexttoward(...) */
	test(nexttoward(1.0, 1.0 + ldbl_eps), 1.0 + DBL_EPSILON, 0);
	testf(nexttowardf(1.0, 1.0 + ldbl_eps), 1.0 + FLT_EPSILON, 0);
	testl(nexttowardl(1.0, 1.0 + ldbl_eps), 1.0 + ldbl_eps, 0);

	printf("ok 3 - next\n");

	/*
	 * Tests at word boundaries, normalization boundaries, etc.
	 */
	testboth(0x1.87654ffffffffp+0, INFINITY, 0x1.87655p+0, 0, );
	testboth(0x1.87655p+0, -INFINITY, 0x1.87654ffffffffp+0, 0, );
	testboth(0x1.fffffffffffffp+0, INFINITY, 0x1p1, 0, );
	testboth(0x1p1, -INFINITY, 0x1.fffffffffffffp+0, 0, );
	testboth(0x0.fffffffffffffp-1022, INFINITY, 0x1p-1022, 0, );
	testboth(0x1p-1022, -INFINITY, 0x0.fffffffffffffp-1022, ex_under, );

	testboth(0x1.fffffep0f, INFINITY, 0x1p1, 0, f);
	testboth(0x1p1, -INFINITY, 0x1.fffffep0f, 0, f);
	testboth(0x0.fffffep-126f, INFINITY, 0x1p-126f, 0, f);
	testboth(0x1p-126f, -INFINITY, 0x0.fffffep-126f, ex_under, f);

#if LDBL_MANT_DIG == 53
	testboth(0x1.87654ffffffffp+0L, INFINITY, 0x1.87655p+0L, 0, l);
	testboth(0x1.87655p+0L, -INFINITY, 0x1.87654ffffffffp+0L, 0, l);
	testboth(0x1.fffffffffffffp+0L, INFINITY, 0x1p1L, 0, l);
	testboth(0x1p1L, -INFINITY, 0x1.fffffffffffffp+0L, 0, l);
	testboth(0x0.fffffffffffffp-1022L, INFINITY, 0x1p-1022L, 0, l);
	testboth(0x1p-1022L, -INFINITY, 0x0.fffffffffffffp-1022L, ex_under, l);
#elif LDBL_MANT_DIG == 64 && !defined(__i386)
	testboth(0x1.87654321fffffffep+0L, INFINITY, 0x1.87654322p+0L, 0, l);
	testboth(0x1.87654322p+0L, -INFINITY, 0x1.87654321fffffffep+0L, 0, l);
	testboth(0x1.fffffffffffffffep0L, INFINITY, 0x1p1L, 0, l);
	testboth(0x1p1L, -INFINITY, 0x1.fffffffffffffffep0L, 0, l);
	testboth(0x0.fffffffffffffffep-16382L, INFINITY, 0x1p-16382L, 0, l);
	testboth(0x1p-16382L, -INFINITY,
	    0x0.fffffffffffffffep-16382L, ex_under, l);
#elif LDBL_MANT_DIG == 113
	testboth(0x1.876543210987ffffffffffffffffp+0L, INFINITY,
	    0x1.876543210988p+0, 0, l);
	testboth(0x1.876543210988p+0L, -INFINITY,
	    0x1.876543210987ffffffffffffffffp+0L, 0, l);
	testboth(0x1.ffffffffffffffffffffffffffffp0L, INFINITY, 0x1p1L, 0, l);
	testboth(0x1p1L, -INFINITY, 0x1.ffffffffffffffffffffffffffffp0L, 0, l);
	testboth(0x0.ffffffffffffffffffffffffffffp-16382L, INFINITY,
	    0x1p-16382L, 0, l);
	testboth(0x1p-16382L, -INFINITY,
	    0x0.ffffffffffffffffffffffffffffp-16382L, ex_under, l);
#endif

	printf("ok 4 - next\n");

	/*
	 * Overflow tests
	 */
	test(idd(nextafter(DBL_MAX, INFINITY)), INFINITY, ex_over);
	test(idd(nextafter(INFINITY, 0.0)), DBL_MAX, 0);
	test(idd(nexttoward(DBL_MAX, DBL_MAX * 2.0L)), INFINITY, ex_over);
#if LDBL_MANT_DIG > 53
	test(idd(nexttoward(INFINITY, DBL_MAX * 2.0L)), DBL_MAX, 0);
#endif

	testf(idf(nextafterf(FLT_MAX, INFINITY)), INFINITY, ex_over);
	testf(idf(nextafterf(INFINITY, 0.0)), FLT_MAX, 0);
	testf(idf(nexttowardf(FLT_MAX, FLT_MAX * 2.0)), INFINITY, ex_over);
	testf(idf(nexttowardf(INFINITY, FLT_MAX * 2.0)), FLT_MAX, 0);

	testboth(ldbl_max, INFINITY, INFINITY, ex_over, l);
	testboth(INFINITY, 0.0, ldbl_max, 0, l);

	printf("ok 5 - next\n");

	return (0);
}
Пример #16
0
static void
test_infinities(void)
{

    testall(INFINITY, 1.0, -1.0, INFINITY, ALL_STD_EXCEPT, 0);
    testall(-1.0, INFINITY, 0.0, -INFINITY, ALL_STD_EXCEPT, 0);
    testall(0.0, 0.0, INFINITY, INFINITY, ALL_STD_EXCEPT, 0);
    testall(1.0, 1.0, INFINITY, INFINITY, ALL_STD_EXCEPT, 0);
    testall(1.0, 1.0, -INFINITY, -INFINITY, ALL_STD_EXCEPT, 0);

    testall(INFINITY, -INFINITY, 1.0, -INFINITY, ALL_STD_EXCEPT, 0);
    testall(INFINITY, INFINITY, 1.0, INFINITY, ALL_STD_EXCEPT, 0);
    testall(-INFINITY, -INFINITY, INFINITY, INFINITY, ALL_STD_EXCEPT, 0);

    testall(0.0, INFINITY, 1.0, NAN, ALL_STD_EXCEPT, FE_INVALID);
    testall(INFINITY, 0.0, -0.0, NAN, ALL_STD_EXCEPT, FE_INVALID);

    /* The invalid exception is optional in this case. */
    testall(INFINITY, 0.0, NAN, NAN, ALL_STD_EXCEPT & ~FE_INVALID, 0);

    testall(INFINITY, INFINITY, -INFINITY, NAN,
            ALL_STD_EXCEPT, FE_INVALID);
    testall(-INFINITY, INFINITY, INFINITY, NAN,
            ALL_STD_EXCEPT, FE_INVALID);
    testall(INFINITY, -1.0, INFINITY, NAN,
            ALL_STD_EXCEPT, FE_INVALID);

    test(fmaf, FLT_MAX, FLT_MAX, -INFINITY, -INFINITY, ALL_STD_EXCEPT, 0);
    test(fma, DBL_MAX, DBL_MAX, -INFINITY, -INFINITY, ALL_STD_EXCEPT, 0);
    test(fmal, LDBL_MAX, LDBL_MAX, -INFINITY, -INFINITY,
         ALL_STD_EXCEPT, 0);
    test(fmaf, FLT_MAX, -FLT_MAX, INFINITY, INFINITY, ALL_STD_EXCEPT, 0);
    test(fma, DBL_MAX, -DBL_MAX, INFINITY, INFINITY, ALL_STD_EXCEPT, 0);
    test(fmal, LDBL_MAX, -LDBL_MAX, INFINITY, INFINITY,
         ALL_STD_EXCEPT, 0);
}
Пример #17
0
void testit(void){
  testall(1.0, true);
  testall(1.0, false);
}
Пример #18
0
static void
test_zeroes(void)
{
    const int rd = (fegetround() == FE_DOWNWARD);

    testall(0.0, 0.0, 0.0, 0.0, ALL_STD_EXCEPT, 0);
    testall(1.0, 0.0, 0.0, 0.0, ALL_STD_EXCEPT, 0);
    testall(0.0, 1.0, 0.0, 0.0, ALL_STD_EXCEPT, 0);
    testall(0.0, 0.0, 1.0, 1.0, ALL_STD_EXCEPT, 0);

    testall(-0.0, 0.0, 0.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0);
    testall(0.0, -0.0, 0.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0);
    testall(-0.0, -0.0, 0.0, 0.0, ALL_STD_EXCEPT, 0);
    testall(0.0, 0.0, -0.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0);
    testall(-0.0, -0.0, -0.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0);

    testall(-0.0, 0.0, -0.0, -0.0, ALL_STD_EXCEPT, 0);
    testall(0.0, -0.0, -0.0, -0.0, ALL_STD_EXCEPT, 0);

    testall(-1.0, 1.0, 1.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0);
    testall(1.0, -1.0, 1.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0);
    testall(-1.0, -1.0, -1.0, rd ? -0.0 : 0.0, ALL_STD_EXCEPT, 0);

    switch (fegetround()) {
    case FE_TONEAREST:
    case FE_TOWARDZERO:
        test(fmaf, -FLT_MIN, FLT_MIN, 0.0, -0.0,
             ALL_STD_EXCEPT, FE_INEXACT | FE_UNDERFLOW);
        test(fma, -DBL_MIN, DBL_MIN, 0.0, -0.0,
             ALL_STD_EXCEPT, FE_INEXACT | FE_UNDERFLOW);
        test(fmal, -LDBL_MIN, LDBL_MIN, 0.0, -0.0,
             ALL_STD_EXCEPT, FE_INEXACT | FE_UNDERFLOW);
    }
}
Пример #19
0
/*
 * Test special cases in sin(), cos(), and tan().
 */
static void
run_special_tests(void)
{

	/* Values at 0 should be exact. */
	testall(tan, 0.0, 0.0, ALL_STD_EXCEPT, 0);
	testall(tan, -0.0, -0.0, ALL_STD_EXCEPT, 0);
	testall(cos, 0.0, 1.0, ALL_STD_EXCEPT, 0);
	testall(cos, -0.0, 1.0, ALL_STD_EXCEPT, 0);
	testall(sin, 0.0, 0.0, ALL_STD_EXCEPT, 0);
	testall(sin, -0.0, -0.0, ALL_STD_EXCEPT, 0);

	/* func(+-Inf) == NaN */
	testall(tan, INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
	testall(sin, INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
	testall(cos, INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
	testall(tan, -INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
	testall(sin, -INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
	testall(cos, -INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);

	/* func(NaN) == NaN */
	testall(tan, NAN, NAN, ALL_STD_EXCEPT, 0);
	testall(sin, NAN, NAN, ALL_STD_EXCEPT, 0);
	testall(cos, NAN, NAN, ALL_STD_EXCEPT, 0);
}