转身以后

文章 评论 浏览 29

转身以后 2025-02-20 18:55:24

是的对话框与活动配对 - 如果您在活动中打开对话框,并且将此活动移至背景,则将随着活动删除对话框,如果您将活动移回前景对话框,则会在活动中显示。
因此,如果您显示对话框,则应等待打开其他活动。

Yes dialogs is paired with activity - if you open dialog in activity and you move this activity to background, dialog will be removed with activity and if you move your activity back to foreground dialog will be showed with activity.
So if you show dialog you should wait with opening another activity.

材料对话框突然关闭,然后进入Android Kotlin的另一项活动

转身以后 2025-02-20 12:55:15

debounce被调用一次。然后,每次释放关键的内部函数都会调用。

您可以通过在debounce中添加console.log通过

传递给addeventListenerdebounce

当您初始化侦听器时,还只能创建一次内部功能。每次侦听器发射时,此功能都会被调用。

The debounce is called once. Then each time you release the key inner function is called.

You can check this by adding a console.log inside the debounce

The second argument that is passed to addEventListener is the inne function of the debounce

Inner function is also created only once when you initialize the listener. This function is just called every time listener fires.

返回的内部函数如何引用相同的外部函数变量,即使外部函数多次触发?

转身以后 2025-02-20 08:01:31

使用 js.dart 用于Web。例如这样的事情:

@JS()
library main;

import 'package:js/js.dart';

@JS('console.log') // annotates `log` function to call `console.log`
external void log(dynamic str);

void main() {
  log('Hello world!');
}

Use js.dart for web. For example something like this:

@JS()
library main;

import 'package:js/js.dart';

@JS('console.log') // annotates `log` function to call `console.log`
external void log(dynamic str);

void main() {
  log('Hello world!');
}

在Web应用程序中执行JavaScript代码Flutter Dart

转身以后 2025-02-19 04:45:01

如果只有线路就足够了,您只需为行图制作一个传说

https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.axes.axes.legend.html

def plot_en(filename):

    data_0 = np.loadtxt(f"{filename[0]}.en")
    data_1 = np.loadtxt(f"{filename[1]}.en")


    fig, (ax0, ax1) = plt.subplots(1, 2)

    plt.subplots_adjust(top = 1, bottom = 0.08, left = 1.5, right = 3.5, hspace = 0.25, wspace = 0.35)

    # Option 1 (annotate the plot)
    plot0,_ = ax0.plot(data_0[:, 0], data_0[:, 1])
    plot1,_ = ax1.plot(data_1[:, 0], data_1[:, 1])

    ax0.set(xlabel="step", ylabel="time")
    ax1.set(xlabel="step", ylabel="time")

    ax0.legend([plot0], ["Admitted"])  
    ax1.legend([plot1], ["Not_Admitted"])

    # Option 2 (directly pass label)
    ax0.plot(data_0[:, 0], data_0[:, 1], label="Admitted")
    ax1.plot(data_1[:, 0], data_1[:, 1], label="Not_Admitted")

    ax0.set(xlabel="step", ylabel="time")
    ax1.set(xlabel="step", ylabel="time")

    ax0.legend()
    ax1.legend()

plot_en(["forward0-on", "forward1-on"])

If just the line plot is enough for you just make a legend for the line plot

https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.legend.html

def plot_en(filename):

    data_0 = np.loadtxt(f"{filename[0]}.en")
    data_1 = np.loadtxt(f"{filename[1]}.en")


    fig, (ax0, ax1) = plt.subplots(1, 2)

    plt.subplots_adjust(top = 1, bottom = 0.08, left = 1.5, right = 3.5, hspace = 0.25, wspace = 0.35)

    # Option 1 (annotate the plot)
    plot0,_ = ax0.plot(data_0[:, 0], data_0[:, 1])
    plot1,_ = ax1.plot(data_1[:, 0], data_1[:, 1])

    ax0.set(xlabel="step", ylabel="time")
    ax1.set(xlabel="step", ylabel="time")

    ax0.legend([plot0], ["Admitted"])  
    ax1.legend([plot1], ["Not_Admitted"])

    # Option 2 (directly pass label)
    ax0.plot(data_0[:, 0], data_0[:, 1], label="Admitted")
    ax1.plot(data_1[:, 0], data_1[:, 1], label="Not_Admitted")

    ax0.set(xlabel="step", ylabel="time")
    ax1.set(xlabel="step", ylabel="time")

    ax0.legend()
    ax1.legend()

