Пример #1
0
osgToy::RhombicDodecahedron::RhombicDodecahedron()
{
    setOverallColor( osg::Vec4(0,1,0,1) );

    osg::Vec3 a0(  1,  1,  1 );
    osg::Vec3 a1(  1,  1, -1 );
    osg::Vec3 a2(  1, -1,  1 );
    osg::Vec3 a3(  1, -1, -1 );
    osg::Vec3 a4( -1,  1,  1 );
    osg::Vec3 a5( -1,  1, -1 );
    osg::Vec3 a6( -1, -1,  1 );
    osg::Vec3 a7( -1, -1, -1 );

    osg::Vec3 xp(  2,  0,  0 );
    osg::Vec3 xn( -2,  0,  0 );
    osg::Vec3 yp(  0,  2,  0 );
    osg::Vec3 yn(  0, -2,  0 );
    osg::Vec3 zp(  0,  0,  2 );
    osg::Vec3 zn(  0,  0, -2 );

    addTristrip( yp, a0, a1, xp );
    addTristrip( xp, a2, a3, yn );
    addTristrip( yn, a6, a7, xn );
    addTristrip( xn, a4, a5, yp );

    addTristrip( zp, a0, a4, yp );
    addTristrip( yp, a1, a5, zn );
    addTristrip( zn, a3, a7, yn );
    addTristrip( yn, a2, a6, zp );

    addTristrip( xp, a0, a2, zp );
    addTristrip( zp, a4, a6, xn );
    addTristrip( xn, a5, a7, zn );
    addTristrip( zn, a1, a3, xp );

    osgToy::FacetingVisitor::facet( *this );
}
Пример #2
0
void
yybessely(void)
{
	double d;
	int n;

	N = pop();
	X = pop();

	push(N);
	n = pop_integer();

	if (isdouble(X) && n != (int) 0x80000000) {
		d = yn(n, X->u.d);
		push_double(d);
		return;
	}
	
	if (isnegativeterm(N)) {
		push_integer(-1);
		push(N);
		power();
		push_symbol(BESSELY);
		push(X);
		push(N);
		negate();
		list(3);
		multiply();
		return;
	}

	push_symbol(BESSELY);
	push(X);
	push(N);
	list(3);
	return;
}
Пример #3
0
int
dosave()
{
	clear_nhwindow(WIN_MESSAGE);
	if(yn("Really save?") == 'n') {
		clear_nhwindow(WIN_MESSAGE);
		if(multi > 0) nomul(0);
	} else {
		clear_nhwindow(WIN_MESSAGE);
		pline("Saving...");
#if defined(UNIX) || defined(VMS) || defined(__EMX__)
		program_state.done_hup = 0;
#endif
		if(dosave0()) {
			program_state.something_worth_saving = 0;
			u.uhp = -1;		/* universal game's over indicator */
			/* make sure they see the Saving message */
			display_nhwindow(WIN_MESSAGE, TRUE);
			exit_nhwindows("Be seeing you...");
			terminate(EXIT_SUCCESS);
		} else (void)doredraw();
	}
	return 0;
}
Пример #4
0
/* returns 1 if save successful */
int
dosave0(void)
{
    const char *fq_save;
    register int fd, ofd;
    xchar ltmp;
    d_level uz_save;
    char whynot[BUFSZ];

#ifdef WHEREIS_FILE
    delete_whereis();
#endif

    if (!SAVEF[0])
        return 0;
    fq_save = fqname(SAVEF, SAVEPREFIX, 1);	/* level files take 0 */

#if defined(UNIX) || defined(VMS)
    (void) signal(SIGHUP, SIG_IGN);
#endif
#ifndef NO_SIGNAL
    (void) signal(SIGINT, SIG_IGN);
#endif

#if defined(MICRO) && defined(MFLOPPY)
    if (!saveDiskPrompt(0)) return 0;
#endif

    HUP if (iflags.window_inited) {
        uncompress_area(fq_save, SAVEF);
        fd = open_savefile();
        if (fd > 0) {
            (void) close(fd);
            clear_nhwindow(WIN_MESSAGE);
            There("seems to be an old save file.");
            if (yn("Overwrite the old file?") == 'n') {
                compress_area(fq_save, SAVEF);
                return 0;
            }
        }
    }

    HUP mark_synch();	/* flush any buffered screen output */

    fd = create_savefile();
    if(fd < 0) {
        HUP pline("Cannot open save file.");
        (void) delete_savefile();	/* ab@unido */
        return(0);
    }

    vision_recalc(2);	/* shut down vision to prevent problems
				   in the event of an impossible() call */

    /* undo date-dependent luck adjustments made at startup time */
    if(flags.moonphase == FULL_MOON)	/* ut-sally!fletcher */
        change_luck(-1);		/* and unido!ab */
    if(flags.friday13)
        change_luck(1);
    if(iflags.window_inited)
        HUP clear_nhwindow(WIN_MESSAGE);

#ifdef MICRO
    dotcnt = 0;
    dotrow = 2;
    curs(WIN_MAP, 1, 1);
    if (strncmpi("X11", windowprocs.name, 3))
        putstr(WIN_MAP, 0, "Saving:");
#endif
#ifdef MFLOPPY
    /* make sure there is enough disk space */
    if (iflags.checkspace) {
        long fds, needed;

        savelev(fd, ledger_no(&u.uz), COUNT_SAVE);
        savegamestate(fd, COUNT_SAVE);
        needed = bytes_counted;

        for (ltmp = 1; ltmp <= maxledgerno(); ltmp++)
            if (ltmp != ledger_no(&u.uz) && level_info[ltmp].where)
                needed += level_info[ltmp].size + (sizeof ltmp);
        fds = freediskspace(fq_save);
        if (needed > fds) {
            HUP {
                There("is insufficient space on SAVE disk.");
                pline("Require %ld bytes but only have %ld.", needed, fds);
            }
            flushout();
            (void) close(fd);
            (void) delete_savefile();
            return 0;
        }
Пример #5
0
/* Handles one turn of book reading. Returns 1 if unfinished, 0 if finshed. */
static int
learn(void)
{
    int i;
    short booktype;
    boolean costly = TRUE;
    boolean already_known = FALSE;
    int first_unknown = MAXSPELL;
    int known_spells = 0;
    const char *splname;

    /* JDS: lenses give 50% faster reading; 33% smaller read time */
    if (u.uoccupation_progress[tos_book] &&
        ublindf && ublindf->otyp == LENSES && rn2(2))
        u.uoccupation_progress[tos_book]++;
    if (Confusion) {    /* became confused while learning */
        confused_book(u.utracked[tos_book]);
        u.utracked[tos_book] = 0;       /* no longer studying */
        helpless(-u.uoccupation_progress[tos_book], hr_busy,
                 "absorbed in a spellbook",
                 "You're finally able to put the book down.");
        u.uoccupation_progress[tos_book] = 0;
        return 0;
    }

    booktype = u.utracked[tos_book]->otyp;
    if (booktype == SPE_BOOK_OF_THE_DEAD) {
        deadbook(u.utracked[tos_book], FALSE);
        u.utracked[tos_book] = 0;
        u.uoccupation_progress[tos_book] = 0;
        return 0;
    }

    /* The book might get cursed while we're reading it. In this case,
       immediately stop reading it, cancel progress, and apply a few turns of
       helplessness. (3.4.3 applies negative spellbook effects but lets you
       memorize the spell anyway; this makes no sense. It destroys the spellbook
       on the "contact poison" result, which makes even less sense.) */
    if (u.utracked[tos_book]->cursed) {
        pline("This book isn't making sense any more.");
        helpless(rn1(5,5), hr_busy,
                 "making sense of a spellbook",
                 "You give up trying to make sense of the spellbook.");
        u.uoccupation_progress[tos_book] = 0;
        u.utracked[tos_book] = 0;
        return 0;
    }

    if (++u.uoccupation_progress[tos_book] < 0)
        return 1;       /* still busy */

    if (ACURR(A_WIS) < 12)
        exercise(A_WIS, TRUE); /* you're studying. */

    splname = msgprintf(objects[booktype].oc_name_known ?
                        "\"%s\"" : "the \"%s\" spell",
                        OBJ_NAME(objects[booktype]));
    for (i = 0; i < MAXSPELL; i++) {
        if (spellid(i) == booktype) {
            already_known = TRUE;
            if (u.utracked[tos_book]->spestudied > MAX_SPELL_STUDY) {
                pline("This spellbook is too faint to be read any more.");
                u.utracked[tos_book]->otyp = booktype = SPE_BLANK_PAPER;
            } else if (spellknow(i) <= 1000) {
                pline("Your knowledge of %s is keener.", splname);
                incrnknow(i);
                u.utracked[tos_book]->spestudied++;
                if (ACURR(A_WIS) < 12)
                    exercise(A_WIS, TRUE); /* extra study */
            } else {    /* 1000 < spellknow(i) <= MAX_SPELL_STUDY */
                pline("You know %s quite well already.", splname);
                if (yn("Do you want to read the book anyway?") == 'y') {
                    pline("You refresh your knowledge of %s.", splname);
                    incrnknow(i);
                    u.utracked[tos_book]->spestudied++;
                } else
                    costly = FALSE;
            }
            /* make book become known even when spell is already known, in case
               amnesia made you forget the book */
            makeknown((int)booktype);
            break;
        } else if (spellid(i) == NO_SPELL &&
                   (i < first_unknown ||
                    i == spellno_from_let(objects[booktype].oc_defletter)))
            first_unknown = i;
        else
            known_spells++;
    }

    if (first_unknown == MAXSPELL && !already_known)
        panic("Too many spells memorized!");

    if (!already_known) {
        spl_book[first_unknown].sp_id = booktype;
        spl_book[first_unknown].sp_lev = objects[booktype].oc_level;
        incrnknow(first_unknown);
        u.utracked[tos_book]->spestudied++;
        pline(known_spells > 0 ? "You add %s to your repertoire." :
              "You learn %s.", splname);
        makeknown((int)booktype);
    }

    if (costly)
        check_unpaid(u.utracked[tos_book]);
    u.utracked[tos_book] = 0;
    return 0;
}
Пример #6
0
/*
 * Look in the "data" file for more info.  Called if the user typed in the
 * whole name (user_typed_name == TRUE), or we've found a possible match
 * with a character/glyph.
 */
static void
checkfile(const char *inp, struct permonst *pm, boolean user_typed_name,
          boolean without_asking)
{
    dlb *fp;
    char buf[BUFSZ], newstr[BUFSZ];
    char *ep, *dbase_str;
    long txt_offset = 0;
    int chk_skip;
    boolean found_in_file = FALSE, skipping_entry = FALSE;

    fp = dlb_fopen(DATAFILE, "r");
    if (!fp) {
        pline("Cannot open data file!");
        return;
    }

    /* To prevent the need for entries in data.base like *ngel to account for
       Angel and angel, make the lookup string the same for both
       user_typed_name and picked name. */
    if (pm != NULL && !user_typed_name)
        dbase_str = strcpy(newstr, pm->mname);
    else
        dbase_str = strcpy(newstr, inp);

    for (ep = dbase_str; *ep; ep++)
        *ep = lowc(*ep);

    if (!strncmp(dbase_str, "interior of ", 12))
        dbase_str += 12;
    if (!strncmp(dbase_str, "a ", 2))
        dbase_str += 2;
    else if (!strncmp(dbase_str, "an ", 3))
        dbase_str += 3;
    else if (!strncmp(dbase_str, "the ", 4))
        dbase_str += 4;
    if (!strncmp(dbase_str, "tame ", 5))
        dbase_str += 5;
    else if (!strncmp(dbase_str, "peaceful ", 9))
        dbase_str += 9;
    if (!strncmp(dbase_str, "invisible ", 10))
        dbase_str += 10;
    if (!strncmp(dbase_str, "statue of ", 10))
        dbase_str[6] = '\0';
    else if (!strncmp(dbase_str, "figurine of ", 12))
        dbase_str[8] = '\0';

    /* Make sure the name is non-empty. */
    if (*dbase_str) {
        /* adjust the input to remove " [seen" and "named " and convert to
           lower case */
        const char *alt = 0;  /* alternate description */

        if ((ep = strstri_mutable(dbase_str, " [seen")) != 0)
            *ep = '\0';

        if ((ep = strstri_mutable(dbase_str, " named ")) != 0)
            alt = ep + 7;
        else
            ep = strstri_mutable(dbase_str, " called ");
        if (!ep)
            ep = strstri_mutable(dbase_str, ", ");
        if (ep && ep > dbase_str)
            *ep = '\0';

        /* 
         * If the object is named, then the name is the alternate description;
         * otherwise, the result of makesingular() applied to the name is. This
         * isn't strictly optimal, but named objects of interest to the user
         * will usually be found under their name, rather than under their
         * object type, so looking for a singular form is pointless.
         */

        if (!alt)
            alt = makesingular(dbase_str);
        else if (user_typed_name)
            alt = msglowercase(alt);

        /* skip first record; read second */
        txt_offset = 0L;
        if (!dlb_fgets(buf, BUFSZ, fp) || !dlb_fgets(buf, BUFSZ, fp)) {
            impossible("can't read 'data' file");
            dlb_fclose(fp);
            return;
        } else if (sscanf(buf, "%8lx\n", &txt_offset) < 1 || txt_offset <= 0)
            goto bad_data_file;

        /* look for the appropriate entry */
        while (dlb_fgets(buf, BUFSZ, fp)) {
            if (*buf == '.')
                break;  /* we passed last entry without success */

            if (digit(*buf)) {
                /* a number indicates the end of current entry */
                skipping_entry = FALSE;
            } else if (!skipping_entry) {
                if (!(ep = strchr(buf, '\n')))
                    goto bad_data_file;
                *ep = 0;
                /* if we match a key that begins with "~", skip this entry */
                chk_skip = (*buf == '~') ? 1 : 0;
                if (pmatch(&buf[chk_skip], dbase_str) ||
                    (alt && pmatch(&buf[chk_skip], alt))) {
                    if (chk_skip) {
                        skipping_entry = TRUE;
                        continue;
                    } else {
                        found_in_file = TRUE;
                        break;
                    }
                }
            }
        }
    }

    if (found_in_file) {
        long entry_offset;
        int entry_count;
        int i;

        /* skip over other possible matches for the info */
        do {
            if (!dlb_fgets(buf, BUFSZ, fp))
                goto bad_data_file;
        } while (!digit(*buf));

        if (sscanf(buf, "%ld,%d\n", &entry_offset, &entry_count) < 2) {
        bad_data_file:impossible("'data' file in wrong format");
            dlb_fclose(fp);
            return;
        }

        if (user_typed_name || without_asking || yn("More info?") == 'y') {
            struct nh_menulist menu;

            if (dlb_fseek(fp, txt_offset + entry_offset, SEEK_SET) < 0) {
                pline("? Seek error on 'data' file!");
                dlb_fclose(fp);
                return;
            }

            init_menulist(&menu);

            for (i = 0; i < entry_count; i++) {
                if (!dlb_fgets(buf, BUFSZ, fp))
                    goto bad_data_file;
                if ((ep = strchr(buf, '\n')) != 0)
                    *ep = 0;
                if (strchr(buf + 1, '\t') != 0)
                    tabexpand(buf + 1);
                add_menutext(&menu, buf + 1);
            }

            display_menu(&menu, NULL, FALSE, PLHINT_ANYWHERE,
                         NULL);
        }
    } else if (user_typed_name)
        pline("I don't have any information on those things.");

    dlb_fclose(fp);
}
Пример #7
0
void Strand2dFCBlockSolver::gradSetupSub(Array3D<double>& gx)
{
  // initialize coefficient array
  gx.set(0.);


  // form quadratic sub elements
  int meshOrderL=2,nElemLocalL=meshOrder-1,nSurfElemL=nSurfElem*nElemLocalL;
  Array3D<int> surfElemL(nSurfElemL,meshOrderL+1,2);
  Array3D<int> elemLocalL(nElemLocalL,meshOrderL+1,2);
  if (meshOrder == 2){
    elemLocalL(0,0,0) = 0; elemLocalL(0,0,1) = 1;
    elemLocalL(0,1,0) = 1; elemLocalL(0,1,1) = 1;
    elemLocalL(0,2,0) = 2; elemLocalL(0,2,1) = 1;
  }
  else if (meshOrder == 3){
    elemLocalL(0,0,0) = 0; elemLocalL(0,0,1) = 1;
    elemLocalL(0,1,0) = 3; elemLocalL(0,1,1) = 0;
    elemLocalL(0,2,0) = 2; elemLocalL(0,2,1) = 1;
    elemLocalL(1,0,0) = 2; elemLocalL(1,0,1) = 0;
    elemLocalL(1,1,0) = 1; elemLocalL(1,1,1) = 1;
    elemLocalL(1,2,0) = 3; elemLocalL(1,2,1) = 1;
  }
  else if (meshOrder == 4){
    elemLocalL(0,0,0) = 0; elemLocalL(0,0,1) = 1;
    elemLocalL(0,1,0) = 3; elemLocalL(0,1,1) = 0;
    elemLocalL(0,2,0) = 2; elemLocalL(0,2,1) = 1;
    elemLocalL(1,0,0) = 2; elemLocalL(1,0,1) = 0;
    elemLocalL(1,1,0) = 4; elemLocalL(1,1,1) = 0;
    elemLocalL(1,2,0) = 3; elemLocalL(1,2,1) = 1;
    elemLocalL(2,0,0) = 3; elemLocalL(2,0,1) = 0;
    elemLocalL(2,1,0) = 1; elemLocalL(2,1,1) = 1;
    elemLocalL(2,2,0) = 4; elemLocalL(2,2,1) = 1;
  }
  
  int k=0;
  for (int n=0; n<nSurfElem; n++)
    for (int i=0; i<nElemLocalL; i++){
      for (int m=0; m<meshOrderL+1; m++){
	surfElemL(k,m,0) = surfElem(n,elemLocalL(i,m,0));
	surfElemL(k,m,1) = elemLocalL(i,m,1);
      }
      k++;
    }
  if (k != nSurfElemL){
    cout << "\n***Problem forming sub-elements in initialize.C***"
	 << endl;
    exit(0);
  }
 

  // Lagrange polynomial derivatives for lower order elements
  int spacing=0; // assume equally spaced points in surface elements for now
  Array1D<double> ss(meshOrderL+1);
  solutionPoints1D(meshOrderL,
		   spacing,
		   &ss(0));

  bool test=false;
  Array2D<double> lc(meshOrderL+1,meshOrderL+1);
  lagrangePoly1D(test, // coefficients to form Lagrange polynomials
		 meshOrderL,
		 &ss(0),
		 &lc(0,0));

  // ls(i,j) = (dl_j/ds)_i (a row is all Lagrange polynomials (derivatives)
  // evaluated at a single mesh point i)
  Array2D<double> lsL(meshOrderL+1,meshOrderL+1);
  lsL.set(0.);
  int km;
  for (int i=0; i<meshOrderL+1; i++) // ith mesh point
    for (int j=0; j<meshOrderL+1; j++) // jth Lagrange polynomial
      for (int k=0; k<meshOrderL+1; k++){
	km        = max(0,k-1);
	lsL(i,j) +=((double)k)*pow(ss(i),km)*lc(j,k);
      }


  // mapping terms for lower order elements
  Array3D<double> xsL(nSurfElemL,meshOrderL+1,nStrandNode);
  Array3D<double> ysL(nSurfElemL,meshOrderL+1,nStrandNode);
  Array3D<double> jacL(nSurfElemL,meshOrderL+1,nStrandNode);
  xsL.set(0.);
  ysL.set(0.);
  int ni,nm;
  double x0,y0,nx,ny;
  for (int n=0; n<nSurfElemL; n++)
    for (int i=0; i<meshOrderL+1; i++){ // ith point in the element
      ni = surfElemL(n,i,0);
      for (int m=0; m<meshOrderL+1; m++){ // mth Lagrange poly. in mapping
	nm = surfElemL(n,m,0);
	x0 = surfX(nm,0);
	y0 = surfX(nm,1);
	nx = pointingVec(nm,0);
	ny = pointingVec(nm,1);
	for (int j=0; j<nStrandNode; j++){
	  xsL(n,i,j) += lsL(i,m)*(x0+nx*strandX(j));
	  ysL(n,i,j) += lsL(i,m)*(y0+ny*strandX(j));
	}}
      for (int j=0; j<nStrandNode; j++)
	jacL(n,i,j) = xsL(n,i,j)*yn(ni,j)-ysL(n,i,j)*xn(ni,j);
    }


  // degree at each surface node
  Array1D<int> sum(nSurfNode);
  sum.set(0);
  for (int n=0; n<nSurfElemL; n++)
    for (int i=0; i<meshOrderL+1; i++)
      sum(surfElemL(n,i,0)) += surfElemL(n,i,1);


  // use elements to form gradient coefficients
  double xnj,ynj;
  Array3D<double> a(nSurfNode,nStrandNode,2);
  a.set(0.);
  for (int n=0; n<nSurfElemL; n++)
    for (int i=0; i<meshOrderL+1; i++){ //ith point in the element
      if (surfElemL(n,i,1) == 1){ //if a contributing node
	ni = surfElemL(n,i,0);
	for (int m=0; m<meshOrderL+1; m++){ //mth Lagrange poly. in mapping
	  nm = surfElemL(n,m,0);
	  for (int j=0; j<nStrandNode; j++){ //local gradient coefficients
	    xnj       = xn(ni,j)/(jacL(n,i,j)*(double)sum(ni));
	    ynj       = yn(ni,j)/(jacL(n,i,j)*(double)sum(ni));
	    a(nm,j,0) = lsL(i,m)*ynj;
	    a(nm,j,1) =-lsL(i,m)*xnj;
	  }}
	for (int m=psp2(ni); m<psp2(ni+1); m++){ //add to coefficient array
	  nm = psp1(m);
	  for (int j=0; j<nStrandNode; j++){
	    gx(m,j,0) += a(nm,j,0);
	    gx(m,j,1) += a(nm,j,1);
	  }}
	for (int m=0; m<meshOrderL+1; m++){ //reset helper array to zero
	  nm = surfElemL(n,m,0);
	  for (int j=0; j<nStrandNode; j++){
	    a(nm,j,0) = 0.;
	    a(nm,j,1) = 0.;
	  }}}}


  // clean up
  sum.deallocate();
  a.deallocate();
  surfElemL.deallocate();
  elemLocalL.deallocate();
  xsL.deallocate();
  ysL.deallocate();
  ss.deallocate();
  lc.deallocate();
  lsL.deallocate();
}
Пример #8
0
double dbesyn_ (const integer *n, double *x) {
    return yn (*n, *x);
}
Пример #9
0
double
G77_dbesyn_0 (const integer * n, double *x)
{
  return yn (*n, *x);
}
Пример #10
0
int Sphere::Triangulate(float3 *outPos, float3 *outNormal, float2 *outUV, int numVertices, bool ccwIsFrontFacing) const
{
	assume(outPos);
	assume(numVertices >= 24 && "At minimum, sphere triangulation will contain at least 8 triangles, which is 24 vertices, but fewer were specified!");
	assume(numVertices % 3 == 0 && "Warning:: The size of output should be divisible by 3 (each triangle takes up 3 vertices!)");

#ifndef MATH_ENABLE_INSECURE_OPTIMIZATIONS
	if (!outPos)
		return 0;
#endif
	assume(this->r > 0.f);

	if (numVertices < 24)
		return 0;

#ifdef MATH_ENABLE_STL_SUPPORT
	std::vector<Triangle> temp;
#else
	Array<Triangle> temp;
#endif
	// Start subdividing from a diamond shape.
	float3 xp(r,0,0);
	float3 xn(-r,0,0);
	float3 yp(0,r,0);
	float3 yn(0,-r,0);
	float3 zp(0,0,r);
	float3 zn(0,0,-r);

	if (ccwIsFrontFacing)
	{
		temp.push_back(Triangle(yp,xp,zp));
		temp.push_back(Triangle(xp,yp,zn));
		temp.push_back(Triangle(yn,zp,xp));
		temp.push_back(Triangle(yn,xp,zn));
		temp.push_back(Triangle(zp,xn,yp));
		temp.push_back(Triangle(yp,xn,zn));
		temp.push_back(Triangle(yn,xn,zp));
		temp.push_back(Triangle(xn,yn,zn));
	}
	else
	{
		temp.push_back(Triangle(yp,zp,xp));
		temp.push_back(Triangle(xp,zn,yp));
		temp.push_back(Triangle(yn,xp,zp));
		temp.push_back(Triangle(yn,zn,xp));
		temp.push_back(Triangle(zp,yp,xn));
		temp.push_back(Triangle(yp,zn,xn));
		temp.push_back(Triangle(yn,zp,xn));
		temp.push_back(Triangle(xn,zn,yn));
	}

	int oldEnd = 0;
	while(((int)temp.size()-oldEnd+3)*3 <= numVertices)
	{
		Triangle cur = temp[oldEnd];
		float3 a = ((cur.a + cur.b) * 0.5f).ScaledToLength(this->r);
		float3 b = ((cur.a + cur.c) * 0.5f).ScaledToLength(this->r);
		float3 c = ((cur.b + cur.c) * 0.5f).ScaledToLength(this->r);

		temp.push_back(Triangle(cur.a, a, b));
		temp.push_back(Triangle(cur.b, c, a));
		temp.push_back(Triangle(cur.c, b, c));
		temp.push_back(Triangle(a, c, b));

		++oldEnd;
	}
	// Check that we really did tessellate as many new triangles as possible.
	assert(((int)temp.size()-oldEnd)*3 <= numVertices && ((int)temp.size()-oldEnd)*3 + 9 > numVertices);

	for(size_t i = oldEnd, j = 0; i < temp.size(); ++i, ++j)
	{
		outPos[3*j] = this->pos + temp[i].a;
		outPos[3*j+1] = this->pos + temp[i].b;
		outPos[3*j+2] = this->pos + temp[i].c;
	}

	if (outNormal)
		for(size_t i = oldEnd, j = 0; i < temp.size(); ++i, ++j)
		{
			outNormal[3*j] = temp[i].a.Normalized();
			outNormal[3*j+1] = temp[i].b.Normalized();
			outNormal[3*j+2] = temp[i].c.Normalized();
		}

	if (outUV)
		for(size_t i = oldEnd, j = 0; i < temp.size(); ++i, ++j)
		{
			outUV[3*j] = float2(atan2(temp[i].a.y, temp[i].a.x) / (2.f * 3.141592654f) + 0.5f, (temp[i].a.z + r) / (2.f * r));
			outUV[3*j+1] = float2(atan2(temp[i].b.y, temp[i].b.x) / (2.f * 3.141592654f) + 0.5f, (temp[i].b.z + r) / (2.f * r));
			outUV[3*j+2] = float2(atan2(temp[i].c.y, temp[i].c.x) / (2.f * 3.141592654f) + 0.5f, (temp[i].c.z + r) / (2.f * r));
		}

	return ((int)temp.size() - oldEnd) * 3;
}
Пример #11
0
/**
 * Given either a SkStream or a SkData, try to decode the encoded
 * image using the specified options and report errors.
 */
static void test_options(skiatest::Reporter* reporter,
                         const SkDecodingImageGenerator::Options& opts,
                         SkStreamRewindable* encodedStream,
                         SkData* encodedData,
                         bool useData,
                         const SkString& path) {
    SkBitmap bm;
    bool success = false;
    if (useData) {
        if (NULL == encodedData) {
            return;
        }
        success = SkInstallDiscardablePixelRef(
            SkDecodingImageGenerator::Create(encodedData, opts), &bm);
    } else {
        if (NULL == encodedStream) {
            return;
        }
        success = SkInstallDiscardablePixelRef(
            SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts), &bm);
    }
    if (!success) {
        if (opts.fUseRequestedColorType
            && (kARGB_4444_SkColorType == opts.fRequestedColorType)) {
            return;  // Ignore known conversion inabilities.
        }
        // If we get here, it's a failure and we will need more
        // information about why it failed.
        ERRORF(reporter, "Bounds decode failed [sampleSize=%d dither=%s "
               "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage),
               options_colorType(opts), path.c_str());
        return;
    }
    #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
    // Android is the only system that use Skia's image decoders in
    // production.  For now, we'll only verify that samplesize works
    // on systems where it already is known to work.
    REPORTER_ASSERT(reporter, check_rounding(bm.height(), kExpectedHeight,
                                             opts.fSampleSize));
    REPORTER_ASSERT(reporter, check_rounding(bm.width(), kExpectedWidth,
                                             opts.fSampleSize));
    // The ImageDecoder API doesn't guarantee that SampleSize does
    // anything at all, but the decoders that this test excercises all
    // produce an output size in the following range:
    //    (((sample_size * out_size) > (in_size - sample_size))
    //     && out_size <= SkNextPow2(((in_size - 1) / sample_size) + 1));
    #endif  // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX
    SkAutoLockPixels alp(bm);
    if (bm.getPixels() == NULL) {
        ERRORF(reporter, "Pixel decode failed [sampleSize=%d dither=%s "
               "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage),
               options_colorType(opts), path.c_str());
        return;
    }

    SkColorType requestedColorType = opts.fRequestedColorType;
    REPORTER_ASSERT(reporter,
                    (!opts.fUseRequestedColorType)
                    || (bm.colorType() == requestedColorType));

    // Condition under which we should check the decoding results:
    if ((kN32_SkColorType == bm.colorType())
        && (!path.endsWith(".jpg"))  // lossy
        && (opts.fSampleSize == 1)) {  // scaled
        const SkColor* correctPixels = kExpectedPixels;
        SkASSERT(bm.height() == kExpectedHeight);
        SkASSERT(bm.width() == kExpectedWidth);
        int pixelErrors = 0;
        for (int y = 0; y < bm.height(); ++y) {
            for (int x = 0; x < bm.width(); ++x) {
                if (*correctPixels != bm.getColor(x, y)) {
                    ++pixelErrors;
                }
                ++correctPixels;
            }
        }
        if (pixelErrors != 0) {
            ERRORF(reporter, "Pixel-level mismatch (%d of %d) "
                   "[sampleSize=%d dither=%s colorType=%s %s]",
                   pixelErrors, kExpectedHeight * kExpectedWidth,
                   opts.fSampleSize, yn(opts.fDitherImage),
                   options_colorType(opts), path.c_str());
        }
    }
}
Пример #12
0
/* Record the breaking of a roleplay-conduct. */
void violated(int cdt)
{
	switch (cdt) {
	case CONDUCT_PACIFISM:
	    u.uconduct.killer++;
	    if (u.roleplay.pacifist) {
		pline("你感到狂暴!");
		if (yn("你确定要退出吗?") == 'y') {
		    killer_format = NO_KILLER_PREFIX;
		    killer = "在一阵狂暴之后退出";
		    done(QUIT);
		}
		if (u.uconduct.killer >= 10) u.roleplay.pacifist = FALSE;
	    }
	    break;

	case CONDUCT_NUDISM:
	    u.uconduct.armoruses++;
	    if (u.roleplay.nudist) {
		pline("你意识到你光着身子。");
		makemon(&mons[PM_COBRA], level, u.ux, u.uy, NO_MM_FLAGS);
		mksobj_at(APPLE, level, u.ux, u.uy, FALSE, FALSE);
		u.roleplay.nudist = FALSE;
	    }
	    break;

	case CONDUCT_BLINDFOLDED:
	    u.uconduct.unblinded++;
	    if (u.roleplay.blindfolded) {
		pline("禅之精神,离开你的身体。");
		makemon(mkclass(&level->z, S_ZOMBIE, 0),
			level, u.ux, u.uy, NO_MM_FLAGS);	/* Z */
		makemon(mkclass(&level->z, S_EYE, 0),
			level, u.ux, u.uy, NO_MM_FLAGS);	/* e */
		makemon(mkclass(&level->z, S_NYMPH, 0),
			level, u.ux, u.uy, NO_MM_FLAGS);	/* n */
		u.roleplay.blindfolded = FALSE;
	    }
	    break;

	case CONDUCT_VEGETARIAN:	/* replaces violated_vegetarian() */
	    if (u.roleplay.vegetarian)
		pline("你感到内疚。");
	    if (Role_if(PM_MONK))
		adjalign(-1);
	    u.uconduct.unvegetarian++;
	    u.uconduct.unvegan++;
	    u.uconduct.food++;
	    if (u.uconduct.unvegetarian >= 30) u.roleplay.vegetarian = FALSE;
	    if (u.uconduct.unvegan >= 20) u.roleplay.vegan = FALSE;
	    if (u.uconduct.food >= 10) u.roleplay.ascet = FALSE;
	    break;

	case CONDUCT_VEGAN:
	    if (u.roleplay.vegan)
		pline("你感到有点内疚。");
	    u.uconduct.unvegan++;
	    u.uconduct.food++;
	    if (u.uconduct.unvegan >= 20) u.roleplay.vegan = FALSE;
	    if (u.uconduct.food >= 10) u.roleplay.ascet = FALSE;
	    break;

	case CONDUCT_FOODLESS:
	    if (u.roleplay.ascet)
		pline("你略微感到内疚。");
	    u.uconduct.food++;
	    if (u.uconduct.food >= 10) u.roleplay.ascet = FALSE;
	    break;

	case CONDUCT_ILLITERACY:
	    u.uconduct.literate++;
	    if (u.roleplay.illiterate) {
		/* should be impossible */
		pline("Literatally literature for literate illiterates!");
		exercise(A_WIS, TRUE);
	    }
	    break;

	case CONDUCT_THIEVERY:
	    u.uconduct.robbed++;
	    if (Role_if(PM_ROGUE))
		pline("你感觉自己像一个强盗。");
	    break;

	default:
	    impossible("violated: unknown conduct");
	}
}
Пример #13
0
static double
l_yn(char *nm)
{
    return(yn((int)(argument(1)+.5), argument(2)));
}
Пример #14
0
TEST(math, yn) {
  ASSERT_DOUBLE_EQ(-HUGE_VAL, yn(4, 0.0));
  ASSERT_DOUBLE_EQ(-33.278423028972114, yn(4, 1.0));
}
Пример #15
0
/* So you want music... */
int
do_play_instrument(struct obj *instr, const struct nh_cmd_arg *arg)
{
    char c = 'y';
    const char *buf;
    int x, y;
    boolean ok;

    if (Underwater) {
        pline(msgc_cancelled, "You can't play music underwater!");
        return 0;
    }
    if (Upolyd && !can_blow_instrument(youmonst.data) &&
        (instr->otyp == BUGLE || instr->otyp == WOODEN_FLUTE ||
         instr->otyp == MAGIC_FLUTE || instr->otyp == TOOLED_HORN ||
         instr->otyp == FIRE_HORN || instr->otyp == FROST_HORN)) {
        pline(msgc_cancelled,
              "You are incapable of playing %s in your current form!",
              the(xname(instr)));
        return 0;
    }
    if (instr->otyp != LEATHER_DRUM && instr->otyp != DRUM_OF_EARTHQUAKE) {
        c = yn("Improvise?");
    }
    if (c == 'n') {
        if (u.uevent.uheard_tune == 2 && yn("Play the passtune?") == 'y') {
            buf = msg_from_string(gamestate.castle_tune);
        } else {
            /* Note: This is explicitly not getarglin(); we don't want
               command repeat to repeat the tune. */
            buf = getlin("What tune are you playing? [5 notes, A-G]", FALSE);
            if (*buf == '\033')
                buf = "";
            buf = msgmungspaces(buf);
            /* convert to uppercase and change any "H" to the expected "B" */
            buf = msgcaseconv(buf, highc_htob, highc_htob, highc_htob);
        }
        pline(msgc_occstart, "You extract a strange sound from %s!",
              the(xname(instr)));

        /* Check if there was the Stronghold drawbridge near and if the tune
           conforms to what we're waiting for. */
        if (Is_stronghold(&u.uz)) {
            exercise(A_WIS, TRUE);      /* just for trying */
            if (!strcmp(buf, gamestate.castle_tune)) {
                /* Search for the drawbridge */
                for (y = youmonst.my - 1; y <= youmonst.my + 1; y++)
                    for (x = youmonst.mx - 1; x <= youmonst.mx + 1; x++)
                        if (isok(x, y))
                            if (find_drawbridge(&x, &y)) {
                                /* tune now fully known */
                                u.uevent.uheard_tune = 2;
                                if (level->locations[x][y].typ ==
                                    DRAWBRIDGE_DOWN)
                                    close_drawbridge(x, y);
                                else
                                    open_drawbridge(x, y);
                                return 1;
                            }
            } else if (canhear()) {
                if (u.uevent.uheard_tune < 1)
                    u.uevent.uheard_tune = 1;
                /* Okay, it wasn't the right tune, but perhaps we can give the
                   player some hints like in the Mastermind game */
                ok = FALSE;
                for (y = youmonst.my - 1; y <= youmonst.my + 1 && !ok; y++)
                    for (x = youmonst.mx - 1; x <= youmonst.mx + 1 && !ok; x++)
                        if (isok(x, y))
                            if (IS_DRAWBRIDGE(level->locations[x][y].typ) ||
                                is_drawbridge_wall(x, y) >= 0)
                                ok = TRUE;
                if (ok) {       /* There is a drawbridge near */
                    int tumblers, gears;
                    boolean matched[5];

                    tumblers = gears = 0;
                    for (x = 0; x < 5; x++)
                        matched[x] = FALSE;

                    for (x = 0; x < (int)strlen(buf); x++)
                        if (x < 5) {
                            if (buf[x] == gamestate.castle_tune[x]) {
                                gears++;
                                matched[x] = TRUE;
                            } else
                                for (y = 0; y < 5; y++)
                                    if (!matched[y] &&
                                        buf[x] == gamestate.castle_tune[y] &&
                                        buf[y] != gamestate.castle_tune[y]) {
                                        tumblers++;
                                        matched[y] = TRUE;
                                        break;
                                    }
                        }
                    if (tumblers)
                        if (gears)
                            You_hear(msgc_hint,
                                     "%d tumbler%s click and %d gear%s turn.",
                                     tumblers, plur(tumblers), gears,
                                     plur(gears));
                        else
                            You_hear(msgc_hint, "%d tumbler%s click.", tumblers,
                                     plur(tumblers));
                    else if (gears) {
                        You_hear(msgc_hint, "%d gear%s turn.", gears,
                                 plur(gears));
                        /* could only get `gears == 5' by playing five correct
                           notes followed by excess; otherwise, tune would have 
                           matched above */
                        if (gears == 5)
                            u.uevent.uheard_tune = 2;
                    }
                }
            }
        }
        return 1;
    } else
        return do_improvisation(instr, arg);
}
Пример #16
0
double G77_besyn_0 (const integer *n, real *x) {
    return yn (*n, *x);
}
Пример #17
0
int
study_book(struct obj *spellbook, const struct nh_cmd_arg *arg)
{
    int booktype = spellbook->otyp;
    boolean confused = (Confusion != 0);
    boolean too_hard = FALSE;

    if (u.uoccupation_progress[tos_book] && !confused &&
        spellbook == u.utracked[tos_book] &&
        /* handle the sequence: start reading, get interrupted, have book
           become erased somehow, resume reading it */
        booktype != SPE_BLANK_PAPER) {
        if (turnstate.continue_message)
            pline("You continue your efforts to memorize the spell.");
    } else {
        /* Restarting reading the book */

        /* KMH -- Simplified this code */
        if (booktype == SPE_BLANK_PAPER) {
            pline("This spellbook is all blank.");
            makeknown(booktype);
            return 1;
        }
        switch (objects[booktype].oc_level) {
        case 1:
        case 2:
            u.uoccupation_progress[tos_book] = -objects[booktype].oc_delay;
            break;
        case 3:
        case 4:
            u.uoccupation_progress[tos_book] =
                -(objects[booktype].oc_level - 1) * objects[booktype].oc_delay;
            break;
        case 5:
        case 6:
            u.uoccupation_progress[tos_book] =
                -objects[booktype].oc_level * objects[booktype].oc_delay;
            break;
        case 7:
            u.uoccupation_progress[tos_book] = -8 * objects[booktype].oc_delay;
            break;
        default:
            impossible("Unknown spellbook level %d, book %d;",
                       objects[booktype].oc_level, booktype);
            return 0;
        }

        /* Books are often wiser than their readers (Rus.) */
        spellbook->in_use = TRUE;
        if (!spellbook->blessed && spellbook->otyp != SPE_BOOK_OF_THE_DEAD) {
            if (spellbook->cursed) {
                too_hard = TRUE;
            } else {
                /* uncursed - chance to fail */
                int read_ability =
                    ACURR(A_INT) + 4 + u.ulevel / 2 -
                    2 * objects[booktype].oc_level +
                    ((ublindf && ublindf->otyp == LENSES) ? 2 : 0);
                /* only wizards know if a spell is too difficult */
                if (Role_if(PM_WIZARD) && read_ability < 20 && !confused) {
                    const char *qbuf;

                    qbuf = msgprintf("This spellbook is %sdifficult to "
                                     "comprehend. Continue?",
                                     (read_ability < 12 ? "very " : ""));
                    if (yn(qbuf) != 'y') {
                        spellbook->in_use = FALSE;
                        return 1;
                    }
                }
                /* it's up to random luck now */
                if (rnd(20) > read_ability) {
                    too_hard = TRUE;
                }
            }
        }

        if (too_hard) {
            boolean gone = cursed_book(spellbook);

            helpless(-u.uoccupation_progress[tos_book], hr_paralyzed,
                     "frozen by a spellbook", NULL);
            u.uoccupation_progress[tos_book] = 0;
            if (gone || !rn2(3)) {
                if (!gone)
                    pline("The spellbook crumbles to dust!");
                if (!objects[spellbook->otyp].oc_name_known &&
                    !objects[spellbook->otyp].oc_uname)
                    docall(spellbook);
                useup(spellbook);
            } else
                spellbook->in_use = FALSE;
            return 1;
        } else if (confused) {
            if (!confused_book(spellbook)) {
                spellbook->in_use = FALSE;
            }
            helpless(-u.uoccupation_progress[tos_book], hr_busy,
                     "absorbed in a spellbook",
                     "You're finally able to put the book down.");
            u.uoccupation_progress[tos_book] = 0;
            u.utracked[tos_book] = 0;
            return 1;
        }
        spellbook->in_use = FALSE;

        pline("You begin to %s the runes.",
              spellbook->otyp == SPE_BOOK_OF_THE_DEAD ? "recite" : "memorize");
    }

    u.utracked[tos_book] = spellbook;

    one_occupation_turn(learn, "studying", occ_book);

    return 1;
}
Пример #18
0
void test_fp_and_80x87_math( void )
{
    double      dnum;
    int         inum;
#ifdef __FPI__
    unsigned    fp_status, fp_control, fp_mask, origbits, bits;
#endif

    printf( "Testing other floating point " );
#ifdef __FPI__
    printf( "and 80x87 specific " );
#endif
    printf( "functions...\n" );
    VERIFY( CompDbl( j0( 2.387 ), 0.009288 ) );
    VERIFY( CompDbl( j1( 2.387 ), 0.522941 ) );
    VERIFY( CompDbl( jn( 2, 2.387 ), 0.428870 ) );
    VERIFY( CompDbl( y0( 2.387 ), 0.511681 ) );
    VERIFY( CompDbl( y1( 2.387 ), 0.094374 ) );
    VERIFY( CompDbl( yn( 2, 2.387 ), -0.432608 ) );
    VERIFY( ceil( 1.0001 ) == 2.0 );
    VERIFY( ceil( -1.0001 ) == -1.0 );
    VERIFY( floor( 1.0001 ) == 1.0 );
    VERIFY( floor( -1.0001 ) == -2.0 );
    VERIFY( CompDbl( exp( 1.0 ), E ) );
    VERIFY( CompDbl( exp( 3.0 ), E * E * E ) );
    VERIFY( exp( 0.0 ) == 1.0 );
    VERIFY( fabs( -1.5 ) == 1.5 );
    VERIFY( fabs( 2.5 ) == 2.5 );
    VERIFY( fabs( 0.0 ) == 0.0 );
    VERIFY( fmod( 2.5, 0.5 ) == 0.0 );
    VERIFY( fmod( 4.5, 2.0 ) == 0.5 );
    VERIFY( fmod( -4.5, 2.0 ) == -0.5 );
    VERIFY( fmod( -7.5, -2.0 ) == -1.5 );
    dnum = frexp( 65535.0, &inum );
    VERIFY( inum == 16 );
    VERIFY( CompDbl( ldexp( dnum, inum ), 65535.0 ) );
    while( inum-- > 0 ) dnum *= 2;
    VERIFY( CompDbl( dnum, 65535.0 ) );
    VERIFY( CompDbl( log( E ), 1.0 ) );
    VERIFY( CompDbl( log( 1.0 ), 0.0 ) );
    VERIFY( CompDbl( log( 1.0 / E ), -1.0 ) );
    VERIFY( CompDbl( log10( 10.0 ), 1.0 ) );
    VERIFY( CompDbl( log10( 1 ), 0.0 ) );
    VERIFY( CompDbl( log10( 0.1 ), -1.0 ) );
#ifdef __WATCOMC__      /* Not in Microsoft libs. */
    VERIFY( CompDbl( log2( 65536.0 ), 16.0 ) );
    VERIFY( CompDbl( log2( 1 ), 0.0 ) );
    VERIFY( CompDbl( log2( 0.25 ), -2.0 ) );
#endif
    VERIFY( CompDbl( sqrt( 99980001.0 ), 9999.0 ) );
    dnum = 1.0/DBL_MIN;
    VERIFY( CompDbl( 1.0 / dnum, DBL_MIN ) );
    VERIFY( CompDbl( modf( PI, &dnum ), PI - 3.0 ) );
    VERIFY( dnum == 3.0 );
    VERIFY( CompDbl( modf( -PI, &dnum ) , - PI + 3.0 ) );
    VERIFY( dnum == -3.0 );
    VERIFY( pow( 1.0, 123456789.0 ) == 1.0 );
    VERIFY( pow( 2.0, 16.0 ) == 65536.0 );
    VERIFY( CompDbl( pow( E, log(1234.0) ), 1234.0 ) );
#ifdef __FPI__
    VERIFY( sqrt( -1 ) == 1 );
    // Now my_matherrno should == DOMAIN after calling sqrt( -1 )
    // If not, matherr() fails
    VERIFY( my_matherrno == DOMAIN );
    my_matherrno = 0;   // reset
    VERIFY( sqrt( 0 ) == 0 );
    VERIFY( my_matherrno == 0 );
    _fpreset();
    fp_status = _clear87();
    VERIFY( fp_status == 0 );
    //
    fp_status = _status87();
    VERIFY( fp_status == 0 );
    //
    _fpreset();
    fp_control = _control87( 0, 0 );
    bits = fp_control & MCW_IC;
    bits = (bits == IC_AFFINE) ? IC_PROJECTIVE : IC_AFFINE;
    fp_control = _control87( bits, MCW_IC );
    VERIFY( (fp_control & MCW_IC) ==  bits );
    bits = (bits == IC_AFFINE) ? IC_PROJECTIVE : IC_AFFINE;
    fp_control = _control87( bits, MCW_IC );
    VERIFY( (fp_control & MCW_IC) ==  bits );
    //
    fp_control = _control87( 0, 0 );
    origbits = fp_control & MCW_RC;
    bits = (origbits == RC_NEAR) ? RC_CHOP : RC_NEAR;
    fp_control = _control87( bits, MCW_RC );
    VERIFY( (fp_control & MCW_RC) ==  bits );
    fp_control = _control87( origbits, MCW_RC );
    VERIFY( (fp_control & MCW_RC) ==  origbits );
    //
    _fpreset();
    fp_control = 0;
    fp_mask = _EM_INEXACT;
    signal( SIGFPE, (void (*)(int))my_handler );
    (void)_control87( fp_control, fp_mask );
    q = a / b;
    VERIFY( sig_count > 0 );
    fp_control = _EM_INEXACT;
    (void)_control87( fp_control, fp_mask );
    sig_count = 0;
    q = a / b;
    VERIFY( sig_count == 0 );
    signal( SIGFPE, SIG_DFL );
#endif
}
Пример #19
0
int main(int argc, char *argv[])
{
  double x = 0.0;
  if (argv) x = yn((double) argc, (double) argc);
  return 0;
}
Пример #20
0
float
ynf (int n, float x)
{
  return (float) yn (n, (double) x);
}
Пример #21
0
double besyn_ (const integer *n, real *x) {
    return yn (*n, *x);
}
Пример #22
0
__device__ void double_precision_math_functions() {
    int iX;
    double fX, fY;

    acos(1.0);
    acosh(1.0);
    asin(0.0);
    asinh(0.0);
    atan(0.0);
    atan2(0.0, 1.0);
    atanh(0.0);
    cbrt(0.0);
    ceil(0.0);
    copysign(1.0, -2.0);
    cos(0.0);
    cosh(0.0);
    cospi(0.0);
    cyl_bessel_i0(0.0);
    cyl_bessel_i1(0.0);
    erf(0.0);
    erfc(0.0);
    erfcinv(2.0);
    erfcx(0.0);
    erfinv(1.0);
    exp(0.0);
    exp10(0.0);
    exp2(0.0);
    expm1(0.0);
    fabs(1.0);
    fdim(1.0, 0.0);
    floor(0.0);
    fma(1.0, 2.0, 3.0);
    fmax(0.0, 0.0);
    fmin(0.0, 0.0);
    fmod(0.0, 1.0);
    frexp(0.0, &iX);
    hypot(1.0, 0.0);
    ilogb(1.0);
    isfinite(0.0);
    isinf(0.0);
    isnan(0.0);
    j0(0.0);
    j1(0.0);
    jn(-1.0, 1.0);
    ldexp(0.0, 0);
    lgamma(1.0);
    llrint(0.0);
    llround(0.0);
    log(1.0);
    log10(1.0);
    log1p(-1.0);
    log2(1.0);
    logb(1.0);
    lrint(0.0);
    lround(0.0);
    modf(0.0, &fX);
    nan("1");
    nearbyint(0.0);
    nextafter(0.0, 0.0);
    fX = 1.0;
    norm(1, &fX);
    norm3d(1.0, 0.0, 0.0);
    norm4d(1.0, 0.0, 0.0, 0.0);
    normcdf(0.0);
    normcdfinv(1.0);
    pow(1.0, 0.0);
    rcbrt(1.0);
    remainder(2.0, 1.0);
    remquo(1.0, 2.0, &iX);
    rhypot(0.0, 1.0);
    rint(1.0);
    fX = 1.0;
    rnorm(1, &fX);
    rnorm3d(0.0, 0.0, 1.0);
    rnorm4d(0.0, 0.0, 0.0, 1.0);
    round(0.0);
    rsqrt(1.0);
    scalbln(0.0, 1);
    scalbn(0.0, 1);
    signbit(1.0);
    sin(0.0);
    sincos(0.0, &fX, &fY);
    sincospi(0.0, &fX, &fY);
    sinh(0.0);
    sinpi(0.0);
    sqrt(0.0);
    tan(0.0);
    tanh(0.0);
    tgamma(2.0);
    trunc(0.0);
    y0(1.0);
    y1(1.0);
    yn(1, 1.0);
}
Пример #23
0
int
dosave()
{
#ifdef KEEP_SAVE
	/*WAC for reloading*/
	register int fd;
#endif

	clear_nhwindow(WIN_MESSAGE);
	if(yn("Really save?") == 'n') {
		clear_nhwindow(WIN_MESSAGE);
		if(multi > 0) nomul(0);
	} else {
		clear_nhwindow(WIN_MESSAGE);
		pline("Saving...");
#if defined(UNIX) || defined(VMS) || defined(__EMX__)
		program_state.done_hup = 0;
#endif
#ifdef KEEP_SAVE
                saverestore = FALSE;
                if (flags.keep_savefile)
                        if(yn("Really quit?") == 'n') saverestore = TRUE;
                if(dosave0() && !saverestore) {
#else
		if(dosave0()) {
#endif
			program_state.something_worth_saving = 0;
			u.uhp = -1;		/* universal game's over indicator */
			/* make sure they see the Saving message */
			display_nhwindow(WIN_MESSAGE, TRUE);
			exit_nhwindows("Be seeing you...");
			terminate(EXIT_SUCCESS);
	}
/*WAC redraw later
		else (void)doredraw();*/
	}
#ifdef KEEP_SAVE
	if (saverestore) {
/*WAC pulled this from pcmain.c - restore game from the file just saved*/
		fd = create_levelfile(0);
		if (fd < 0) {
			raw_print("Cannot create lock file");
		} else {
			hackpid = 1;
			write(fd, (genericptr_t) &hackpid, sizeof(hackpid));
			close(fd);
		}
#ifdef MFLOPPY
		level_info[0].where = ACTIVE;
#endif

		fd = restore_saved_game();
		if (fd >= 0) dorecover(fd);
		check_special_room(FALSE);
		flags.move = 0;
/*WAC correct these after restore*/
		if(flags.moonphase == FULL_MOON)
			change_luck(1);         
		if(flags.friday13)
			change_luck(-1);
		if(iflags.window_inited)
			clear_nhwindow(WIN_MESSAGE);
	}
	saverestore = FALSE;
#endif
	(void)doredraw();
	return 0;
}


#if defined(UNIX) || defined(VMS) || defined (__EMX__) || defined(WIN32)
/*ARGSUSED*/
void
hangup(sig_unused)  /* called as signal() handler, so sent at least one arg */
int sig_unused;
{
# ifdef NOSAVEONHANGUP
	(void) signal(SIGINT, SIG_IGN);
	clearlocks();
#  ifndef VMS
	terminate(EXIT_FAILURE);
#  endif
# else	/* SAVEONHANGUP */
	if (!program_state.done_hup++) {
	    if (program_state.something_worth_saving)
		(void) dosave0();
#  ifdef VMS
	    /* don't call exit when already within an exit handler;
	       that would cancel any other pending user-mode handlers */
	    if (!program_state.exiting)
#  endif
	    {
		clearlocks();
		terminate(EXIT_FAILURE);
	    }
	}
# endif
	return;
}
#endif

/* returns 1 if save successful */
int
dosave0()
{
	const char *fq_save;
	register int fd, ofd;
	xchar ltmp;
	d_level uz_save;
	char whynot[BUFSZ];

	if (!SAVEF[0])
		return 0;
	fq_save = fqname(SAVEF, SAVEPREFIX, 1);	/* level files take 0 */

#if defined(UNIX) || defined(VMS)
	(void) signal(SIGHUP, SIG_IGN);
#endif
#ifndef NO_SIGNAL
	(void) signal(SIGINT, SIG_IGN);
#endif

#if defined(MICRO) && defined(MFLOPPY)
	if (!saveDiskPrompt(0)) return 0;
#endif

	HUP if (iflags.window_inited) {
	    uncompress_area(fq_save, SAVEF);
	    fd = open_savefile();
	    if (fd > 0) {
		(void) close(fd);
		clear_nhwindow(WIN_MESSAGE);
		There("seems to be an old save file.");
		if (yn("Overwrite the old file?") == 'n') {
		    compress_area(fq_save, SAVEF);
#ifdef KEEP_SAVE
/*WAC don't restore if you didn't save*/
			saverestore = FALSE;
#endif
		    return 0;
		}
	    }
	}

	HUP mark_synch();	/* flush any buffered screen output */

	fd = create_savefile();
	if(fd < 0) {
		HUP pline("Cannot open save file.");
		(void) delete_savefile();	/* ab@unido */
		return(0);
	}

	vision_recalc(2);	/* shut down vision to prevent problems
				   in the event of an impossible() call */
	
	/* undo date-dependent luck adjustments made at startup time */
	if(flags.moonphase == FULL_MOON)	/* ut-sally!fletcher */
		change_luck(-1);		/* and unido!ab */
	if(flags.friday13)
		change_luck(1);
	if(iflags.window_inited)
	    HUP clear_nhwindow(WIN_MESSAGE);

#if defined(MICRO) && defined(TTY_GRAPHICS)
	if (!strncmpi("tty", windowprocs.name, 3)) {
	dotcnt = 0;
	dotrow = 2;
	curs(WIN_MAP, 1, 1);
	  putstr(WIN_MAP, 0, "Saving:");
	}
#endif
#ifdef MFLOPPY
	/* make sure there is enough disk space */
	if (iflags.checkspace) {
	    long fds, needed;

	    savelev(fd, ledger_no(&u.uz), COUNT_SAVE);
	    savegamestate(fd, COUNT_SAVE);
	    needed = bytes_counted;

	    for (ltmp = 1; ltmp <= maxledgerno(); ltmp++)
		if (ltmp != ledger_no(&u.uz) && level_info[ltmp].where)
		    needed += level_info[ltmp].size + (sizeof ltmp);
	    fds = freediskspace(fq_save);
	    if (needed > fds) {
		HUP {
		    There("is insufficient space on SAVE disk.");
		    pline("Require %ld bytes but only have %ld.", needed, fds);
		}
		flushout();
		(void) close(fd);
		(void) delete_savefile();
		return 0;
	    }

	    co_false();
	}
Пример #24
0
/* TODO: Perhaps work out some way to let controlled teleport in on a
   CMD_ARG_POS, but there are too many codeflow possibilities involved to make
   that easy. For now, if dotele turns into the spell, we copy the argument on
   to the spell-handling function (which currently ignores it), but the other
   possible codepaths just lose it. */
int
dotele(const struct nh_cmd_arg *arg)
{
    struct trap *trap;

    trap = t_at(level, u.ux, u.uy);
    if (trap && (!trap->tseen || trap->ttyp != TELEP_TRAP))
        trap = 0;

    if (trap) {
        if (trap->once) {
            pline("This is a vault teleport, usable once only.");
            if (yn("Jump in?") == 'n')
                trap = 0;
            else {
                deltrap(level, trap);
                newsym(u.ux, u.uy);
            }
        }
        if (trap)
            pline("You %s onto the teleportation trap.",
                  locomotion(youmonst.data, "jump"));
    }
    if (!trap) {
        boolean castit = FALSE;
        int sp_no = 0, energy = 0;

        if (!supernatural_ability_available(SPID_RLOC)) {
            /* Try to use teleport away spell. */
            if (objects[SPE_TELEPORT_AWAY].oc_name_known && !Confusion)
                for (sp_no = 0; sp_no < MAXSPELL; sp_no++)
                    if (spl_book[sp_no].sp_id == SPE_TELEPORT_AWAY) {
                        castit = TRUE;
                        break;
                    }
            if (!castit) {
                if (!Teleportation)
                    pline("You don't know that spell.");
                else
                    pline("You are not able to teleport at will.");
                return 0;
            }
        }

        if (u.uhunger <= 100 || ACURR(A_STR) < 6) {
            pline("You lack the strength %s.",
                  castit ? "for a teleport spell" : "to teleport");
            return 1;
        }

        energy = objects[SPE_TELEPORT_AWAY].oc_level * 7 / 2 - 2;
        if (u.uen <= energy) {
            pline("You lack the energy %s.",
                  castit ? "for a teleport spell" : "to teleport");
            return 1;
        }

        if (check_capacity("Your concentration falters from carrying so much."))
            return 1;

        if (castit) {
            exercise(A_WIS, TRUE);
            if (spelleffects(sp_no, TRUE, arg))
                return 1;
            else
                return 0;
        } else
            u.uen -= energy;
    }

    if (trap && trap->once) {
        if (next_to_u())
            vault_tele();
        else
            pline("You shudder for a moment.");
    } else if (!tele_impl(FALSE, TRUE))
        return 0;

    next_to_u();

    if (!trap)
        morehungry(100);
    return 1;
}
Пример #25
0
int dogaze(void)
{
	struct monst *mtmp;
	int looked = 0;
	char qbuf[QBUFSZ];
	int i;
	uchar adtyp = 0;

	for (i = 0; i < NATTK; i++) {
	    if (youmonst.data->mattk[i].aatyp == AT_GAZE) {
		adtyp = youmonst.data->mattk[i].adtyp;
		break;
	    }
	}
	if (adtyp != AD_CONF && adtyp != AD_FIRE) {
	    impossible("gaze attack %d?", adtyp);
	    return 0;
	}


	if (Blind) {
	    pline("You can't see anything to gaze at.");
	    return 0;
	}
	if (u.uen < 15) {
	    pline("You lack the energy to use your special gaze!");
	    return 0;
	}
	u.uen -= 15;
	iflags.botl = 1;

	for (mtmp = level->monlist; mtmp; mtmp = mtmp->nmon) {
	    if (DEADMONSTER(mtmp)) continue;
	    if (canseemon(mtmp) && couldsee(mtmp->mx, mtmp->my)) {
		looked++;
		if (Invis && !perceives(mtmp->data))
		    pline("%s seems not to notice your gaze.", Monnam(mtmp));
		else if (mtmp->minvis && !See_invisible)
		    pline("You can't see where to gaze at %s.", Monnam(mtmp));
		else if (mtmp->m_ap_type == M_AP_FURNITURE
			|| mtmp->m_ap_type == M_AP_OBJECT) {
		    looked--;
		    continue;
		} else if (flags.safe_dog && !Confusion && !Hallucination
		  && mtmp->mtame) {
		    pline("You avoid gazing at %s.", y_monnam(mtmp));
		} else {
		    if (flags.confirm && mtmp->mpeaceful && !Confusion
							&& !Hallucination) {
			sprintf(qbuf, "Really %s %s?",
			    (adtyp == AD_CONF) ? "confuse" : "attack",
			    mon_nam(mtmp));
			if (yn(qbuf) != 'y') continue;
			setmangry(mtmp);
		    }
		    if (!mtmp->mcanmove || mtmp->mstun || mtmp->msleeping ||
				    !mtmp->mcansee || !haseyes(mtmp->data)) {
			looked--;
			continue;
		    }
		    /* No reflection check for consistency with when a monster
		     * gazes at *you*--only medusa gaze gets reflected then.
		     */
		    if (adtyp == AD_CONF) {
			if (!mtmp->mconf)
			    pline("Your gaze confuses %s!", mon_nam(mtmp));
			else
			    pline("%s is getting more and more confused.",
							Monnam(mtmp));
			mtmp->mconf = 1;
		    } else if (adtyp == AD_FIRE) {
			int dmg = dice(2,6);
			pline("You attack %s with a fiery gaze!", mon_nam(mtmp));
			if (resists_fire(mtmp)) {
			    pline("The fire doesn't burn %s!", mon_nam(mtmp));
			    dmg = 0;
			}
			if ((int) u.ulevel > rn2(20))
			    destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE);
			if ((int) u.ulevel > rn2(20))
			    destroy_mitem(mtmp, POTION_CLASS, AD_FIRE);
			if ((int) u.ulevel > rn2(25))
			    destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE);
			if (dmg && !DEADMONSTER(mtmp)) mtmp->mhp -= dmg;
			if (mtmp->mhp <= 0) killed(mtmp);
		    }
		    /* For consistency with passive() in uhitm.c, this only
		     * affects you if the monster is still alive.
		     */
		    if (!DEADMONSTER(mtmp) &&
			  (mtmp->data==&mons[PM_FLOATING_EYE]) && !mtmp->mcan) {
			if (!Free_action) {
			    pline("You are frozen by %s gaze!",
					     s_suffix(mon_nam(mtmp)));
			    nomul((u.ulevel > 6 || rn2(4)) ?
				    -dice((int)mtmp->m_lev+1,
					    (int)mtmp->data->mattk[0].damd)
				    : -200, "frozen by a monster's gaze");
			    return 1;
			} else
			    pline("You stiffen momentarily under %s gaze.",
				    s_suffix(mon_nam(mtmp)));
		    }
		    /* Technically this one shouldn't affect you at all because
		     * the Medusa gaze is an active monster attack that only
		     * works on the monster's turn, but for it to *not* have an
		     * effect would be too weird.
		     */
		    if (!DEADMONSTER(mtmp) &&
			    (mtmp->data == &mons[PM_MEDUSA]) && !mtmp->mcan) {
			pline(
			 "Gazing at the awake %s is not a very good idea.",
			    l_monnam(mtmp));
			/* as if gazing at a sleeping anything is fruitful... */
			pline("You turn to stone...");
			killer_format = KILLED_BY;
			killer = "deliberately meeting Medusa's gaze";
			done(STONING);
		    }
		}
	    }
	}
	if (!looked) pline("You gaze at no place in particular.");
	return 1;
}
Пример #26
0
ULONG MathFunc(CHAR *name, ULONG numargs, RXSTRING args[],
                        CHAR *queuename, RXSTRING *retstr)
{
	double x, y, result;
	int i, fn_id = -1;

#ifdef ENABLE_CACHE
   if (RxMathFncCache.id >= 0)
      fn_id = cache_func(name, numargs);

   if (fn_id < 0)
   {
   	fn_id = resolve_func(name, numargs);
	   if (fn_id < 0)           
		   return INVALID_ROUTINE;
   }
#else
  	fn_id = resolve_func(name, numargs);
   if (fn_id < 0)           
	   return INVALID_ROUTINE;
#endif

	x = atof(args[0].strptr);
	if (numargs > 1L)
	{
		y = atof(args[1].strptr);
		i = atoi(args[1].strptr);
	}

	switch (fn_id)
	{
	case fn_acos:
		result = acos(x);
		break;
	case fn_asin: 
		result = asin(x);
		break;
	case fn_atan: 
		result = atan(x);
		break;
	case fn_atan2:
		result = atan2(x, y);
		break;
	case fn_ceil: 
		result = ceil(x);
		break;
	case fn_cos:  
		result = cos(x);
		break;
	case fn_cosh: 
		result = cosh(x);
		break;
	case fn_exp:  
		result = exp(x);
		break;
	case fn_fabs: 
		result = fabs(x);
		break;
	case fn_floor:
		result = floor(x);
		break;
	case fn_fmod: 
		result = fmod(x, y);
		break;
	case fn_frexp:
		result = frexp(x, &i);
		break;
	case fn_ldexp:
		result = ldexp(x, i);
		break;
	case fn_log:  
		result = log(x);
		break;
	case fn_log10:
		result = log10(x);
		break;
	case fn_modf: 
		result = modf(x, &y);
		break;
	case fn_pow:  
		result = pow(x, y);
		break;
	case fn_sin:  
		result = sin(x);
		break;
	case fn_sinh: 
		result = sinh(x);
		break;
	case fn_sqrt: 
		result = sqrt(x);
		break;
	case fn_tan: 
		result = tan(x);
		break;
	case fn_tanh:
		result = tanh(x);
		break;
#ifdef __IBMC__
	case fn_erf:
      result = erf( x );
		break;
	case fn_erfc:  
      result = erfc( x );
		break;
	case fn_gamma: 
      result = gamma( x );
		break;
#endif
	case fn_hypot: 
      result = hypot( x, y );
		break;
	case fn_j0:    
      result = j0( x );
		break;
	case fn_j1:    
      result = j1( x );
		break;
	case fn_jn:    
      result = jn( i, x );
		break;
	case fn_y0:    
      result = y0( x );
		break;
	case fn_y1:    
      result = y1( x );
		break;
	case fn_yn:    
      result = yn( i, x );
		break;
	case fn_pi:    
      result = 3.1415926575;
		break;
   default:
	   return INVALID_ROUTINE;
	}

	switch (fn_id)
	{
	case fn_frexp:
		sprintf(retstr->strptr, "%lf %i", result, i);
		break;
	case fn_modf: 
		sprintf(retstr->strptr, "%lf %lf", result, y);
		break;
	default:
		sprintf(retstr->strptr, "%lf", result);
		break;
	}

	retstr->strlength = strlen(retstr->strptr);
	return VALID_ROUTINE;
}
Пример #27
0
void
domath  (void)
{
#ifndef NO_DOUBLE
  double f1;
  double f2;

  int i1;

  f1 = acos (0.0);
  fprintf( stdout, "acos           : %f\n", f1);

  f1 = acosh (0.0);
  fprintf( stdout, "acosh          : %f\n", f1);

  f1 = asin (1.0);
  fprintf( stdout, "asin           : %f\n", f1);

  f1 = asinh (1.0);
  fprintf( stdout, "asinh          : %f\n", f1);

  f1 = atan (M_PI_4);
  fprintf( stdout, "atan           : %f\n", f1);

  f1 = atan2 (2.3, 2.3);
  fprintf( stdout, "atan2          : %f\n", f1);

  f1 = atanh (1.0);
  fprintf( stdout, "atanh          : %f\n", f1);

  f1 = cbrt (27.0);
  fprintf( stdout, "cbrt           : %f\n", f1);

  f1 = ceil (3.5);
  fprintf( stdout, "ceil           : %f\n", f1);

  f1 = copysign (3.5, -2.5);
  fprintf( stdout, "copysign       : %f\n", f1);

  f1 = cos (M_PI_2);
  fprintf( stdout, "cos            : %f\n", f1);

  f1 = cosh (M_PI_2);
  fprintf( stdout, "cosh           : %f\n", f1);

  f1 = erf (42.0);
  fprintf( stdout, "erf            : %f\n", f1);

  f1 = erfc (42.0);
  fprintf( stdout, "erfc           : %f\n", f1);

  f1 = exp (0.42);
  fprintf( stdout, "exp            : %f\n", f1);

  f1 = exp2 (0.42);
  fprintf( stdout, "exp2           : %f\n", f1);

  f1 = expm1 (0.00042);
  fprintf( stdout, "expm1          : %f\n", f1);

  f1 = fabs (-1.123);
  fprintf( stdout, "fabs           : %f\n", f1);

  f1 = fdim (1.123, 2.123);
  fprintf( stdout, "fdim           : %f\n", f1);

  f1 = floor (0.5);
  fprintf( stdout, "floor          : %f\n", f1);
  f1 = floor (-0.5);
  fprintf( stdout, "floor          : %f\n", f1);

  f1 = fma (2.1, 2.2, 3.01);
  fprintf( stdout, "fma            : %f\n", f1);

  f1 = fmax (-0.42, 0.42);
  fprintf( stdout, "fmax           : %f\n", f1);

  f1 = fmin (-0.42, 0.42);
  fprintf( stdout, "fmin           : %f\n", f1);

  f1 = fmod (42.0, 3.0);
  fprintf( stdout, "fmod           : %f\n", f1);

  /* no type-specific variant */
  i1 = fpclassify(1.0);
  fprintf( stdout, "fpclassify     : %d\n", i1);

  f1 = frexp (42.0, &i1);
  fprintf( stdout, "frexp          : %f\n", f1);

  f1 = hypot (42.0, 42.0);
  fprintf( stdout, "hypot          : %f\n", f1);

  i1 = ilogb (42.0);
  fprintf( stdout, "ilogb          : %d\n", i1);

  /* no type-specific variant */
  i1 = isfinite(3.0);
  fprintf( stdout, "isfinite       : %d\n", i1);

  /* no type-specific variant */
  i1 = isgreater(3.0, 3.1);
  fprintf( stdout, "isgreater      : %d\n", i1);

  /* no type-specific variant */
  i1 = isgreaterequal(3.0, 3.1);
  fprintf( stdout, "isgreaterequal : %d\n", i1);

  /* no type-specific variant */
  i1 = isinf(3.0);
  fprintf( stdout, "isinf          : %d\n", i1);

  /* no type-specific variant */
  i1 = isless(3.0, 3.1);
  fprintf( stdout, "isless         : %d\n", i1);

  /* no type-specific variant */
  i1 = islessequal(3.0, 3.1);
  fprintf( stdout, "islessequal    : %d\n", i1);

  /* no type-specific variant */
  i1 = islessgreater(3.0, 3.1);
  fprintf( stdout, "islessgreater  : %d\n", i1);

  /* no type-specific variant */
  i1 = isnan(0.0);
  fprintf( stdout, "isnan          : %d\n", i1);

  /* no type-specific variant */
  i1 = isnormal(3.0);
  fprintf( stdout, "isnormal       : %d\n", i1);

  /* no type-specific variant */
  f1 = isunordered(1.0, 2.0);
  fprintf( stdout, "isunordered    : %d\n", i1);

  f1 = j0 (1.2);
  fprintf( stdout, "j0             : %f\n", f1);

  f1 = j1 (1.2);
  fprintf( stdout, "j1             : %f\n", f1);

  f1 = jn (2,1.2);
  fprintf( stdout, "jn             : %f\n", f1);

  f1 = ldexp (1.2,3);
  fprintf( stdout, "ldexp          : %f\n", f1);

  f1 = lgamma (42.0);
  fprintf( stdout, "lgamma         : %f\n", f1);

  f1 = llrint (-0.5);
  fprintf( stdout, "llrint         : %f\n", f1);
  f1 = llrint (0.5);
  fprintf( stdout, "llrint         : %f\n", f1);

  f1 = llround (-0.5);
  fprintf( stdout, "lround         : %f\n", f1);
  f1 = llround (0.5);
  fprintf( stdout, "lround         : %f\n", f1);

  f1 = log (42.0);
  fprintf( stdout, "log            : %f\n", f1);

  f1 = log10 (42.0);
  fprintf( stdout, "log10          : %f\n", f1);

  f1 = log1p (42.0);
  fprintf( stdout, "log1p          : %f\n", f1);

  f1 = log2 (42.0);
  fprintf( stdout, "log2           : %f\n", f1);

  f1 = logb (42.0);
  fprintf( stdout, "logb           : %f\n", f1);

  f1 = lrint (-0.5);
  fprintf( stdout, "lrint          : %f\n", f1);
  f1 = lrint (0.5);
  fprintf( stdout, "lrint          : %f\n", f1);

  f1 = lround (-0.5);
  fprintf( stdout, "lround         : %f\n", f1);
  f1 = lround (0.5);
  fprintf( stdout, "lround         : %f\n", f1);

  f1 = modf (42.0,&f2);
  fprintf( stdout, "lmodf          : %f\n", f1);

  f1 = nan ("");
  fprintf( stdout, "nan            : %f\n", f1);

  f1 = nearbyint (1.5);
  fprintf( stdout, "nearbyint      : %f\n", f1);

  f1 = nextafter (1.5,2.0);
  fprintf( stdout, "nextafter      : %f\n", f1);

  f1 = pow (3.01, 2.0);
  fprintf( stdout, "pow            : %f\n", f1);

  f1 = remainder (3.01,2.0);
  fprintf( stdout, "remainder      : %f\n", f1);

  f1 = remquo (29.0,3.0,&i1);
  fprintf( stdout, "remquo         : %f\n", f1);

  f1 = rint (0.5);
  fprintf( stdout, "rint           : %f\n", f1);
  f1 = rint (-0.5);
  fprintf( stdout, "rint           : %f\n", f1);

  f1 = round (0.5);
  fprintf( stdout, "round          : %f\n", f1);
  f1 = round (-0.5);
  fprintf( stdout, "round          : %f\n", f1);

  f1 = scalbln (1.2,3);
  fprintf( stdout, "scalbln        : %f\n", f1);

  f1 = scalbn (1.2,3);
  fprintf( stdout, "scalbn         : %f\n", f1);

  /* no type-specific variant */
  i1 = signbit(1.0);
  fprintf( stdout, "signbit        : %i\n", i1);

  f1 = sin (M_PI_4);
  fprintf( stdout, "sin            : %f\n", f1);

  f1 = sinh (M_PI_4);
  fprintf( stdout, "sinh           : %f\n", f1);

  f1 = sqrt (9.0);
  fprintf( stdout, "sqrt           : %f\n", f1);

  f1 = tan (M_PI_4);
  fprintf( stdout, "tan            : %f\n", f1);

  f1 = tanh (M_PI_4);
  fprintf( stdout, "tanh           : %f\n", f1);

  f1 = tgamma (2.1);
  fprintf( stdout, "tgamma         : %f\n", f1);

  f1 = trunc (3.5);
  fprintf( stdout, "trunc          : %f\n", f1);

  f1 = y0 (1.2);
  fprintf( stdout, "y0             : %f\n", f1);

  f1 = y1 (1.2);
  fprintf( stdout, "y1             : %f\n", f1);

  f1 = yn (3,1.2);
  fprintf( stdout, "yn             : %f\n", f1);
#endif
}
Пример #28
0
TEST(math, yn) {
  ASSERT_FLOAT_EQ(-HUGE_VAL, yn(4, 0.0));
  ASSERT_FLOAT_EQ(-33.278423, yn(4, 1.0));
}
Пример #29
0
int
doconsult(struct monst *oracl)
{
    int umoney = money_cnt(invent);
    int u_pay, minor_cost = 50, major_cost = 500 + 50 * u.ulevel;
    int add_xpts;
    char qbuf[QBUFSZ];

    multi = 0;

    if (!oracl) {
        pline("There is no one here to consult.");
        return 0;
    } else if (!oracl->mpeaceful) {
        pline("%s is in no mood for consultations.", Monnam(oracl));
        return 0;
    } else if (!umoney) {
        pline("You have no money.");
        return 0;
    }

    sprintf(qbuf, "\"Wilt thou settle for a minor consultation?\" (%d %s)",
            minor_cost, currency(minor_cost));
    switch (ynq(qbuf)) {
    default:
    case 'q':
        return 0;
    case 'y':
        if (umoney < minor_cost) {
            pline("You don't even have enough money for that!");
            return 0;
        }
        u_pay = minor_cost;
        break;
    case 'n':
        if (umoney <= minor_cost ||     /* don't even ask */
            (oracle_cnt == 1 || oracle_flg < 0))
            return 0;
        sprintf(qbuf, "\"Then dost thou desire a major one?\" (%d %s)",
                major_cost, currency(major_cost));
        if (yn(qbuf) != 'y')
            return 0;
        u_pay = (umoney < major_cost ? umoney : major_cost);

        break;
    }

    money2mon(oracl, u_pay);
    iflags.botl = 1;
    add_xpts = 0;       /* first oracle of each type gives experience points */
    if (u_pay == minor_cost) {
        outrumor(1, BY_ORACLE);
        if (!u.uevent.minor_oracle)
            add_xpts = u_pay / (u.uevent.major_oracle ? 25 : 10);
        /* 5 pts if very 1st, or 2 pts if major already done */
        u.uevent.minor_oracle = TRUE;
    } else {
        boolean cheapskate = u_pay < major_cost;

        outoracle(cheapskate, TRUE);
        if (!cheapskate && !u.uevent.major_oracle)
            add_xpts = u_pay / (u.uevent.minor_oracle ? 25 : 10);
        /* ~100 pts if very 1st, ~40 pts if minor already done */
        u.uevent.major_oracle = TRUE;
        historic_event(FALSE, "received advice from The Oracle.");
        exercise(A_WIS, !cheapskate);
    }
    if (add_xpts) {
        more_experienced(add_xpts, u_pay / 50);
        newexplevel();
    }
    return 1;
}
Пример #30
0
int
doconsult(struct monst *oracl)
{
    int umoney = money_cnt(invent);
    int u_pay, minor_cost = 50, major_cost = 500 + 50 * u.ulevel;
    int add_xpts;
    const char *qbuf;

    /* TODO: Do we want this? The purpose seems to be specifically to prevent
       repeating an Oracle donation. */
    action_completed();

    if (!oracl) {
        pline("There is no one here to consult.");
        return 0;
    } else if (!oracl->mpeaceful) {
        pline("%s is not in the mood for conversation (believe it or not...)", Monnam(oracl));
        return 0;
    } else if (!umoney) {
        pline("You have no money.  There's no free lunch in wireless... and in being an oracle!");
        return 0;
    }

    qbuf = msgprintf("\"Would you mind talking for a little bit?\" (%d %s)",
                     minor_cost, currency(minor_cost));
    switch (ynq(qbuf)) {
    default:
    case 'q':
        return 0;
    case 'y':
        if (umoney < minor_cost) {
            pline("You don't even have enough money for that! There's no free lunch in wireless... and in being an oracle!");
            return 0;
        }
        u_pay = minor_cost;
        break;
    case 'n':
        if (umoney <= minor_cost ||     /* don't even ask */
            (oracle_cnt == 1 || oracle_flg < 0))
            return 0;
        qbuf = msgprintf("\"Oh! You'd like to sit and talk for a _long_ while?\" (%d %s)",
                         major_cost, currency(major_cost));
        if (yn(qbuf) != 'y')
            return 0;
        u_pay = (umoney < major_cost ? umoney : major_cost);

        break;
    }

    money2mon(oracl, u_pay);
    add_xpts = 0;       /* first oracle of each type gives experience points */
    if (u_pay == minor_cost) {
        outrumor(1, BY_ORACLE);
        if (!u.uevent.minor_oracle)
            add_xpts = u_pay / (u.uevent.major_oracle ? 25 : 10);
        /* 5 pts if very 1st, or 2 pts if major already done */
        u.uevent.minor_oracle = TRUE;
    } else {
        boolean cheapskate = u_pay < major_cost;

        outoracle(cheapskate, TRUE);
        if (!cheapskate && !u.uevent.major_oracle)
            add_xpts = u_pay / (u.uevent.minor_oracle ? 25 : 10);
        /* ~100 pts if very 1st, ~40 pts if minor already done */
        u.uevent.major_oracle = TRUE;
        historic_event(FALSE, "received advice from The Oracle.");
        exercise(A_WIS, !cheapskate);
    }
    if (add_xpts) {
        more_experienced(add_xpts, u_pay / 50);
        newexplevel();
    }
    return 1;
}