本文整理汇总了C++中pow10函数的典型用法代码示例。如果您正苦于以下问题:C++ pow10函数的具体用法?C++ pow10怎么用?C++ pow10使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pow10函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update_range_lables
static void
update_range_lables(GtkWidget *from, GtkWidget *to, GtkWidget *unit,
gdouble min, gdouble max, const gchar *unitstring)
{
GwySIValueFormat *vf;
GwySIUnit *siunit;
gint power10;
gchar *s;
siunit = gwy_si_unit_new_parse(unitstring, &power10);
min *= pow10(power10);
max *= pow10(power10);
vf = gwy_si_unit_get_format_with_digits(siunit, GWY_SI_UNIT_FORMAT_VFMARKUP,
MAX(fabs(min), fabs(max)), 3,
NULL);
s = g_strdup_printf("%.*f", vf->precision, min/vf->magnitude);
gtk_label_set_markup(GTK_LABEL(from), s);
g_free(s);
s = g_strdup_printf("%.*f", vf->precision, max/vf->magnitude);
gtk_label_set_markup(GTK_LABEL(to), s);
g_free(s);
gtk_label_set_markup(GTK_LABEL(unit), vf->units);
gwy_si_unit_value_format_free(vf);
g_object_unref(siunit);
}
示例2: ftoa
/*
* convert floating to ascii. ftoa returns an integer e such that
* f=g*10**e, with .1<=|g|<1 (e=0 when g==0) and puts an ascii
* representation of g in the buffer pointed to by bp. bp[0] will
* be '+' or '-', and bp[1] to bp[NFTOA-2]
* will be appropriate digits of g. bp[NFTOA-1] will be '\0'
*/
int ftoa(double f, char *bp) {
int e, e1, e2, i;
double digit, g, p;
if(f>=0) *bp++='+';
else {
f=-f;
*bp++='-';
}
/* find e such that f==0 or 1<=f*pow10(e)<10, and set f=f*pow10(e) */
if(f==0.) e=1;
else {
frexp(f, &e);
e=-e*30103/100000;
/* split in 2 pieces to guard against overflow in extreme cases */
e1=e/2;
e2=e-e1;
p=f*pow10(e2);
while((g=p*pow10(e1))<1.) e1++;
while((g=p*pow10(e1))>=10.) --e1;
e=e1+e2;
f=g;
}
for(i=0; i!=NDIG; i++) {
f=modf(f, &digit)*10.;
*bp++=digit+'0';
}
*bp='\0';
return 1-e;
}
示例3: main
void main (void)
{
printf("10 raised to -1 is %f\n", pow10(-1));
printf("10 raised to 0 is %f\n", pow10(0));
printf("10 raised to 1 is %f\n", pow10(1));
printf("10 raised to 2 is %f\n", pow10(2));
}
示例4: parse_exact_real
cons_t* parse_exact_real(const char* sc, int radix)
{
if ( radix != 10 )
raise(parser_exception(
"Only reals with decimal radix are supported"));
/*
* Since the real is already in string form, we can simply turn it into a
* rational number.
*/
char *s = strdup(sc);
char *d = strchr(s, '.');
*d = '\0';
const char* left = s;
const char* right = d+1;
int decimals = strlen(right);
/*
* NOTE: If we overflow here, we're in big trouble.
* TODO: Throw an error if we overflow. Or just implement bignums.
*/
rational_t r;
r.numerator = to_i(left, radix)*pow10(decimals) + to_i(right, radix);
r.denominator = pow10(decimals);
free(s);
return rational(r, true);
}
示例5: reverse
int reverse(int x){
int keta = 1 + (int)log10(x);
int i,y=0;
for( i=0; i<keta; i++){
y += (int)(x / pow10(i)) % 10 * pow10(keta-i-1);
}
// printf("x:%d keta:%d, y:%d, test:%d",x,keta,y,pow10(2));
return y;
}
示例6: fix_scales
static void
fix_scales(EZDSection *section,
gint idx,
GwyContainer *container)
{
GwyDataField *dfield;
GwySIUnit *siunit;
gchar key[40];
gint power10;
gdouble r;
g_snprintf(key, sizeof(key), "/%d/data", idx);
dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(container, key));
/* Fix value scale */
siunit = gwy_si_unit_new_parse(section->zrange.unit, &power10);
gwy_data_field_set_si_unit_z(dfield, siunit);
g_object_unref(siunit);
r = pow10(power10);
gwy_data_field_multiply(dfield, r*section->zrange.range);
gwy_data_field_add(dfield, r*section->zrange.min);
/* Fix lateral scale */
siunit = gwy_si_unit_new_parse(section->xrange.unit, &power10);
gwy_data_field_set_si_unit_xy(dfield, siunit);
g_object_unref(siunit);
gwy_data_field_set_xreal(dfield, pow10(power10)*section->xrange.range);
siunit = gwy_si_unit_new_parse(section->yrange.unit, &power10);
gwy_data_field_set_yreal(dfield, pow10(power10)*section->yrange.range);
g_object_unref(siunit);
/* Some metadata */
if (section->zrange.name) {
const gchar *s;
switch (section->direction) {
case SCAN_FORWARD:
s = " forward";
break;
case SCAN_BACKWARD:
s = " backward";
break;
default:
s = "";
break;
}
g_snprintf(key, sizeof(key), "/%d/data/title", idx);
gwy_container_set_string_by_name(container, key,
g_strdup_printf("%s%s",
section->zrange.name,
s));
}
}
示例7: throwBigRealInvalidArgumentException
// Same as getFirst32, but k = [0..MAXDIGITS_INT128] = [0..38]
_uint128 &BigReal::getFirst128(_uint128 &dst, const UINT k, BRExpoType *scale) const {
#ifdef _DEBUG
DEFINEMETHODNAME;
if(k > MAXDIGITS_INT128) {
throwBigRealInvalidArgumentException(method, _T("k=%d. Legal interval is [0..%d]"),k,MAXDIGITS_INT128);
}
#endif
const Digit *p = m_first;
if(p == NULL) {
if(scale) *scale = 0;
dst = 0;
return dst;
}
int tmpScale = 0;
dst = p->n;
int digits = getDecimalDigitCount(p->n), firstDigits = digits;
if((UINT)digits >= k) {
dst /= pow10(digits-k); // digits-k <= LOG10_BIGREALBASE, so pow10 will not fail
if(scale) {
ADJUSTSCALEMOD10(dst);
}
} else { // digits < k
if(scale) {
for(p = p->next; (UINT)digits < k; digits += LOG10_BIGREALBASE) {
if(p) {
const BRDigitType p10 = pow10(min(LOG10_BIGREALBASE,k-digits));
dst = dst * p10 + p->n / (BIGREALBASE/p10);
p = p->next;
} else {
tmpScale = k - digits;
break;
}
}
ADJUSTSCALEMOD10(dst);
} else { // scale == NULL
for(p = p->next; (UINT)digits < k; digits += LOG10_BIGREALBASE) {
const BRDigitType p10 = pow10(min(LOG10_BIGREALBASE,k-digits));
dst *= p10;
if(p) {
dst += p->n / (BIGREALBASE/p10);
p = p->next;
}
}
}
}
if(scale) {
*scale = m_expo * LOG10_BIGREALBASE + firstDigits - 1 + tmpScale - k;
}
return dst;
}
示例8: rhkspm32_read_data
static GwyDataField*
rhkspm32_read_data(RHKPage *rhkpage)
{
GwyDataField *dfield;
const guint16 *p;
GwySIUnit *siunit;
gdouble *data;
const gchar *s;
gdouble q;
gint power10;
guint i, j, xres, yres;
p = (const guint16*)(rhkpage->buffer + rhkpage->data_offset);
xres = rhkpage->xres;
yres = rhkpage->yres;
// the scales are no longer gurunteed to be positive,
// so they must be "fixed" here (to enable spectra)
dfield = gwy_data_field_new(xres, yres,
xres*fabs(rhkpage->x.scale),
yres*fabs(rhkpage->y.scale),
FALSE);
data = gwy_data_field_get_data(dfield);
for (i = 0; i < yres; i++) {
for (j = 0; j < xres; j++)
data[i*xres + xres-1 - j] = GINT16_FROM_LE(p[i*xres + j]);
}
siunit = gwy_data_field_get_si_unit_xy(dfield);
gwy_si_unit_set_from_string_parse(siunit, rhkpage->x.units, &power10);
if (power10) {
q = pow10(power10);
gwy_data_field_set_xreal(dfield, q*gwy_data_field_get_xreal(dfield));
gwy_data_field_set_yreal(dfield, q*gwy_data_field_get_yreal(dfield));
}
siunit = gwy_data_field_get_si_unit_z(dfield);
s = rhkpage->z.units;
/* Fix some silly units */
if (gwy_strequal(s, "N/sec"))
s = "s^-1";
gwy_si_unit_set_from_string_parse(siunit, s, &power10);
q = pow10(power10);
gwy_data_field_multiply(dfield, q*fabs(rhkpage->z.scale));
gwy_data_field_add(dfield, q*rhkpage->z.offset);
return dfield;
}
示例9: main
int main()
{
int i, stage;
int level;
int success = 0;
clock_t start, end;
srand((unsigned long)time(NULL));
printf("数値記憶トレーニング\n");
do {
printf("挑戦するレベル (%d ~ %d): ", LEVEL_MIN, LEVEL_MAX);
scanf("%d", &level);
} while (level < LEVEL_MIN || level > LEVEL_MAX);
start = clock();
for (stage = 0; stage < MAX_STAGE; stage++) {
int ans;
int input;
ans = pow10(level-1) + rand() % (pow10(level-1) * 9);
printf("%d", ans);
fflush(stdout);
sleep(125*level);
int pos = rand() % level;
printf("\r%*s\r%d 桁目は? 入力: ", level, " ", pos+1);
scanf("%d", &input);
if (get_onenum(ans, pos, level) != input)
printf("不正解です\n");
else {
printf("正解です\n");
success++;
}
}
end = clock();
printf("終了\n");
printf("正答率: %3.2f (%d / %d)\n", (double)(success * 100/MAX_STAGE), success, MAX_STAGE);
printf("経過時間: %f\n", (double)(end - start)/CLOCKS_PER_SEC);
return 0;
}
示例10: timeWidth
void AmplitudeWidget::drawVerticalRefLines()
{
//Draw the vertical reference lines
double timeStep = timeWidth() / double(width()) * 150.0; //time per 150 pixels
double timeScaleBase = pow10(floor(log10(timeStep))); //round down to the nearest power of 10
//choose a timeScaleStep which is a multiple of 1, 2 or 5 of timeScaleBase
int largeFreq;
if(timeScaleBase * 5.0 < timeStep) { largeFreq = 5; }
else if (timeScaleBase * 2.0 < timeStep) { largeFreq = 2; }
else { largeFreq = 2; timeScaleBase /= 2; }
double timePos = floor(leftTime() / (timeScaleBase*largeFreq)) * (timeScaleBase*largeFreq); //calc the first one just off the left of the screen
int x, largeCounter=-1;
double ratio = double(width()) / timeWidth();
double lTime = leftTime();
for(; timePos <= rightTime(); timePos += timeScaleBase) {
if(++largeCounter == largeFreq) {
largeCounter = 0;
glColor4ub(25, 125, 170, 128); //draw the darker lines
} else {
glColor4ub(25, 125, 170, 64); //draw the lighter lines
}
x = toInt((timePos-lTime) * ratio);
mygl_line(x, 0, x, height()-1);
}
}
示例11: main
int
main(int argc, char* argv[])
{
int div;
int max=0;
int val = -1;
for(div=1;div<1000;++div) {
int i;
int digits[1000];
int ndigits;
int num = 1;
int nn = nmultiplier(div);
memset(digits, 0, sizeof(digits));
ndigits=0;
for(i=0;i<1000;++i)
{
num *= pow10(nn);
num %= div;
if(!find(digits, ndigits, num))
digits[ndigits++]=num;
}
if(ndigits>max)
{
max = ndigits;
val=div;
}
}
printf("%d\n", val);
return 0;
}
示例12: getColor
void TPercentageText::draw()
{
ushort color = getColor(1);
char *string = new char[size.x + 1];
itoa( Round( percentage * pow10( precisionDigits ) ), string, 10 );
if( precisionDigits > 0 )
{
memmove( &string[strlen( string ) - precisionDigits + 1],
&string[strlen( string ) - precisionDigits],
precisionDigits + 1 );
string[strlen( string ) - 1 - precisionDigits] = point;
}
strcat( string, percentageString );
if( string[0] == point )
{
memmove( &string[1], string, strlen( string ) + 1 );
string[0] = '0';
}
TDrawBuffer b;
b.moveChar( 0, ' ', color, size.x );
b.moveStr( size.x - 1 - strlen( string ), string, color );
writeLine( 0, 0, size.x, 1, b );
delete[] string;
}
示例13: main
int main(void)
{
#pragma STDC FENV_ACCESS ON
double y;
float d;
int e, i, err = 0;
struct d_d *p;
for (i = 0; i < sizeof t/sizeof *t; i++) {
p = t + i;
if (p->r < 0)
continue;
fesetround(p->r);
feclearexcept(FE_ALL_EXCEPT);
y = pow10(p->x);
e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);
if (!checkexcept(e, p->e, p->r)) {
printf("%s:%d: bad fp exception: %s pow10(%a)=%a, want %s",
p->file, p->line, rstr(p->r), p->x, p->y, estr(p->e));
printf(" got %s\n", estr(e));
err++;
}
d = ulperr(y, p->y, p->dy);
if (!checkulp(d, p->r)) {
printf("%s:%d: %s pow10(%a) want %a got %a ulperr %.3f = %a + %a\n",
p->file, p->line, rstr(p->r), p->x, p->y, y, d, d-p->dy, p->dy);
err++;
}
}
return !!err;
}
示例14: gwy_si_unit_get_format_with_digits
/**
* gwy_si_unit_get_format_with_digits:
* @siunit: A SI unit.
* @style: Unit format style.
* @maximum: The maximum value to be represented.
* @sdigits: The number of significant digits the value should have.
* @format: A value format to set-up, may be %NULL, a new value format is
* allocated then.
*
* Finds a good format for representing a values with given number of
* significant digits.
*
* The values should be then printed as value/@format->magnitude
* [@format->units] with @format->precision decimal places.
*
* Returns: The value format. If @format was %NULL, a newly allocated format
* is returned, otherwise (modified) @format itself is returned.
**/
GwySIValueFormat*
gwy_si_unit_get_format_with_digits(GwySIUnit *siunit,
GwySIUnitFormatStyle style,
gdouble maximum,
gint sdigits,
GwySIValueFormat *format)
{
const GwySIStyleSpec *spec;
gwy_debug("");
g_return_val_if_fail(GWY_IS_SI_UNIT(siunit), NULL);
spec = gwy_si_unit_find_style_spec(style);
if (!format)
format = (GwySIValueFormat*)g_new0(GwySIValueFormat, 1);
maximum = fabs(maximum);
if (!maximum) {
format->magnitude = 1;
format->precision = sdigits;
}
else
format->magnitude
= gwy_math_humanize_numbers(maximum/pow10(sdigits),
maximum, &format->precision);
siunit->power10 = ROUND(log10(format->magnitude));
format->units_gstring = gwy_si_unit_format(siunit, spec,
format->units_gstring);
format->units = format->units_gstring->str;
return format;
}
示例15: bitset_print
/*
* The following prints a bitset with a 'ruler' that look like this
*
* 11111111112222222222333333333344444444445555555555666666666677
* 012345678901234567890123456789012345678901234567890123456789012345678901
* xx:........................................................................
* 11111111111111111111111111111111111111111111
* 777777778888888888999999999900000000001111111111222222222233333333334444
* 234567890123456789012345678901234567890123456789012345678901234567890123
* ........................................................................
* 111111111111111111111111111111111111111111111111111111112222222222222222
* 444444555555555566666666667777777777888888888899999999990000000000111111
* 456789012345678901234567890123456789012345678901234567890123456789012345
* ........................................................................
* 2222222222
* 1111222222
* 6789012345
* ..........
*
* to identify individual bits that are set.
*/
static void
bitset_print(bitset_t *bs, char *label, int width)
{
int val_start;
int val_max;
int label_width;
int ruler_width;
int v, vm, vi;
int nl, l;
int i;
int p;
char c;
val_start = 0;
val_max = bitset_highbit(bs) + 1;
if (val_max <= val_start) {
mdb_printf("%s: empty-set", label);
return;
}
label_width = strlen(label) + 1;
ruler_width = width - label_width;
for (v = val_start; v < val_max; v = vm) {
if ((v + ruler_width) < val_max)
vm = v + ruler_width;
else
vm = val_max;
nl = log10(vm) - 1;
for (l = nl; l >= 0; l--) {
p = pow10(l);
for (i = 0; i < label_width; i++)
mdb_printf(" ");
for (vi = v; vi < vm; vi++) {
c = '0' + ((vi / p) % 10);
if ((l == nl) && (c == '0'))
c = ' ';
mdb_printf("%c", c);
}
mdb_printf("\n");
}
if (v == val_start) {
mdb_printf("%s:", label);
} else {
for (i = 0; i < label_width; i++)
mdb_printf(" ");
}
for (vi = v; vi < vm; vi++) {
if (BT_TEST(bs->bs_set, vi))
mdb_printf("X");
else
mdb_printf(".");
}
mdb_printf("\n");
}
}