plot_en(["forward0-on", "forward1-on"])

使用MATPLOT标记子图

转身以后 2025-02-18 18:04:59
<EditText
android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="fintme"
android:inputType="text"
android:imeOptions="actionSend" />

EditText editText = (EditText) findViewById(R.id.edittext);
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    boolean handled = false;
    if (actionId == EditorInfo.IME_ACTION_SEND) {
        //yourcode
        handled = true;
    }
    return handled;
  }
});
<EditText
android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="fintme"
android:inputType="text"
android:imeOptions="actionSend" />

EditText editText = (EditText) findViewById(R.id.edittext);
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    boolean handled = false;
    if (actionId == EditorInfo.IME_ACTION_SEND) {
        //yourcode
        handled = true;
    }
    return handled;
  }
});

如何使用键盘操作Appium Android按绿色tick按钮

转身以后 2025-02-18 13:10:50

使用,则可以在dplyr本身中完成。

library(dplyr)
mtcars <-  mtcars %>% 
    mutate(across(all_of(col_names), rcompanion::blom, method = "blom"))

如果我们跨 output

> head(mtcars)
                         mpg        cyl        disp         hp       drat          wt       qsec         vs         am       gear
Mazda RX4          0.2353289 -0.1168527 -0.23532887 -0.2754823  0.3989603 -0.62056827 -0.9368471 -0.5741128  0.8223940  0.3989603
Mazda RX4 Wag      0.2353289 -0.1168527 -0.23532887 -0.2754823  0.3989603 -0.35721583 -0.4846749 -0.5741128  0.8223940  0.3989603
Datsun 710         0.6684036 -0.9368471 -0.93684711 -0.8223940  0.2754823 -0.82239396  0.5288648  0.7690553  0.8223940  0.3989603
Hornet 4 Drive     0.3989603 -0.1168527  0.11685275 -0.2754823 -0.6684036 -0.03887224  0.8223940  0.7690553 -0.5288648 -0.7178201
Hornet Sportabout -0.1168527  0.7690553  0.99892823  0.3572158 -0.4846749  0.19555148 -0.4846749 -0.5741128 -0.5288648 -0.7178201
Valiant           -0.1955515 -0.1168527  0.03887224 -0.5288648 -1.8134176  0.35721583  1.6411071  0.7690553 -0.5288648 -0.7178201
                        carb id
Mazda RX4          0.7690553  1
Mazda RX4 Wag      0.7690553  2
Datsun 710        -1.2138469  3
Hornet 4 Drive    -1.2138469  4
Hornet Sportabout -0.3160850  5
Valiant           -1.2138469  6

This could be done within dplyr itself if we use across

library(dplyr)
mtcars <-  mtcars %>% 
    mutate(across(all_of(col_names), rcompanion::blom, method = "blom"))

-output

> head(mtcars)
                         mpg        cyl        disp         hp       drat          wt       qsec         vs         am       gear
Mazda RX4          0.2353289 -0.1168527 -0.23532887 -0.2754823  0.3989603 -0.62056827 -0.9368471 -0.5741128  0.8223940  0.3989603
Mazda RX4 Wag      0.2353289 -0.1168527 -0.23532887 -0.2754823  0.3989603 -0.35721583 -0.4846749 -0.5741128  0.8223940  0.3989603
Datsun 710         0.6684036 -0.9368471 -0.93684711 -0.8223940  0.2754823 -0.82239396  0.5288648  0.7690553  0.8223940  0.3989603
Hornet 4 Drive     0.3989603 -0.1168527  0.11685275 -0.2754823 -0.6684036 -0.03887224  0.8223940  0.7690553 -0.5288648 -0.7178201
Hornet Sportabout -0.1168527  0.7690553  0.99892823  0.3572158 -0.4846749  0.19555148 -0.4846749 -0.5741128 -0.5288648 -0.7178201
Valiant           -0.1955515 -0.1168527  0.03887224 -0.5288648 -1.8134176  0.35721583  1.6411071  0.7690553 -0.5288648 -0.7178201
                        carb id
