def asFloatOrNone(val):
    """Converts floats, integers and string representations of either to floats.
    If val is "NaN" (case irrelevant) or "?" returns None.

    Raises ValueError or TypeError for all other values

    """

    # check for NaN first in case ieee floating point is in use
    # (in which case float(val) would return something instead of failing)

    if hasattr(val, "lower") and val.lower() in ("nan", "?"):
        return None
    else:
        return float(val)