Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Welcome to SUnits

SUnits is a Units Calculator.

Current version: 6.3

Written by: saiba

License: GPLv2

Screenshot

Installation

No installation required, single exe file. Download SUnits (Console version)

NOTE: Sometimes downloaded file name does not have ".exe" extension. In that case, please append ".exe" to the downloaded file name to make it an executable.

Features

  • Uses matlab like command prompt.
  • Useful for converting units in "complex" form, like N/m -> lbf/in or N*m*s/rad -> lbf*in*s/deg.
  • Fractional powers for units, eg: time = (2*m / g_acc)^1|2
  • Addition of physical quantities, eg: distance = 2*km + (2*km/hr)*5*min + 1/2*(1.3*m/s^2)*(5*min)^2
  • User defined units.
  • User defined functions.
  • GUI is in DFL

Examples

> ~ <- this character starts a comment
> distance = 23.5 * m
distance = 23.5 m

> time = 4.9 * s
time = 4.9 s

> speed = distance / time
speed = 4.79592 m / s

> speed_in_miles_per_hour = speed > mi/hr
speed_in_miles_per_hour = 10.7282

> temp_centigrade = 37.0 * dC
temp_centigrade = 37 dC

> temp_fahrenheit = dc2df(temp_centigrade)
temp_fahrenheit = 98.6 dF

> func time_period(len) { len :: m;  2 * pi * (len / g_acc)^1|2; }
function added: time_period(len)

> time_period(6*m)
ans = 4.91468 s

> ~ Base conversion, from base 10 to 16
> printInBase(16, 123.456)
@123.456_10 = @7b.74bc6a_16

ans = 123.456

> ~ Base conversion, from base 16 to 10
> @a2b3b4d_16
ans = 1.70605e+08

BNF

    translation-unit : statements

    statements       : ( statement EOS )+  

    EOS              :  ";" | "," | EOF 
        End-of-statement. If a statement is followed by ";", its value is 
        not echo-ed. EOF is end-of-file

    statement        : cmd | assign_expr | func_def | unit_def
        For available 'cmd' see at the end.

    assign_expr      : (var ( "=" | ":=" ) )? dim_chk_expr 
        Assignment expression. Operator ":=" ensures that the variable "var"
        is not defined earlier.

    dim_chk_expr     : conv_expr ( (":" | "::") mul_expr)?
        Dimension check expression,
        Operator ":"  Checks if conv_expr is dimensionless or conv_expr and 
        mul_expr have same dimensions, 
        Operator "::"  Checks if conv_expr conv_expr and mul_expr have 
        strictly same dimensions, 
        Returns conv_expr. Useful to ensure dimensions of intermediate steps.

    conv_expr        : add_expr ( (">" | "->" | "<" | "<-") add_expr)*
        Conversion expression,
        ">" and "<" are not comparision operators, but conversion operators
        defined as follows:
        a > b = a/b 
        a < b = b/a
        "<-" and "->" are same as "<" and ">", but prints pretty equation. 

    add_expr         : mul_expr ( ("+" | "-") mul_expr)* 

    mul_expr         : pow_expr ( ("*" | "/") pow_expr)*

    unary_expr       : ("-" | "+" | "#" | "$")? pow_expr
         Operator "#" is non-dimensionalizing operator, strips all dimensions
         and makes the expression dimensionless. Operator "$" makes the 
         magnitude unity.

    pow_expr         : pri_expr ("^" exp_expr)?

    pri_expr         : real_no | real_any_base | var | func_call | paran_expr

    func_call        : var ( "(" func_call_args ")" )+
                       function var is called repeatedly for all sets of 
                       arguments. Returned value is the return value from the
                       last call.

    func_call_args   : ( dim_chk_expr ( "," dim_chk_expr )* )*

    paran_expr       : "(" conv_expr ")"

    exp_expr         : unary_int ( "|" unary_int )?
        Currently only integer or integer ratios in p|q form are allowed 
        in exponents. Floating point values are not allowed in exponents,
        as it makes comparing dimensions harder.         
        For example 2.3^4.5 is not allowed, it can be written as 2.3^9|2
        Please note that "|" used in exponent not "/".

    unary_int        : ("-" | "+")? int_no

    real_any_base    : "@" float_any_base ( "_" int_no )?
                       real_any_base is an float literal, value is specified by 
                       float_any_base after "@" in base specified after "_".

    float_any_base   : [0-9a-zA-Z]+ ("." [0-9a-zA-Z]+)?
                       Upto base 36 can be represented using above alphabets.

    int_no           : [0-9]+ 

    func_def         : ( "func"  | "funcdef" ) var "(" func_def_args ")" 
                       "{" statements "}" ( description )?
        Function call always returns the last assign_expr value.
        Using "funcdef" ensures that the "var" is not defined earlier.

    func_def_args    : ( var ( "," var )* )?

    unit_def         : "newunit" var ( description )?
        Create new fundamental unit

    var              : C identifier
    var_name         : C identifier
    real_no          : C floating point number
    description      : any string not containing statement_end
    cmd              : described below

    cmd:
    ====

    delete   var     : deletes a variable var from memory
    precision int    : set display precision of floats, default 6.
    catagory  cat    : set catagory for subsequently defined variables
    defof            : show definition and value of a variable
    cls              : clear screen
    about            : print info about the program
    doc              : print documentation
    examples         : print some examples

Note:
-----
o  Line comment starts with '~' until end of line.
o  If file sunits.units exist in current working directory, 
   it is read on start up.

Acknowledgments