Mazda RX4          0.7690553  1
Mazda RX4 Wag      0.7690553  2
Datsun 710        -1.2138469  3
Hornet 4 Drive    -1.2138469  4
Hornet Sportabout -0.3160850  5
Valiant           -1.2138469  6

purrr将功能映射到除一个列以外的所有列

转身以后 2025-02-17 12:11:36

如果假API在这里称呼更多名称,该怎么办?在完成API调用之前,UpdateNames函数已被调用。

updateNames才能调用,直到完成callapi#函数完成; 等待使代码块(将控件回到事件循环中),直到两个承诺(当功能是async本身时,明确创建或隐含)完成。

如果所讨论的功能不返回承诺,请同步/热切执行,则等待Promise.all([...])是毫无意义的(没有涉及的承诺),但仍然没有updateNames的风险在callapi#呼叫完成之前被调用;要么:

  1. callapi#返回承诺(在这种情况下等待阻止当前任务,直到他们完成,在等待时将控件返回到事件循环)或
  2. callapi #不会返回承诺,所有工作都立即完成

,无论哪种情况,您都无法在完成之前UpdateNames

在这种情况下,我不想 block 让它同步吗?

等待阻止当前功能调用/任务。 其他在事件循环中安排的任务可以运行,而等待仍被阻止,这是异步处理的优势。 JavaScript中的每个显然异步的东西都共享该事件循环,如果您完全阻止(而不是等待异步调用),则它们都无法运行。例如,这意味着:

  1. settimeout/setInterval呼叫不射击
  2. UI绘图操作不会发生
  3. 用户输入,并阻止了
  4. 所有事件,并且观察者处理代码被推迟了

真正同步呼叫将使该(以及更多)的所有等待foo完成。这就是为什么有时将异步代码称为“合作多任务处理”的原因;没有像您在多线程代码中看到的那样,控制控制权永远不会脱离当前任务,而是将控制权自愿回到事件循环(通过等待)。处理,或任务完成时。当异步任务具有结果时,它会等待事件循环将控制权交给它,然后继续将其关闭。

What if the fake API calls here pushed more names to the array? The updateNames function would be called already before the api calls would be done.

updateNames would not be called until both of the callAPI# functions completed; the await makes the code block (yielding control back to the event loop) until both promises (explicitly created or implicit when the functions are async themselves) complete.

If the functions in question don't return promises, executing synchronously/eagerly, then the await Promise.all([...]) is pointless (there were no promises involved), but there's still no risk of updateNames being called before the callAPI# calls finish; either:

  1. callAPI# returns a promise (in which case await blocks the current task until they complete, returning control to the event loop while it waits), or
  2. callAPI# does not return a promise and all the work is done immediately

and in either case, you can't get to updateNames before they finish.

Wouldn't I want to block the runtime in this case and make it synchronous?

You are blocking the current function call/task with the await. Other tasks scheduled on the event loop can run while the await is still blocked though, and that's the advantage to async processing. Every apparently asynchronous thing in JavaScript is sharing that event loop, and if you completely blocked (rather than awaiting an async call), none of them could run. This means, for example:

  1. setTimeout/setInterval calls don't fire
  2. UI drawing operations don't occur
  3. User input is blocked
  4. All events and observer handling code is deferred

Truly synchronous calls would make all of that (and more) wait until the entirety of foo completed. This is why async code is sometimes referred to as "cooperative multitasking"; control is never wrested away from the current task without its consent like you'd see in multithreaded code, instead control is handed back to the event loop voluntarily (via await) whenever a task is blocked waiting on asynchronous processing, or when the task completes. When the async task has a result, it waits for the event loop to hand control back to it, then continues where it left off.

JS:调用API时的异步/等待好处是什么?

转身以后 2025-02-17 04:11:12

感谢 @mike Organek的评论,通过将格式从CSV切换到文本,我的问题已经解决了。现在,当我将转储文件名封闭在双引号中时,输出更多是预期的,并且按预期工作。现在唯一奇怪的是,在输出中,它在文件名中创建了第二个后斜线。我的代码已更新如下:

