IEEE 754:是否始终保证v * = -1与v = -v相同?

问题描述

标准(IEEE 754 / C)是否保证在以下代码声明中将永远不会失败?

int main()
{
    for ( /* all possible float / double values */ )
    {
        v_neg1 = v * -1;
        v_neg2 = -v;
        assert( v_neg1 == v_neg2 );
    }
    return 0;
}

UPD。

  1. 询问时,我的意思是all possible float / double values 包括NaNs
  2. 看到类似的问题:.NET decimal.Negate vs multiplying by -1

解决方法

不,这不一定是正确的,因为 NaNs 从不相互比较。

除此之外,考虑到符号位与指数和绝对有效位无关,我认为对于所有普通值来说都是正确的。 C指ISO / IEC 60559 / IEEE 754附录;不幸的是,我本人没有这个标准。

 flutter doctor --android-licenses
Error: Unknown argument --licenses
Usage: 
  sdkmanager [--uninstall] [<common args>] \
    [--package_file <package-file>] [<packages>...]
  sdkmanager --update [<common args>]
  sdkmanager --list [<common args>]

In its first form,installs,or uninstalls,or updates packages.
    <package> is a sdk-style path (e.g. "build-tools;23.0.0" or 
             "platforms;android-23").
    <package-file> is a text file where each line is a sdk-style path
                   of a package to install or uninstall.
    Multiple --package_file arguments may be specified in combination
     with explicit paths.
In its second form (with --update),currently installed packages are
    updated to the latest version.
In its third form,all installed and available packages are printed out.

Common Arguments:
    --sdk_root=<sdkRootPath>: Use the specified SDK root instead of the SDK containing this tool
    --channel=<channelId>: Include packages in channels up to <channelId>.
                           Common channels are:
                           0 (Stable),1 (Beta),2 (Dev),and 3 (Canary).

    --include_obsolete: With --list,show obsolete packages in the
                        package listing. With --update,update obsolete                                                                                                                                          
                        packages as well as non-obsolete.                                                                                                                                                        
    --no_https: Force all connections to use http rather than https.                                                                                                                                             
    --proxy=<http | socks>: Connect via a proxy of the given type.                                                                                                                                               
    --proxy_host=<IP or DNS address>: IP or DNS address of the proxy to use.                                                                                                                                     
    --proxy_port=<port #>: Proxy port to connect to.                                                                                                                                                             
                                                                                                                                                                                                                 
* If the env var REPO_OS_OVERRIDE is set to "windows","macosx",or "linux",packages will be downloaded for that OS.