Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#111 engineering_notation function

None
closed
nobody
display (1)
5
2015-01-19
2014-01-08
hugocoolens
No

It would be handy to have an engineering_notation function. Engineering notation is a version of scientific notation in which the powers of ten must be multiples of three. A few examples: 0.0001 should be converted to 100*10^6, 47000E-12 should be converted to 47*10^-9, 120000 should be converted to 120*10^3. Volker van Nek wrote some code which achieves this for single arguments but it would be better if it would also work for a list of arguments, just the same way as when you use float(x) and x consists of multiple arguments.

Here is Volker's code:
engineering_notation(f):=
block([s,e],
s : printf(false, "~e", f),
e : parse_string(substring(s, 1 + ssearch("E", s))),
e : e - mod(e,3),
s : ssubst(string(e), "#", "~,,,#h"),
ssubst("e", "b", printf(false, s, f)) )$

Discussion

  • Robert Dodier
    Robert Dodier
    2015-01-19

    • labels: --> display
    • status: open --> closed
    • Group: -->
     
  • Robert Dodier
    Robert Dodier
    2015-01-19

    This functionality is available in the share package engineering-format.lisp which you can load via load("engineering-format.lisp); and thereafter all floats are displayed as powers of 10 which are a multiple of 3. That package is available version 5.34 and later.