COPY (SELECT 'pg_dump '|| datname || ' > "e:\postgresbackups\FULL\' || datname || '_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%_%time:~3,2%_%time:~6,2%.dump"' FROM pg_database) TO 'E:\PostgresBackups\Script\FULL_Postgres_Backup_Job.bat' (format text, delimiter ';');

在BAT文件中创建的输出的一个示例如下:

pg_dump postgres > "e:\\postgresbackups\\FULL\\postgres_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%_%time:~3,2%_%time:~6,2%.dump"

如您所见,它添加了双重倾斜;但是,pg_dump成功执行!

Thanks to @Mike Organek's comment, my issue has been resolved by switching the format from CSV to TEXT. Now when I enclose the dump filename in double quotes, the output is more of what is expected and works as intended. The only odd thing now is that in the output it creates a second backslash in the filename. My code has been updated as follows:

COPY (SELECT 'pg_dump '|| datname || ' > "e:\postgresbackups\FULL\' || datname || '_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%_%time:~3,2%_%time:~6,2%.dump"' FROM pg_database) TO 'E:\PostgresBackups\Script\FULL_Postgres_Backup_Job.bat' (format text, delimiter ';');

An example of the output that gets created within the bat file is as follows:

pg_dump postgres > "e:\\postgresbackups\\FULL\\postgres_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%_%time:~3,2%_%time:~6,2%.dump"

As you can see, it adds a double backslash; however, the pg_dump executes successfully!

Postgres复制输出带有双重报价,添加了超出所需的内容

转身以后 2025-02-17 02:25:25

您可以使用Flex属性来解决此问题。您将拥有一个父母Div,其中包含所有三个孩子的物品。根据您的HTML代码中项目的位置,内容将证明其相应的方面是合理的。因此,如果它是第一个,则将是合理的。如果是第二个,它将是合理的。如果是第三个,它将是合理的。这是您将如何做的;

#bar {
  display: flex;
}

#bar>* {
  flex: 1;
  display: flex;
}

#bar> :nth-child(1) {
  justify-content: flex-start;
}

#bar> :nth-child(2) {
  justify-content: center;
}

#bar> :nth-child(3) {
  justify-content: flex-end;
}
<div id="bar">
  <p>Left</p>
  <p>Middle</p>
  <p>Right</p>
</div>

You could use the flex property to solve this. You would have a parent div which contains all 3 of your children items. Depending on where the item is in your HTML code, the content will justify to its respective side. So if it's the first, it will be justified to the left. If it's the second, it will be justified to the middle. And if it's the third, it will be justified to the right. Here is how you would do it;

#bar {
  display: flex;
}

#bar>* {
  flex: 1;
  display: flex;
}

#bar> :nth-child(1) {
  justify-content: flex-start;
}

#bar> :nth-child(2) {
  justify-content: center;
}

#bar> :nth-child(3) {
  justify-content: flex-end;
}
<div id="bar">
  <p>Left</p>
  <p>Middle</p>
  <p>Right</p>
</div>

卡住。我如何居中并置于这三个文本?

转身以后 2025-02-17 01:32:51

我已经测试了您的代码,在大多数情况下似乎还不错。

It seems to be a problem with the abi belonging to the contract you're interacting with, since the code works successfully on, example these hashes (randomly selected from ethscan):

0xb670ab16162f8e4b00cbd57175b0dfb0025690b79a31876d802af84bcc793246
0x4BB2E49BF8965B6ACDF5C1B7C18E88E811A0E4704A6C37775D743CD8304054ADEA9

我做了一些谷歌搜索,并在此线程中遇到了相同的问题:

-DECODE-INPUT-DATA-使用web3-py-using-the-decode-function-inp”> https://ethereum.stackexchange.com/questions/70340/how-exactly-do-do-you-decode-inpode-input-data-data-using-web3-py - 使用Decode-function-inp

对不起,我无法为您提供一个问题的解决方案,但我希望它将您指向正确的方向!

I have tested your code and it seems fine in most cases.

It seems to be a problem with the abi belonging to the contract you're interacting with, since the code works successfully on, example these hashes (randomly selected from ethscan):

0xb670ab16162f8e4b00cbd57175b0dfb0025690b79a31876d802af84bcc793246
0x4bb2e49bf8965b6acdf5c1b7c18e8811a0e4704a6c3775d743cd8304054adea9

