1
0
mirror of https://gitlab.com/rnger/amath synced 2025-10-06 02:49:59 +00:00
Files
amath/doc/man/man3/DecimalSystem.3
2017-01-24 22:03:15 +01:00

201 lines
5.3 KiB
Groff

.TH "DecimalSystem" 3 "Tue Jan 24 2017" "Version 1.6.2" "amath" \" -*- nroff -*-
.ad l
.nh
.SH NAME
DecimalSystem \-
.SH SYNOPSIS
.br
.PP
.PP
\fC#include <ntext\&.h>\fP
.PP
Inherits \fBPositionalNumeralSystem\fP\&.
.SS "Public Member Functions"
.in +1c
.ti -1c
.RI "\fBDecimalSystem\fP ()"
.br
.ti -1c
.RI "\fBDecimalSystem\fP (unsigned int \fBdigits\fP)"
.br
.ti -1c
.RI "\fBDecimalSystem\fP (unsigned int \fBdigits\fP, const char \fBfractionpoint\fP)"
.br
.ti -1c
.RI "\fB~DecimalSystem\fP ()"
.br
.ti -1c
.RI "virtual const char * \fBGetText\fP (\fBNumber\fP *number)"
.br
.in -1c
.SS "Private Member Functions"
.in +1c
.ti -1c
.RI "const char * \fBGetRealText\fP (double value)"
.br
.in -1c
.SS "Additional Inherited Members"
.SH "Detailed Description"
.PP
Definition at line 98 of file ntext\&.h\&.
.SH "Constructor & Destructor Documentation"
.PP
.SS "DecimalSystem::DecimalSystem ()"
.PP
Definition at line 355 of file ntext\&.cpp\&.
.PP
References PositionalNumeralSystem::PositionalNumeralSystem()\&.
.PP
.nf
355 :
356 PositionalNumeralSystem(10, 5, '\0')
357 { }
.fi
.SS "DecimalSystem::DecimalSystem (unsigned int digits)"
.PP
Definition at line 359 of file ntext\&.cpp\&.
.PP
References PositionalNumeralSystem::PositionalNumeralSystem()\&.
.PP
Referenced by MemoryStatement::Execute(), DigitsStatement::Execute(), PlotStatement::Execute(), PreferencesBase::GetDescription(), PositionalNumeralSystem::GetName(), Parser::ParseDigistStatement(), and Parser::ParseNumeralStatement()\&.
.PP
.nf
359 :
360 PositionalNumeralSystem(10, digits, '\&.')
361 { }
.fi
.SS "DecimalSystem::DecimalSystem (unsigned int digits, const char fractionpoint)"
.PP
Definition at line 363 of file ntext\&.cpp\&.
.PP
References PositionalNumeralSystem::PositionalNumeralSystem()\&.
.PP
Referenced by Program::NewPositionalInput(), Program::NewPositionalOutput(), and Program::Program()\&.
.PP
.nf
365 :
366 PositionalNumeralSystem(10, digits, fractionpoint)
367 { }
.fi
.SS "DecimalSystem::~DecimalSystem ()"
.PP
Definition at line 369 of file ntext\&.cpp\&.
.PP
.nf
370 { }
.fi
.SH "Member Function Documentation"
.PP
.SS "const char * DecimalSystem::GetRealText (double value)\fC [private]\fP"
.PP
Definition at line 405 of file ntext\&.cpp\&.
.PP
References CharBuffer::Append(), NumeralSystem::buf, PositionalNumeralSystem::digits, CharBuffer::EnsureGrowth(), PositionalNumeralSystem::fractionpoint, CharBuffer::GetString(), log10(), pow(), PrintFloat64(), PrintFloatFormat_Positional, PrintFloatFormat_Scientific, CharBuffer::RemoveTrailing(), round(), and trunc()\&.
.PP
Referenced by GetText()\&.
.PP
.nf
406 {
407 double exponent = log10(fabs(value));
408 int formatdigits = digits - (int)trunc(exponent) - 1;
409
410 double rounddigits = digits - 1;
411 if (exponent < 0\&.0) {
412 rounddigits++;
413 formatdigits++;
414 }
415
416 // Remove output of inaccuracy
417 if (formatdigits > (int)digits) {
418 formatdigits = digits;
419 }
420
421 double roundfactor = pow(10\&.0, rounddigits);
422 double roundedvalue = round(value * roundfactor) / roundfactor;
423
424 if (roundedvalue == 0\&.0) {
425 return "0";
426 }
427
428 double ulimit = pow(10\&.0, (double)digits);
429 double llimit = pow(10\&.0, -(double)digits);
430
431 if (fabs(roundedvalue) > ulimit) {
432 return "INF";
433 } else if (fabs(roundedvalue) < llimit) {
434 return "-INF";
435 }
436
437 double expborder = log10(fabs(roundedvalue));
438 tPrintFloatFormat format = (expborder > 6\&.0 || expborder < -5\&.0) ?
439 PrintFloatFormat_Scientific :
440 PrintFloatFormat_Positional;
441
442 static const int size = 32;
443 char *out = new char[size];
444 PrintFloat64(out, size, roundedvalue, format, formatdigits, fractionpoint);
445 buf->EnsureGrowth(size);
446 buf->Append(out);
447 while (buf->RemoveTrailing('0'))
448 ;
449 buf->RemoveTrailing(fractionpoint);
450 delete[] out;
451
452 return buf->GetString();
453 }
.fi
.SS "const char * DecimalSystem::GetText (\fBNumber\fP * number)\fC [virtual]\fP"
.PP
Reimplemented from \fBPositionalNumeralSystem\fP\&.
.PP
Definition at line 372 of file ntext\&.cpp\&.
.PP
References CharBuffer::Append(), NumeralSystem::buf, cimag(), creal(), CharBuffer::Empty(), ComplexNumber::GetComplexValue(), GetRealText(), Number::GetRealValue(), CharBuffer::GetString(), nsysreal, and Number::system\&.
.PP
.nf
373 {
374 buf->Empty();
375
376 if (number->system == nsysreal) {
377 return GetRealText(number->GetRealValue());
378 }
379
380 complex w = ((ComplexNumber*)number)->GetComplexValue();
381 double a = creal(w);
382 double b = cimag(w);
383
384 if (a == 0\&.0 && b == 0\&.0) {
385 buf->Append('0');
386 return buf->GetString();
387 }
388
389 if (a != 0\&.0) {
390 GetRealText(a);
391 }
392
393 if (a != 0\&.0 && b > 0\&.0) {
394 buf->Append('+');
395 }
396
397 if (b != 0\&.0) {
398 GetRealText(b);
399 buf->Append('i');
400 }
401
402 return buf->GetString();
403 }
.fi
.SH "Author"
.PP
Generated automatically by Doxygen for amath from the source code\&.