View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0031515 | Open CASCADE | OCCT:Foundation Classes | public | 2020-04-23 13:44 | 2020-09-18 07:38 |
Reporter | sshutina | Assigned To | nds | ||
Priority | low | Severity | feature | ||
Status | closed | Resolution | no change required | ||
Summary | 0031515: Incorrect conversion Standard_Real to TCollection_AsciiString and TCollection_ExtendedString | ||||
Description | Standard_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. | ||||
Tags | No tags attached. | ||||
Test case number | |||||
|
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. |
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 | |
2020-04-23 15:07 | sshutina | Description Updated | |
2020-04-23 15:07 | sshutina | Description Updated | |
2020-04-23 15:15 | sshutina | Description Updated | |
2020-04-23 15:26 | sshutina | Description Updated | |
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 |
|
Status | new => closed |
2020-09-18 07:38 |
|
Resolution | open => no change required |
2020-09-18 07:38 |
|
Target Version | 7.5.0 => |