i did some googling myself and came over this thread that states the same problem:

https://ethereum.stackexchange.com/questions/70340/how-exactly-do-you-decode-input-data-using-web3-py-using-the-decode-function-inp

Sorry i couldnt give you an exact solution to the problem but i hope it points you in the right direction!

func_obj,func_params解码以太坊交易时没有响应

转身以后 2025-02-17 01:05:13

这里的问题是您在中间有screen.exitonclick()。这会生成另一个窗口,该窗口在执行screet.exitonclick()之后,该窗口被执行。您应该做的是将screen.exitonClick()放在最后。

import turtle as t

screen = t.Screen()
screen.title("My Snake Game")
screen.setup(width=600, height=600)
screen.bgcolor("black")



terry = t.Turtle(shape='square')
terry.color('white')
terry.goto(0, 0)
screen.exitonclick()

这将是代码。

The problem here is that you have the screen.exitonclick() in the middle. That generates another window that apears and desapears after screen.exitonclick() is executed. What you should do is to put screen.exitonclick() at the end.

import turtle as t

screen = t.Screen()
screen.title("My Snake Game")
screen.setup(width=600, height=600)
screen.bgcolor("black")



terry = t.Turtle(shape='square')
terry.color('white')
terry.goto(0, 0)
screen.exitonclick()

This would be the code.

我屏幕上的乌龟物体没有出现

转身以后 2025-02-16 23:55:49

这是将1:n关系作为n端上的外键的标准模式(因此您的情况下购买的客户ID)

通常也应该对此有一个索引,因此正在发生的查询(<代码>从购买中选择“ cunteruction = 123 )的count(*)”,以及您描述的(从购买ID中的ID中)(...,...,...,...)中的count(*))的性能不应大不相同。

此外:“存储购买ID的列表”要高效,您必须每个客户最大数量的购买,否则您将为每个客户提供所有购买的大型斑点。

总而言之,在这里信任,这种方法是行业标准。并在愿意的情况下添加反向导航属性。

It is the standard pattern to store a 1:n relation as a foreign key on the n-end (so a customer id in the purchase in your case)

Normally you should also have an index on that, so the query that's happening (select count(*) from purchase where customerId = 123) and the one you describe (select count(*) from purchase where Id in (..., ..., ...)) should not be dramatically different in performance.

Additionally: "store a list of purchase Id's" for this to be efficient, you must impose a maximum number of purchases per customer, otherwise you hve an arbitrary big blob for each customer with all its purchases.

All in all, trust EF here, the approach is industry standard. And add the reverse navigation property if you like.

为什么实体框架在外国实体中添加外国钥匙,这意味着什么?

转身以后 2025-02-16 13:02:51

我已经更新了逻辑以将对象推向数组并存储ID。

let serving_point_key = serving_points?.findIndex(sp => sp.socket_id === socket.id);

    if (serving_point_key === -1) {
        
        let id = null;
        if (serving_points.length === 0) {
            id = 1;
        } else {
            for( var i = 0; i < serving_points.length; i++ ) {
                let id_exists = (serving_points?.findIndex(sp => sp.id === (i + 1)) !== -1);
                if (id_exists === false) {
                    id = (i + 1);
                }
            }
            console.log(id);
            if (id === null) {
                id = serving_points.length + 1;
            }
        }

        let sp_data = {
            'id': id,
            'socket_id': socket.id
        }

        serving_points.push(sp_data);
        serving_point_key = serving_points?.findIndex(sp => sp.socket_id === socket.id);
    }
    let serving_point_id = serving_points[serving_point_key].id;

I've updated the logic to push an object to the array and store the ID.

let serving_point_key = serving_points?.findIndex(sp => sp.socket_id === socket.id);

    if (serving_point_key === -1) {
        
        let id = null;
        if (serving_points.length === 0) {
            id = 1;
        } else {
            for( var i = 0; i < serving_points.length; i++ ) {
                let id_exists = (serving_points?.findIndex(sp => sp.id === (i + 1)) !== -1);
                if (id_exists === false) {
                    id = (i + 1);
                }
            }
            console.log(id);
            if (id === null) {
                id = serving_points.length + 1;
            }
        }

        let sp_data = {
            'id': id,
            'socket_id': socket.id
        }

        serving_points.push(sp_data);
        serving_point_key = serving_points?.findIndex(sp => sp.socket_id === socket.id);
    }
    let serving_point_id = serving_points[serving_point_key].id;

