Opened 4 weeks ago

Closed 4 weeks ago

#28730 closed Bug (fixed)

Large integer literals lose precision in templates

Reported by: Fraser Nevett Owned by: nobody
Component: Template system Version: master
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 Changed 4 weeks ago by Fraser Nevett

Type: UncategorizedBug

comment:2 Changed 4 weeks ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:3 Changed 4 weeks ago by Claude Paroz

Has patch: set
Version: 1.11master

comment:4 Changed 4 weeks ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:5 Changed 4 weeks ago by Claude Paroz <claude@…>

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