Skip to content

Fix AssertionError in _float_to_nastran_string for three-digit exponents - #1580

Closed
smoltafet wants to merge 1 commit into
nschloe:mainfrom
smoltafet:fix/nastran-float-length
Closed

smoltafet wants to merge 1 commit into
nschloe:mainfrom
smoltafet:fix/nastran-float-length

Conversation

@smoltafet

Copy link
Copy Markdown

Fixes #1539.

_float_to_nastran_string formatted every value with a fixed precision of 11 and asserted the result fits the 16-character field. For values with a three-digit exponent and a full mantissa, e.g. -1.234567890123e-100 or 1.500000000001e308, the string is longer than 16 characters and writing the mesh died with an AssertionError.

The formatter now lowers the precision step by step until the string fits the requested field length, so extreme values lose a few digits instead of crashing the write. Output for ordinary values is unchanged. The length argument is also honored now (the assert hardcoded 16).

Added parametrized tests covering zero, ordinary values, and three-digit-exponent values, plus a short-field case. tests/test_nastran.py: 23 passed; the two test_reference_file failures are pre-existing on upstream main.

@smoltafet

Copy link
Copy Markdown
Author

Hi @nschloe, could you take a look at this when you get a chance? It fixes the Nastran writer crashing on values with three digit exponents. Tests pass locally. Thanks!

@smoltafet

Copy link
Copy Markdown
Author

closing this one, no traction. thanks anyway

@smoltafet smoltafet closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] assertion error in _nastran.py funtion _float_to_nastran_string

1 participant