JavaScript-将数据推向数组并删除时,如何将ID固定在数组中?

转身以后 2025-02-16 12:14:54

您可以做这样的事情:

import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors as mcol

cmap = mcol.ListedColormap(["blue","green","red"])

bounds = [0, 40, 60, 100]
norm = mcol.BoundaryNorm(bounds, cmap.N)

x=np.arange(100)
plt.scatter(x,x,c=x,cmap=cmap,norm=norm)
plt.show()

”输入图像在此处“在此处”

有关更多详细信息,请查看在这里

You can do something like this:

import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors as mcol

cmap = mcol.ListedColormap(["blue","green","red"])

bounds = [0, 40, 60, 100]
norm = mcol.BoundaryNorm(bounds, cmap.N)

x=np.arange(100)
plt.scatter(x,x,c=x,cmap=cmap,norm=norm)
plt.show()

enter image description here

For further details, take a look here:

matplotlib在散点图中自定义颜色

转身以后 2025-02-16 11:53:46

十进制数字,例如0.10.20.3,并未完全用二进制编码的浮点类型表示。 0.10.2的近似值与用于0.3的近似值不同,因此0.1 + 0.2 == 0.3在这里可以更清楚地看到:

#include <stdio.h>

int main() {
    printf("0.1 + 0.2 == 0.3 is %s\n", 0.1 + 0.2 == 0.3 ? "true" : "false");
    printf("0.1 is %.23f\n", 0.1);
    printf("0.2 is %.23f\n", 0.2);
    printf("0.1 + 0.2 is %.23f\n", 0.1 + 0.2);
    printf("0.3 is %.23f\n", 0.3);
    printf("0.3 - (0.1 + 0.2) is %g\n", 0.3 - (0.1 + 0.2));
    return 0;
}

输出:

0.1 + 0.2 == 0.3 is false
0.1 is 0.10000000000000000555112
0.2 is 0.20000000000000001110223
0.1 + 0.2 is 0.30000000000000004440892
0.3 is 0.29999999999999998889777
0.3 - (0.1 + 0.2) is -5.55112e-17

为了更可靠地评估这些计算,您需要使用基于小数的表示浮点值。 C标准不默认指定此类类型,而是按A 技术报告

_decimal32_decimal64_decimal128类型可以在您的系统上使用(例如,选定的目标,但是 clang clang 不支持它们on os&nbsp; x )。

Decimal numbers such as 0.1, 0.2, and 0.3 are not represented exactly in binary encoded floating point types. The sum of the approximations for 0.1 and 0.2 differs from the approximation used for 0.3, hence the falsehood of 0.1 + 0.2 == 0.3 as can be seen more clearly here:

#include <stdio.h>

int main() {
    printf("0.1 + 0.2 == 0.3 is %s\n", 0.1 + 0.2 == 0.3 ? "true" : "false");
    printf("0.1 is %.23f\n", 0.1);
    printf("0.2 is %.23f\n", 0.2);
    printf("0.1 + 0.2 is %.23f\n", 0.1 + 0.2);
    printf("0.3 is %.23f\n", 0.3);
    printf("0.3 - (0.1 + 0.2) is %g\n", 0.3 - (0.1 + 0.2));
    return 0;
}

Output:

0.1 + 0.2 == 0.3 is false
0.1 is 0.10000000000000000555112
0.2 is 0.20000000000000001110223
0.1 + 0.2 is 0.30000000000000004440892
0.3 is 0.29999999999999998889777
0.3 - (0.1 + 0.2) is -5.55112e-17

For these computations to be evaluated more reliably, you would need to use a decimal-based representation for floating point values. The C Standard does not specify such types by default but as an extension described in a technical Report.

The _Decimal32, _Decimal64 and _Decimal128 types might be available on your system (for example, GCC supports them on selected targets, but Clang does not support them on OS X).

浮点数学破裂了吗?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文