Skip to content

Weird truncation with printf %g #952

@stephane-chazelas

Description

@stephane-chazelas
$ ksh -c 'printf "%.30g\n" 1e{10..31}'
10000000000
100000000000
1000000000000
10000000000000
100000000000000
1000000000000000
10000000000000000
100000000000000000
100000000000000000
100000000000000000
100000000000000000
100000000000000000
100000000000000000
100000000000000000
100000000000000000
100000000000000000
100000000000000000
100000000000000000
100000000000000000
100000000000000000
1e+30
1e+31

Same with typeset -E:

$ ksh -c 'typeset -E30 i; for i in 1e{10..31}; do print "$i"; done'
10000000000
100000000000
1000000000000
10000000000000
100000000000000
100000000000000
100000000000000
100000000000000
100000000000000
100000000000000
100000000000000
100000000000000
100000000000000
100000000000000
100000000000000
100000000000000
100000000000000
100000000000000
100000000000000
100000000000000
1e+30
1e+31

With both:

$ ksh --version
  version         sh (AT&T Research) 93u+m/1.0.10 2024-08-01

on Debian testing amd64 and current git head:

$ ksh --version
  version         sh (AT&T Research) 93u+m/1.1.0-alpha+de24bb01 2026-03-23

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is not working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions