Understand limitations of floating point representations.Never check for equality with ==. Instead, check if the difference is less than an epsilon value.

public class Line{
static double epsilon=0.000001;
public double slope;
public double yintersect; public Line(double s, double y){
slope=s;
yintersect=y;
} public boolean intersect(Line line2){
return Math.abs(slope-line2.slope)>epsilon||
Math.abs(yintersect-line2.yintersect)<epsilon;
}
}

  

Float Equal Problem的更多相关文章

  1. ural 1433. Diamonds

    1433. Diamonds Time limit: 1.0 secondMemory limit: 64 MB Sasha is lucky to have a diamond in the for ...

  2. js实现省市区联动

    先来看看效果图吧,嘻嘻~~~~~~~~~~~~~~~~~~~· 代码在下面: 示例一: html: <!DOCTYPE html> <html> <head> &l ...

  3. [LeetCode&Python] Problem 453. Minimum Moves to Equal Array Elements

    Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...

  4. C++ little errors , Big problem

    ---------------------------------------------------------------------------------------------------- ...

  5. POJ 3100:Root of the Problem

    Root of the Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12060   Accepted: 6 ...

  6. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  7. Manthan, Codefest 16(B--A Trivial Problem)

    B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. The Solution of UESTC 2016 Summer Training #1 Div.2 Problem B

    Link http://acm.hust.edu.cn/vjudge/contest/121539#problem/B Description standard input/output Althou ...

  9. C - NP-Hard Problem

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

随机推荐

  1. java笔试三

    请问如何不使用第三个变量交换两个变量值?     例如   int   a=5,b=10:     如何不使用第三个变量交换a,b的值? public class T { public static ...

  2. 暑假热身 D. 条形码设计

    校ACM队准备筹划向学校批请一个专用机房.但是为了防止它变成公用机房,FL建议采用刷卡进入的办法,她设计了一种条形码,每人都对应一个.这种大小为2*n的条形码由以下三种元素构成:1*2.2*1.2*2 ...

  3. ubuntu 12.04 server编译安装nginx

    tar -xvf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./config make make install above is for zlib(refers http:// ...

  4. 每天一个脚本解析day1==》《service xxxxx status》之service脚本解析

    vim    /sbin/service #!/bin/sh . /etc/init.d/functions #读取环境变量. VERSION="$(basename $0) ver. 0. ...

  5. 【Python】Django支持事务方式

    代码: with transaction.atomic(): for i in xrange(int(svc_instance_num)): tmp_fileprotect_svc_instance ...

  6. 【leetcode】Sort List

    Sort List Sort a linked list in O(n log n) time using constant space complexity.   需要采用归并排序对链表进行操作. ...

  7. linux(Ubuntu)安装QQ2013

    首先简述自己的系统配置:win7+ ubuntu12.04 linuxQQ 有各种版本,这里介绍两种:linuxQQ 和 wineQQ 1 ------linuxqq是QQ简化版,功能很少,界面很差, ...

  8. 【python】继承时注意事项

    1. __init__ 注意事项 如果父类有__init__函数,子类没有,则子类自动调用父类__init__函数 如果父类有__init__函数,子类也有,则子类必须主动调用父类__init__函数 ...

  9. JDK1.7 HashMap 源码分析

    概述 HashMap是Java里基本的存储Key.Value的一个数据类型,了解它的内部实现,可以帮我们编写出更高效的Java代码. 本文主要分析JDK1.7中HashMap实现,JDK1.8中的Ha ...

  10. stm32——Flash读写

    stm32——Flash读写 一.Flash简介 通过对stm32内部的flash的读写可以实现对stm32的编程操作. stm32的内置可编程Flash在许多场合具有十分重要的意义.如其支持ICP( ...