标签: fmodf

相当于C#中的fmodf?

C++ C中:输出:"1610612736"

#include <math.h>
#include <stdio.h>

int main(int argc, char** argv)
{
    printf("%d\n", fmodf(5.6f, 6.4f));
    getchar();
}
Run Code Online (Sandbox Code Playgroud)

在C#中:输出:"5.6"

using System;

static class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine(5.6f % 6.4f);
        Console.Read();
    }
}
Run Code Online (Sandbox Code Playgroud)

显然输出不一样.建议?

c c# fmodf

2
推荐指数
1
解决办法
1380
查看次数

float fmodf(float_x,float_y)函数,math.h,c ++

你好,我希望有人可以帮助我.

我正在使用math.h中的float fmodf(float_x,float_y)函数.

我能够正确编码,但我只是想知道有没有人知道函数的确切代码是什么,所以我可以更好地理解它

c++ floating-point math.h modulus fmodf

2
推荐指数
1
解决办法
861
查看次数

modf以小数形式返回1:

我有这个静态方法,它接收一个double并"切割"它的小数尾部,在点之后留下两位数.工程几乎所有的时间.我注意到当它收到2.3时它会变成2.29.0.3,1.3,3.3,4.3和102.3不会发生这种情况.代码基本上将数字乘以100使用modf将整数值除以100并返回它.这里代码捕获了这个特定的数字并打印出来:

static double dRound(double number) {

    bool c = false;
    if (number == 2.3)
        c = true;


    int factor = pow(10, 2);
    number *= factor;


    if (c) {
        cout << " number *= factor : " << number << endl;
        //number = 230;// When this is not marked as comment the code works well.
    }


    double returnVal;
    if (c){
        cout << " fractional : " << modf(number, &returnVal) << endl;
        cout << " integer : " <<returnVal << …
Run Code Online (Sandbox Code Playgroud)

c++ double integer fractions fmodf

1
推荐指数
1
解决办法
907
查看次数

获得数字的分数部分的最佳方法

鉴于const auto foo = 13.42我想得到数字小数部分,所以.42

我倾向于使用fmod像:fmod(foo, 1.0)

但我也可以做foo / static_cast<int>(foo) - 1.0或者或许其他一些神秘的方法.

我不会简单地使用动机fmod吗?

c++ decimal modulo fractions fmodf

0
推荐指数
1
解决办法
193
查看次数

modf无法正常工作

如果小数部分的前3位数字包含"9",则此代码应显示,但不起作用.令人惊讶的是,"mod"变量对于任何数字都是0.

int main( void )
{
    float number, dmod;
    int mod;
    double digit_1, digit_2, digit_3;
    double search=9;

    cout<<"Enter the number:";
    cin>>number;

    mod = modf(number, &dmod);
    digit_1 = mod /100 % 10;
    digit_2 = mod /10  % 10;
    digit_3 = mod /1   % 10;

    if( (digit_1 == search) || (digit_2 == search) || (digit_3 ==search) )
    {
        cout<<"mod contains 9"<<endl;
    }
    else
    {
        cout<<"mod does not contains 9"<<endl;
    }
 }
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++ fmodf

0
推荐指数
1
解决办法
560
查看次数

标签 统计

fmodf ×5

c++ ×4

fractions ×2

c ×1

c# ×1

decimal ×1

double ×1

floating-point ×1

integer ×1

math.h ×1

modulo ×1

modulus ×1

visual-c++ ×1