Skip to content

Commit

Permalink
Ah! The no-negative-zero formatting qualifier is new in 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanhogg committed Jul 25, 2024
1 parent 2440bf2 commit 9f8bee8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/flitter/model.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,17 @@ cdef class Vector:
text += <str>objptr
elif isinstance(<object>objptr, (float, int)):
number= <object>objptr
text += SymbolTable.get(number, f'{number:z.9g}')
text += SymbolTable.get(number, f'{number:.9g}')
elif isinstance(<object>objptr, Node):
text += (<Node>objptr).kind
elif callable(<object>objptr) and hasattr(<object>objptr, '__name__'):
text += (<object>objptr).__name__
elif n:
for i in range(n):
text += SymbolTable.get(self.numbers[i], f'{self.numbers[i]:z.9g}')
if self.numbers[i] == 0:
text += "0"
else:
text += SymbolTable.get(self.numbers[i], f'{self.numbers[i]:.9g}')
return text

def __iter__(self):
Expand Down Expand Up @@ -653,13 +656,16 @@ cdef class Vector:
cdef str symbol
if self.numbers != NULL:
for i in range(n):
symbol = SymbolTable.get(self.numbers[i])
parts.append(':' + symbol if symbol is not None else f'{self.numbers[i]:z.9g}')
if self.numbers[i] == 0:
parts.append("0")
else:
symbol = SymbolTable.get(self.numbers[i])
parts.append(':' + symbol if symbol is not None else f'{self.numbers[i]:.9g}')
else:
for obj in self.objects:
if isinstance(obj, (float, int)):
symbol = SymbolTable.get(obj)
parts.append(':' + symbol if symbol is not None else f'{obj:z.9g}')
parts.append(':' + symbol if symbol is not None else f'{obj:.9g}')
elif isinstance(obj, str):
parts.append(repr(<str>obj))
else:
Expand Down

0 comments on commit 9f8bee8

Please sign in to comment.