void test_fx_fixed_limits_double(ostream& out) { out << "****************** limits fx_fixed<8, 5>_double\n"; sc_fixed<8, 5> zero_min("-0"); SHOW(zero_min); sc_fixed<8, 5> zero_plus("+0"); SHOW(zero_plus); sc_fixed<8, 5> zero(0); SHOW(zero); sc_fixed<8, 5> long_max(LONG_MAX); SHOW(long_max); sc_fixed<8, 5> long_min(LONG_MIN); SHOW(long_min); sc_fixed<8, 5> int_max(INT_MAX); SHOW(int_max); sc_fixed<8, 5> int_min(INT_MIN); SHOW(int_min); sc_fixed<8, 5> uint_max(UINT_MAX); SHOW(uint_max); sc_fixed<8, 5> ulong_max(ULONG_MAX); SHOW(ulong_max); sc_fixed<8, 5> double_min(DBL_MIN); SHOW(double_min); sc_fixed<8, 5> double_max(DBL_MAX); SHOW(double_max); sc_fixed<8, 5> float_min(FLT_MIN); SHOW(float_min); sc_fixed<8, 5> float_max(FLT_MAX); SHOW(float_max); // sc_fixed<8, 5> res; // SHOW_EXPS(double_min); // SHOW_EXPS(double_max); // SHOW_EXPS(float_min); // SHOW_EXPS(float_max); }
void test_fx_fix_limits_long(ostream& out) { out << "****************** limits fx_fix_long\n"; sc_fix zero_min("-0"); SHOW(zero_min); sc_fix zero_plus("+0"); SHOW(zero_plus); sc_fix zero(0); SHOW(zero); sc_fix long_max(LONG_MAX); SHOW(long_max); sc_fix long_min(LONG_MIN); SHOW(long_min); sc_fix int_max(INT_MAX); SHOW(int_max); sc_fix int_min(INT_MIN); SHOW(int_min); sc_fix uint_max(UINT_MAX); SHOW(uint_max); sc_fix ulong_max(ULONG_MAX); SHOW(ulong_max); sc_fix double_min(DBL_MIN); SHOW(double_min); sc_fix double_max(DBL_MAX); SHOW(double_max); sc_fix float_min(FLT_MIN); SHOW(float_min); sc_fix float_max(FLT_MAX); SHOW(float_max); // sc_fix res; // SHOW_EXPS(long_max); // SHOW_EXPS(long_min); // SHOW_EXPS(int_max); // SHOW_EXPS(int_min); // SHOW_EXPS(uint_max); // SHOW_EXPS(ulong_max); }
void test_fx_float_limits_zero(ostream& out) { cerr << "****************** limits fx_float_zero\n"; sc_fxval zero_min("-0"); SHOW(zero_min); sc_fxval zero_plus("+0"); SHOW(zero_plus); sc_fxval zero(0); SHOW(zero); sc_fxval nan("NaN"); SHOW(nan); sc_fxval inf_plus("+Inf"); SHOW(inf_plus); sc_fxval inf_min("-Inf"); SHOW(inf_min); sc_fxval inf("Inf"); SHOW(inf); sc_fxval long_max(LONG_MAX); SHOW(long_max); sc_fxval long_min(LONG_MIN); SHOW(long_min); sc_fxval int_max(INT_MAX); SHOW(int_max); sc_fxval int_min(INT_MIN); SHOW(int_min); sc_fxval uint_max(UINT_MAX); SHOW(uint_max); sc_fxval ulong_max(ULONG_MAX); SHOW(ulong_max); sc_fxval double_min(DBL_MIN); SHOW(double_min); sc_fxval double_max(DBL_MAX); SHOW(double_max); sc_fxval float_min(FLT_MIN); SHOW(float_min); sc_fxval float_max(FLT_MAX); SHOW(float_max); sc_fxval res; SHOW_EXPS(zero_min); SHOW_EXPS(zero_plus); SHOW_EXPS(zero); }
int main() { printf("Floating point information:\n"); printf("float radix: %d\n", FLT_RADIX); printf("float exponent size: %d (%d bits)\n", FLT_MAX_EXP, bits(FLT_MAX_EXP)); printf("double exponent size: %d (%d bits)\n", DBL_MAX_EXP, bits(DBL_MAX_EXP)); printf("long double exponent size: %d (%d bits)\n", LDBL_MAX_EXP, bits(LDBL_MAX_EXP)); printf("Ranges:\n"); printf("float: [%f, %f]\n", float_min(), float_max()); printf("float: [%f, %f] (system)\n", FLT_MIN, FLT_MAX); printf("double: [%f, %f]\n", double_min(), double_max()); printf("double: [%f, %f] (system)\n", DBL_MIN, DBL_MAX); printf("long double: [%Lf, %Lf]\n", dlong_min(), dlong_max()); printf("long double: [%Lf, %Lf] (system)\n", LDBL_MIN, LDBL_MAX); return 0; }
int main() { printf("\nFixed Point\n"); printf("____________\n\n"); printf("\nBy Calculation.\n\n"); fixed_range(); printf("\nFrom limits.h\n\n"); header_limits_range(); printf("\nFloating Point"); printf("\n________________\n\n"); printf("\nBy Calculation.\n\n"); float_max(); float_min(); double_max(); double_min(); long_double_max(); printf("\nFrom float.h\n\n"); header_float_range(); return 0; }
static int advanceStroke( float* pRemainingTime, float timeStep ) { // draw stroke.. Page* pPage = &s_renderer.pages[ s_renderer.currentPage ]; Stroke* pStroke = &s_renderer.currentStroke; const StrokeCommand* pCommand = &s_renderer.strokeBuffer.commands[ s_renderer.currentCommand ]; if( !pCommand || pCommand->type != StrokeCommandType_Draw ) { SYS_TRACE_ERROR( "no active stroke!\n" ); return FALSE; } const StrokeDrawCommandData* pDrawCommand = &pCommand->data.draw; graphics_setRenderTarget( &pPage->fgTarget ); graphics_setShader( &s_renderer.penShader ); graphics_setBlendMode( BlendMode_Over ); const PenDefinition* pPen = &s_renderer.pens[ pDrawCommand->penId ]; const float variance = pDrawCommand->variance; // set constant shader parameters: graphics_setFp4f( 0u, 0.5f * pPen->width, variance, 0.05f * variance, 0.0f ); graphics_setFp4f( 1u, pPen->color.x, pPen->color.y, pPen->color.z, 1.0f ); float currentProgress = pStroke->progress; const float strokeLength = pStroke->length; float newProgress; if( s_renderer.strokeDrawSpeed <= 0.0f ) { // always finish the whole stroke: newProgress = strokeLength; // and we don't need any time: *pRemainingTime = timeStep; } else { // how long until we reach the end of this stroke?: const float remainingStrokeTime = ( strokeLength - pStroke->progress ) / s_renderer.strokeDrawSpeed; const float usedTime = float_min( timeStep, remainingStrokeTime ); newProgress = pStroke->progress + usedTime * s_renderer.strokeDrawSpeed; *pRemainingTime = timeStep - usedTime; } // SYS_TRACE_DEBUG( "advancing stroke from %f to %f! length=%f\n", currentProgress, newProgress, strokeLength ); if( newProgress <= currentProgress ) { return TRUE; } const uint segmentCount = pDrawCommand->pointCount - 1u; float remainingLength = newProgress - currentProgress; const float2* pStrokePoints = &s_renderer.strokeBuffer.points[ pDrawCommand->pointIndex ]; const float2* pStrokeNormals = &s_renderer.strokeBuffer.pointNormals[ pDrawCommand->pointIndex ]; while( pStroke->activeSegment < segmentCount && remainingLength > 0.0f ) { const float2 segmentStart = pStrokePoints[ pStroke->activeSegment ]; const float2 segmentEnd = pStrokePoints[ pStroke->activeSegment + 1u ]; const float2 segmentNormalStart = pStrokeNormals[ pStroke->activeSegment ]; const float2 segmentNormalEnd = pStrokeNormals[ pStroke->activeSegment + 1u ]; // get remaining length in current segment: float activeSegmentLength = float2_distance( &segmentStart, &segmentEnd ); if( activeSegmentLength <= 0.0f ) { break; } float remainingSegmentLength = activeSegmentLength - pStroke->segmentProgress; const float segmentAdvance = float_min( remainingSegmentLength, remainingLength ); // draw segment part: const float partStart = pStroke->segmentProgress; const float partEnd = partStart + segmentAdvance; const float strokeU0 = currentProgress / strokeLength; const float strokeU1 = ( currentProgress + segmentAdvance ) / strokeLength; const float segmentU0 = partStart / activeSegmentLength; const float segmentU1 = partEnd / activeSegmentLength; // draw the active segment between partStart and partEnd: //SYS_TRACE_DEBUG( "drawing segment part from %f to %f!\n", partStart / activeSegmentLength, partEnd / activeSegmentLength ); // compute part // :todo: draw start and end parts if this is the start/end of the segment // compute coordinates of quad enclosing the segment part: float2 segmentDir; float2_normalize( float2_sub( &segmentDir, &segmentEnd, &segmentStart ) ); float2 normalStart, normalEnd; float2_lerp( &normalStart, &segmentNormalStart, &segmentNormalEnd, segmentU0 ); float2_lerp( &normalEnd, &segmentNormalStart, &segmentNormalEnd, segmentU1 ); float2 startPos, endPos; float2_addScaled1f( &startPos, &segmentStart, &segmentDir, partStart ); float2_addScaled1f( &endPos, &segmentStart, &segmentDir, partEnd ); const float ws = 2.0f * ( 64.0f / sys_getScreenWidth() ); float2 vertices[ 4u ]; float2_addScaled1f( &vertices[ 0u ], &startPos, &normalStart, ws * pPen->width ); float2_addScaled1f( &vertices[ 1u ], &startPos, &normalStart, -ws * pPen->width ); float2_addScaled1f( &vertices[ 2u ], &endPos, &normalEnd, -ws * pPen->width ); float2_addScaled1f( &vertices[ 3u ], &endPos, &normalEnd, ws * pPen->width ); const float u0 = strokeU0; const float u1 = strokeU1; //SYS_TRACE_DEBUG( "u0=%f u1=%f v0=%f,%f v3=%f,%f\n", u0, u1, vertices[ 0u ].x, vertices[ 0u ].y, vertices[ 3u ].x, vertices[ 3u ].y ); graphics_drawQuad( vertices, u0, 0.0f, u1, 1.0f ); pStroke->segmentProgress += segmentAdvance; remainingLength -= segmentAdvance; currentProgress += segmentAdvance; if( segmentAdvance >= remainingSegmentLength ) { // next segment: pStroke->activeSegment++; pStroke->segmentProgress = 0.0f; } } if( newProgress < strokeLength ) { pStroke->progress = newProgress; return TRUE; } return FALSE; }