MantisBT
Mantis Bug Tracker Workflow

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0031515Open CASCADE[OCCT] OCCT:Foundation Classespublic2020-04-23 13:442020-09-18 07:38
Reportersshutina 
Assigned Tonds 
PrioritylowSeverityfeature 
StatusclosedResolutionno change required 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0031515: Incorrect conversion Standard_Real to TCollection_AsciiString and TCollection_ExtendedString
DescriptionStandard_Real is converted to TCollection_AsciiString or TCollection_ExtendedString via the constructor TCollection_AsciiString::TCollection_AsciiString (const Standard_Real value) or TCollection_ExtendedString::TCollection_ExtendedString (const Standard_Real value).
The result is the string of the length no more than 7 digits.
TCollection_AsciiString (const Standard_Integer value) and TCollection_ExtendedString (const Standard_Integer value) haven't the limits of the number of the digits.

Output:
Standard_Real: 123456.7 TCollection_ExtendedString : 123457 Lenght = 6
Standard_Real: 12345.67 TCollection_ExtendedString : 12345.7 Lenght = 7
Standard_Real: 12.34567 TCollection_ExtendedString : 12.3457 Lenght = 7
Standard_Integer: 1234567 TCollection_ExtendedString : 1234567 Lenght = 7
Standard_Real: 12345.6 TCollection_ExtendedString : 12345.6 Lenght = 7
Standard_Integer: 123456789 TCollection_ExtendedString : 123456789 Lenght = 9
Standard_Real: 12345.6789 TCollection_ExtendedString : 12345.7 Lenght = 7

Standard_Real: 123456.7 TCollection_AsciiString : 123457 Lenght = 6
Standard_Real: 12345.67 TCollection_AsciiString : 12345.7 Lenght = 7
Standard_Real: 12.34567 TCollection_AsciiString : 12.3457 Lenght = 7
Standard_Integer: 1234567 TCollection_AsciiString : 1234567 Lenght = 7
Standard_Real: 12345.6 TCollection_AsciiString : 12345.6 Lenght = 7
Standard_Integer: 123456789 TCollection_AsciiString : 123456789 Lenght = 9
Standard_Real: 12345.6789 TCollection_AsciiString : 12345.7 Lenght = 7

In the code
// -------------------------------------------------------------------------
// Create an asciistring from a real
// -------------------------------------------------------------------------
TCollection_AsciiString::TCollection_AsciiString(const Standard_Real aValue)
     : mystring(0)
{
  char t [50];
  mylength = Sprintf( t,"%g",aValue);
  mystring = Allocate(mylength+1);
  memcpy (mystring, t, mylength);
  mystring[mylength] = '\0';
}

the function Sprintf(...) returns the incorrect length and the incorrect array of the characters.
TagsNo tags attached.
Test case number
Attached Files

- Relationships
related to 0031516verifiedbugmaster PMI Visualization - Set/Get the number of the digits after the comma 

-  Notes
(0091751)
kgv (developer)
2020-04-23 19:31

This is by design - default string constructor with real numbers is just expected to be used for printing messages, so that it relies on %g for "smart compact real representation".

Code which requires controlling floating point precision should use Sprintf() or similar and pass it to TCollection_AsciiString as string, if needed.

- Issue History
Date Modified Username Field Change
2020-04-23 13:44 sshutina New Issue
2020-04-23 13:44 sshutina Assigned To => nds
2020-04-23 15:06 sshutina Description Updated View Revisions
2020-04-23 15:07 sshutina Description Updated View Revisions
2020-04-23 15:07 sshutina Description Updated View Revisions
2020-04-23 15:15 sshutina Description Updated View Revisions
2020-04-23 15:26 sshutina Description Updated View Revisions
2020-04-23 19:17 nds Relationship added related to 0031516
2020-04-23 19:31 kgv Note Added: 0091751
2020-04-23 19:41 nds Priority normal => low
2020-04-23 19:41 nds Severity minor => feature
2020-09-18 07:38 abv Status new => closed
2020-09-18 07:38 abv Resolution open => no change required
2020-09-18 07:38 abv Target Version 7.5.0 =>


Copyright © 2000 - 2020 MantisBT Team
Powered by Mantis Bugtracker