Opened 7 years ago

Closed 7 years ago

#28730 closed Bug (fixed)

Large integer literals lose precision in templates

Reported by: Fraser Nevett Owned by: nobody
Component: Template system Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

While looking at #28721, I realised that there is loss of precision on large integer literals:

>>> from django.template import Template, Context
>>> Template('{{ 999999999999999999999999999 }}').render(Context())
u'1000000000000000013287555072'

This happens because the code tries to first convert literal values to a float and then from the float to an int, which is a lossy operation.

Change History (5)

comment:1 by Fraser Nevett, 7 years ago

Type: UncategorizedBug

comment:2 by Tim Graham, 7 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Claude Paroz, 7 years ago

Has patch: set
Version: 1.11master

comment:4 by Tim Graham, 7 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Claude Paroz <claude@…>, 7 years ago

Resolution: fixed
Status: newclosed

In 9ec7d8e:

Fixed #28730 -- Fixed loss of precision for large integer literals in templates

Thanks Fraser Nevett for the report and Tim Graham for patch edits.

Note: See TracTickets for help on using tickets.
Back to Top