Skip to content

Normalization of number in scientific notation in pgfmath #1444

Description

@Rmano

This is probably not a bug, but it is quite a surprising thing (disclaimer: probably it is a case of "don't do that", but just to document it...

When using scientific notation, it would be nice to normalize the mantissa before the final conversion. The example below shows the problem:

\documentclass{article}
\usepackage{pgf}
\begin{document}
\pgfmathparse{500e-6}\pgfmathresult{} vs \pgfmathparse{5e-4}\pgfmathresult
\end{document}
Image

This is doubly surprising if you do that inside a pgfplot environment, because in that case the addplot works (I understand it is because it's using some fpu) and the \pgfmathparse not:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\begin{document}
    %% use 0.0005 or 0.5e.3 and it works
    \newcommand{\valueB}{500e-6}%
    % \newcommand{\valueB}{0.5e-3}%
    \begin{tikzpicture}[declare function={
        NL(\t)=4 + 0.03*(\t) - \valueB*((\t-50)^2);}
    ]
    \begin{axis}[ xmin=0, xmax=90, domain=0:80, ]
        \addplot[color=red, ultra thick] {NL(x)}; % works always
        \pgfmathsetmacro{\Value}{NL(20)} % fails with \valueB 500e-6
        \node [draw,pin=above:\Value] at (20, \Value) {};
    \end{axis}
    \end{tikzpicture}
\end{document}
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions