• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 04:53
CEST 10:53
KST 17:53
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12TL.net Map Contest #22 - Voting & Ladder Map Selection7Code S Season 2 (2026) - RO8 Preview8[ASL21] Finals Preview: Two Legacies21
Community News
ZeroSpace at Steam NextFest - Last free demo13Weekly Cups (June 8-14): Clem and Solar double, PTR tested0RSL: S6 Finals played at BlizzCon 202611Douyu Cup 2026: $20,000 Legends Event (June 26-28)10[BSL22] Non-Korean Championship from 13 to 28 June4
StarCraft 2
General
StarCraft II 5.0.16 PTR Patch Notes may 26th J188 – Nhà Cái Cá Cược Trực Tuyến Đẳng Cấp Châu Á Code S Season 2 (2026) - RO8 Preview Daily SC2 Player Grid - feedback wanted TL Poll: How do you feel about the 5.0.16 PTR balance changes?
Tourneys
Master Swan Open (Global Bronze-Master 2) GSL CK #4 20-21th June Crank Gathers Season 4: BW vs SC2 Team League Douyu Cup 2026: $20,000 Legends Event (June 26-28) Maestros of The Game 2 announcement and schedule !
Strategy
[G] Having the right mentality to improve
Custom Maps
Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
Mutation # 530 One For All The PondCast: SC2 News & Results Mutation # 529 Opportunities Unleashed Mutation # 528 Infection Detected
Brood War
General
Fact based Zerg Upgrade Tier List vespene.gg — BW replays in browser BGH Auto Balance -> http://bghmmr.eu/ Data needed BW General Discussion
Tourneys
[Megathread] Daily Proleagues CSLAN 4 is Coming! Small VOD Thread 2.0 The Casual Games of the Week Thread
Strategy
Simple Questions, Simple Answers Relatively freeroll strategies Creating a full chart of Zerg builds Why doesn't anyone use restoration?
Other Games
General Games
ZeroSpace at Steam NextFest - Last free demo Nintendo Switch Thread Path of Exile Stormgate/Frost Giant Megathread ZeroSpace Megathread
Dota 2
Looking for a Dota Mentor Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
Vanilla Mini Mafia {D-2} Late to making 20.06.2026 memorable [p]94718
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread [H]Internet/Gaming Cafe Tips and Tricks The Games Industry And ATVI UK Politics Mega-thread
Fan Clubs
The HerO Fan Club! The herO Fan Club!
Media & Entertainment
Movie Discussion! [Req][Books] Good Fantasy/SciFi books [TV/BOOK] *SPOILERS* Game of Thrones Discussion
Sports
2024 - 2026 Football Thread McBoner: A hockey love story TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion Cricket [SPORT]
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread Facing Challenges in Mobile App Development
TL Community
The Automated Ban List
Blogs
How To Predict Tilt in Espor…
TrAiDoS
An Exploration of th…
waywardstrategy
I'm an arrogant trash talke…
FlaShFTW
Gauntlet SC2: A Retrospectiv…
Ctone23
Why RTS gamers make better f…
gosubay
Customize Sidebar...

Website Feedback

Closed Threads



Active: 8620 users

The Big Programming Thread - Page 674

Forum Index > General Forum
Post a Reply
Prev 1 672 673 674 675 676 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Manit0u
Profile Blog Joined August 2004
Poland17770 Posts
Last Edited: 2015-11-02 07:33:48
November 02 2015 07:30 GMT
#13461
On October 31 2015 18:10 supereddie wrote:
Show nested quote +
On October 31 2015 03:54 Manit0u wrote:
On October 29 2015 04:39 supereddie wrote:
Even if you round, the binary representation of fractions is still a problem. To avoid other problems, use a delta in comparisons.

double delta = 0.00001; // max deviation/fault tolerance
Math.Abs(0.3 - (0.1 + 0.2)) < delta


All cool and dandy, but what do you want to compare here?

You have 2 doubles and you want to see if the result of an operation performed on them is within delta. How do you determine what do you want to compare the result against?

It's nice when talking about 0.1, 0.2 and 0.3 for the sake of examples, but what if you don't know any of them beforehand?

The delta should be an application or business rule. The others can just be variables or something. Basically anywhere you do an equals comparison between floats/doubles you can replace it with this.

Useless example:

// Somewhere else
internal static readonly double FaultTolerance = 0.001;

private bool IsOneThird(double someNumber)
{
// any someNumer between 0.332 and 0.334 is counted as 1/3
return (Math.Abs(0.33 - someNumer) < Constants.FaultTolerance);
}


This still doesn't answer my question. Where did 0.33 come from in this example?

Let's say someNumber is 9268.27. How do you know which method to use to see if it's within fault tolerance?
Time is precious. Waste it wisely.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2015-11-02 08:11:07
November 02 2015 08:08 GMT
#13462
On November 02 2015 16:30 Manit0u wrote:
Show nested quote +
On October 31 2015 18:10 supereddie wrote:
On October 31 2015 03:54 Manit0u wrote:
On October 29 2015 04:39 supereddie wrote:
Even if you round, the binary representation of fractions is still a problem. To avoid other problems, use a delta in comparisons.

double delta = 0.00001; // max deviation/fault tolerance
Math.Abs(0.3 - (0.1 + 0.2)) < delta


All cool and dandy, but what do you want to compare here?

You have 2 doubles and you want to see if the result of an operation performed on them is within delta. How do you determine what do you want to compare the result against?

It's nice when talking about 0.1, 0.2 and 0.3 for the sake of examples, but what if you don't know any of them beforehand?

The delta should be an application or business rule. The others can just be variables or something. Basically anywhere you do an equals comparison between floats/doubles you can replace it with this.

Useless example:

// Somewhere else
internal static readonly double FaultTolerance = 0.001;

private bool IsOneThird(double someNumber)
{
// any someNumer between 0.332 and 0.334 is counted as 1/3
return (Math.Abs(0.33 - someNumer) < Constants.FaultTolerance);
}


This still doesn't answer my question. Where did 0.33 come from in this example?

Let's say someNumber is 9268.27. How do you know which method to use to see if it's within fault tolerance?


What are you asking?

All mathematic operations are within whatever IEEE spec that the language/compiler supports, that's where you get your guarantees about the tolerance of operations.

When you have floats/doubles you want to compare, you can only compare them up to the tolerance of that IEEE spec because multiple operations lose precision, but you already know that.

If you have a budget of like $100.00 (or whatever a user enters) and you need to check if you reached that budget and you used floats for some poor reason, you can have three items costing 10.0+10.0+80.0 that equals 100.00. But because you represented them in floats it's actually 100.0000001, and that's higher than your first 100 which was actually 100.0000000001, so your check fails when obviously it should be correct. So to fix that you don't go 10.0+10.0+80.0 < 100.00 but 100.00 - 10.0+10.0+80.0 < tolerance.
There is no one like you in the universe.
amazingxkcd
Profile Blog Joined September 2010
GRAND OLD AMERICA16375 Posts
November 02 2015 19:00 GMT
#13463
has anyone else seen this? this is super nifty

https://github.com/yuvaltz/Granular/wiki/TL;DR
The world is burning and you rather be on this terrible website discussing video games and your shallow feelings
Manit0u
Profile Blog Joined August 2004
Poland17770 Posts
November 02 2015 19:24 GMT
#13464
On November 02 2015 17:08 Blisse wrote:
Show nested quote +
On November 02 2015 16:30 Manit0u wrote:
On October 31 2015 18:10 supereddie wrote:
On October 31 2015 03:54 Manit0u wrote:
On October 29 2015 04:39 supereddie wrote:
Even if you round, the binary representation of fractions is still a problem. To avoid other problems, use a delta in comparisons.

double delta = 0.00001; // max deviation/fault tolerance
Math.Abs(0.3 - (0.1 + 0.2)) < delta


All cool and dandy, but what do you want to compare here?

You have 2 doubles and you want to see if the result of an operation performed on them is within delta. How do you determine what do you want to compare the result against?

It's nice when talking about 0.1, 0.2 and 0.3 for the sake of examples, but what if you don't know any of them beforehand?

The delta should be an application or business rule. The others can just be variables or something. Basically anywhere you do an equals comparison between floats/doubles you can replace it with this.

Useless example:

// Somewhere else
internal static readonly double FaultTolerance = 0.001;

private bool IsOneThird(double someNumber)
{
// any someNumer between 0.332 and 0.334 is counted as 1/3
return (Math.Abs(0.33 - someNumer) < Constants.FaultTolerance);
}


This still doesn't answer my question. Where did 0.33 come from in this example?

Let's say someNumber is 9268.27. How do you know which method to use to see if it's within fault tolerance?


What are you asking?

All mathematic operations are within whatever IEEE spec that the language/compiler supports, that's where you get your guarantees about the tolerance of operations.

When you have floats/doubles you want to compare, you can only compare them up to the tolerance of that IEEE spec because multiple operations lose precision, but you already know that.

If you have a budget of like $100.00 (or whatever a user enters) and you need to check if you reached that budget and you used floats for some poor reason, you can have three items costing 10.0+10.0+80.0 that equals 100.00. But because you represented them in floats it's actually 100.0000001, and that's higher than your first 100 which was actually 100.0000000001, so your check fails when obviously it should be correct. So to fix that you don't go 10.0+10.0+80.0 < 100.00 but 100.00 - 10.0+10.0+80.0 < tolerance.


I'm asking how do you know what to compare your value against?

Unless you set some pre-defined constants you really can't do it since you'd have to calculate it using floats which could also be erroneous. That's why you can't really use delta comparison in a system where you don't know how many or how large your input values will be and you don't have pre-set data to compare it. Unless I'm mistaken, but that's why I'm asking the question.
Time is precious. Waste it wisely.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
Last Edited: 2015-11-02 20:03:48
November 02 2015 20:01 GMT
#13465
On November 03 2015 04:00 amazingxkcd wrote:
has anyone else seen this? this is super nifty

https://github.com/yuvaltz/Granular/wiki/TL;DR

I'm not sure I fully understand the point of it. This allows you to develop web layouts without having to touch JS/CSS/HTML? You can just write it in, what, C#, and it compiles to a web suite version?

On November 03 2015 04:24 Manit0u wrote:
Show nested quote +
On November 02 2015 17:08 Blisse wrote:
On November 02 2015 16:30 Manit0u wrote:
On October 31 2015 18:10 supereddie wrote:
On October 31 2015 03:54 Manit0u wrote:
On October 29 2015 04:39 supereddie wrote:
Even if you round, the binary representation of fractions is still a problem. To avoid other problems, use a delta in comparisons.

double delta = 0.00001; // max deviation/fault tolerance
Math.Abs(0.3 - (0.1 + 0.2)) < delta


All cool and dandy, but what do you want to compare here?

You have 2 doubles and you want to see if the result of an operation performed on them is within delta. How do you determine what do you want to compare the result against?

It's nice when talking about 0.1, 0.2 and 0.3 for the sake of examples, but what if you don't know any of them beforehand?

The delta should be an application or business rule. The others can just be variables or something. Basically anywhere you do an equals comparison between floats/doubles you can replace it with this.

Useless example:

// Somewhere else
internal static readonly double FaultTolerance = 0.001;

private bool IsOneThird(double someNumber)
{
// any someNumer between 0.332 and 0.334 is counted as 1/3
return (Math.Abs(0.33 - someNumer) < Constants.FaultTolerance);
}


This still doesn't answer my question. Where did 0.33 come from in this example?

Let's say someNumber is 9268.27. How do you know which method to use to see if it's within fault tolerance?


What are you asking?

All mathematic operations are within whatever IEEE spec that the language/compiler supports, that's where you get your guarantees about the tolerance of operations.

When you have floats/doubles you want to compare, you can only compare them up to the tolerance of that IEEE spec because multiple operations lose precision, but you already know that.

If you have a budget of like $100.00 (or whatever a user enters) and you need to check if you reached that budget and you used floats for some poor reason, you can have three items costing 10.0+10.0+80.0 that equals 100.00. But because you represented them in floats it's actually 100.0000001, and that's higher than your first 100 which was actually 100.0000000001, so your check fails when obviously it should be correct. So to fix that you don't go 10.0+10.0+80.0 < 100.00 but 100.00 - 10.0+10.0+80.0 < tolerance.


I'm asking how do you know what to compare your value against?

Unless you set some pre-defined constants you really can't do it since you'd have to calculate it using floats which could also be erroneous. That's why you can't really use delta comparison in a system where you don't know how many or how large your input values will be and you don't have pre-set data to compare it. Unless I'm mistaken, but that's why I'm asking the question.


Right, which is why earlier he mentioned that you need to define the constants ahead of time for your delta. They may be business constants, etc. If you're using money, it could be 2 digits(i.e. 20.00 and 20.01 are different, but 20.00 and 20.0049 are the same, so your delta would be 0.005). If you don't know anything about your system, then you can't really use a delta effectively, but you can just make one up that sounds like it might work.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
November 02 2015 20:45 GMT
#13466
On November 03 2015 04:24 Manit0u wrote:
Show nested quote +
On November 02 2015 17:08 Blisse wrote:
On November 02 2015 16:30 Manit0u wrote:
On October 31 2015 18:10 supereddie wrote:
On October 31 2015 03:54 Manit0u wrote:
On October 29 2015 04:39 supereddie wrote:
Even if you round, the binary representation of fractions is still a problem. To avoid other problems, use a delta in comparisons.

double delta = 0.00001; // max deviation/fault tolerance
Math.Abs(0.3 - (0.1 + 0.2)) < delta


All cool and dandy, but what do you want to compare here?

You have 2 doubles and you want to see if the result of an operation performed on them is within delta. How do you determine what do you want to compare the result against?

It's nice when talking about 0.1, 0.2 and 0.3 for the sake of examples, but what if you don't know any of them beforehand?

The delta should be an application or business rule. The others can just be variables or something. Basically anywhere you do an equals comparison between floats/doubles you can replace it with this.

Useless example:

// Somewhere else
internal static readonly double FaultTolerance = 0.001;

private bool IsOneThird(double someNumber)
{
// any someNumer between 0.332 and 0.334 is counted as 1/3
return (Math.Abs(0.33 - someNumer) < Constants.FaultTolerance);
}


This still doesn't answer my question. Where did 0.33 come from in this example?

Let's say someNumber is 9268.27. How do you know which method to use to see if it's within fault tolerance?


What are you asking?

All mathematic operations are within whatever IEEE spec that the language/compiler supports, that's where you get your guarantees about the tolerance of operations.

When you have floats/doubles you want to compare, you can only compare them up to the tolerance of that IEEE spec because multiple operations lose precision, but you already know that.

If you have a budget of like $100.00 (or whatever a user enters) and you need to check if you reached that budget and you used floats for some poor reason, you can have three items costing 10.0+10.0+80.0 that equals 100.00. But because you represented them in floats it's actually 100.0000001, and that's higher than your first 100 which was actually 100.0000000001, so your check fails when obviously it should be correct. So to fix that you don't go 10.0+10.0+80.0 < 100.00 but 100.00 - 10.0+10.0+80.0 < tolerance.


I'm asking how do you know what to compare your value against?

Unless you set some pre-defined constants you really can't do it since you'd have to calculate it using floats which could also be erroneous. That's why you can't really use delta comparison in a system where you don't know how many or how large your input values will be and you don't have pre-set data to compare it. Unless I'm mistaken, but that's why I'm asking the question.


You have to have some sort of predetermined value. If you sum any amount of numbers and you wanted to verify an answer you have to know something beforehand whether you are working with ints or doubles. Typically you'd have some predetermined total that you'd want to compare against.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Kickstart
Profile Blog Joined May 2008
United States1941 Posts
November 02 2015 21:53 GMT
#13467
Not posted in this thread before but I'm doing some javascript and I'm new to it and I am failing hard. Feel like an idiot because I can't get it to work. I'm trying to do a few things with functions on a webpage. What I'm stuck on atm is that I am trying to create a function that will get the day's date. I am able to figure out how to get the date but when I try to make it a function it messes it up :/. I know I'm doing something stupid but I can't figure it out so yeah.

I have this which returns the date correctly:

var currentdate = new Date();
var dd = currentdate.getDate();
var mm = currentdate.getMonth()+1;
var yyyy = currentdate.getFullYear();

if(dd<10) {
dd='0'+dd
}

if(mm<10) {
mm='0'+mm
}

today = mm+'/'+dd+'/'+yyyy;

alert(today);


But the requirement for the project I'm doing says it needs to be in a function today(). Why I don't know because it would work without that but whatever. Right now I am trying this which doesn't work:

function today()
{
var currentdate = new Date();
var dd = currentdate.getDate();
var mm = currentdate.getMonth()+1;
var yyyy = currentdate.getFullYear();

if(dd<10) {
dd='0'+dd
}

if(mm<10) {
mm='0'+mm
}

return mm+'/'+dd+'/'+yyyy;
}

I've tried a bunch of other things as well but to no avail.

Any help would be appreciated, or even pointing me to a resource that will clear things up so I am less clueless.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2015-11-02 22:15:57
November 02 2015 22:07 GMT
#13468
On November 03 2015 04:24 Manit0u wrote:
Show nested quote +
On November 02 2015 17:08 Blisse wrote:
On November 02 2015 16:30 Manit0u wrote:
On October 31 2015 18:10 supereddie wrote:
On October 31 2015 03:54 Manit0u wrote:
On October 29 2015 04:39 supereddie wrote:
Even if you round, the binary representation of fractions is still a problem. To avoid other problems, use a delta in comparisons.

double delta = 0.00001; // max deviation/fault tolerance
Math.Abs(0.3 - (0.1 + 0.2)) < delta


All cool and dandy, but what do you want to compare here?

You have 2 doubles and you want to see if the result of an operation performed on them is within delta. How do you determine what do you want to compare the result against?

It's nice when talking about 0.1, 0.2 and 0.3 for the sake of examples, but what if you don't know any of them beforehand?

The delta should be an application or business rule. The others can just be variables or something. Basically anywhere you do an equals comparison between floats/doubles you can replace it with this.

Useless example:

// Somewhere else
internal static readonly double FaultTolerance = 0.001;

private bool IsOneThird(double someNumber)
{
// any someNumer between 0.332 and 0.334 is counted as 1/3
return (Math.Abs(0.33 - someNumer) < Constants.FaultTolerance);
}


This still doesn't answer my question. Where did 0.33 come from in this example?

Let's say someNumber is 9268.27. How do you know which method to use to see if it's within fault tolerance?


What are you asking?

All mathematic operations are within whatever IEEE spec that the language/compiler supports, that's where you get your guarantees about the tolerance of operations.

When you have floats/doubles you want to compare, you can only compare them up to the tolerance of that IEEE spec because multiple operations lose precision, but you already know that.

If you have a budget of like $100.00 (or whatever a user enters) and you need to check if you reached that budget and you used floats for some poor reason, you can have three items costing 10.0+10.0+80.0 that equals 100.00. But because you represented them in floats it's actually 100.0000001, and that's higher than your first 100 which was actually 100.0000000001, so your check fails when obviously it should be correct. So to fix that you don't go 10.0+10.0+80.0 < 100.00 but 100.00 - 10.0+10.0+80.0 < tolerance.


I'm asking how do you know what to compare your value against?

Unless you set some pre-defined constants you really can't do it since you'd have to calculate it using floats which could also be erroneous. That's why you can't really use delta comparison in a system where you don't know how many or how large your input values will be and you don't have pre-set data to compare it. Unless I'm mistaken, but that's why I'm asking the question.


floating point representation is not "erroneous". It's imprecise, which is not the same as "erroneous" or inaccurate. For your question, reference this wiki page: https://en.wikipedia.org/wiki/Machine_epsilon. Rounding modes are also important for understanding where the imprecision comes from, as different floating point implementations may round differently which is why floats come out slightly off from what you expect. see https://en.wikipedia.org/wiki/Floating_point#Rounding_modes.

For an example, many implementations of the C software floating point libraries first compare the bitfields for the exponent, then compare the base using the machine epsilon. This is a sufficient way to compare floats without needing to know before hand what their values might be.

Any sufficiently advanced technology is indistinguishable from magic
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2015-11-03 02:15:33
November 02 2015 22:16 GMT
#13469
On November 03 2015 04:24 Manit0u wrote:
Show nested quote +
On November 02 2015 17:08 Blisse wrote:
On November 02 2015 16:30 Manit0u wrote:
On October 31 2015 18:10 supereddie wrote:
On October 31 2015 03:54 Manit0u wrote:
On October 29 2015 04:39 supereddie wrote:
Even if you round, the binary representation of fractions is still a problem. To avoid other problems, use a delta in comparisons.

double delta = 0.00001; // max deviation/fault tolerance
Math.Abs(0.3 - (0.1 + 0.2)) < delta


All cool and dandy, but what do you want to compare here?

You have 2 doubles and you want to see if the result of an operation performed on them is within delta. How do you determine what do you want to compare the result against?

It's nice when talking about 0.1, 0.2 and 0.3 for the sake of examples, but what if you don't know any of them beforehand?

The delta should be an application or business rule. The others can just be variables or something. Basically anywhere you do an equals comparison between floats/doubles you can replace it with this.

Useless example:

// Somewhere else
internal static readonly double FaultTolerance = 0.001;

private bool IsOneThird(double someNumber)
{
// any someNumer between 0.332 and 0.334 is counted as 1/3
return (Math.Abs(0.33 - someNumer) < Constants.FaultTolerance);
}


This still doesn't answer my question. Where did 0.33 come from in this example?

Let's say someNumber is 9268.27. How do you know which method to use to see if it's within fault tolerance?


What are you asking?

All mathematic operations are within whatever IEEE spec that the language/compiler supports, that's where you get your guarantees about the tolerance of operations.

When you have floats/doubles you want to compare, you can only compare them up to the tolerance of that IEEE spec because multiple operations lose precision, but you already know that.

If you have a budget of like $100.00 (or whatever a user enters) and you need to check if you reached that budget and you used floats for some poor reason, you can have three items costing 10.0+10.0+80.0 that equals 100.00. But because you represented them in floats it's actually 100.0000001, and that's higher than your first 100 which was actually 100.0000000001, so your check fails when obviously it should be correct. So to fix that you don't go 10.0+10.0+80.0 < 100.00 but 100.00 - 10.0+10.0+80.0 < tolerance.


I'm asking how do you know what to compare your value against?

Unless you set some pre-defined constants you really can't do it since you'd have to calculate it using floats which could also be erroneous. That's why you can't really use delta comparison in a system where you don't know how many or how large your input values will be and you don't have pre-set data to compare it. Unless I'm mistaken, but that's why I'm asking the question.


No that should be wrong.

If you have a spreadsheet and you need to compare the sums of two columns of doubles/floats then you don't have pre-defined constants but you still need to use epsilon checks to compare the two.

The point is that if you ever need to compare two numbers represented as double/floats, you cannot do so directly because they're imprecise and operations accumulate errors, so you need to deal with the poor precision by doing an epsilon comparison.

I don't really understand how you can't think of an example where you need to compare two numbers that are double/floats so I'm still really lost.

---

If you're talking about how the errors in precision can become unclear/unbounded if you have a large number of double/float operations, your error is bounded by the IEEE implementation of the type and internal to the language - use another number representation if you need more precision.

http://stackoverflow.com/questions/747470/what-is-the-meaning-of-numeric-limitsdoubledigits10
There is no one like you in the universe.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
November 02 2015 22:39 GMT
#13470
--- Nuked ---
Kickstart
Profile Blog Joined May 2008
United States1941 Posts
November 02 2015 22:56 GMT
#13471
On November 03 2015 07:39 Nesserev wrote:
Show nested quote +
On November 03 2015 06:53 Kickstart wrote:
Not posted in this thread before but I'm doing some javascript and I'm new to it and I am failing hard. Feel like an idiot because I can't get it to work. I'm trying to do a few things with functions on a webpage. What I'm stuck on atm is that I am trying to create a function that will get the day's date. I am able to figure out how to get the date but when I try to make it a function it messes it up :/. I know I'm doing something stupid but I can't figure it out so yeah.

I have this which returns the date correctly:

var currentdate = new Date();
var dd = currentdate.getDate();
var mm = currentdate.getMonth()+1;
var yyyy = currentdate.getFullYear();

if(dd<10) {
dd='0'+dd
}

if(mm<10) {
mm='0'+mm
}

today = mm+'/'+dd+'/'+yyyy;

alert(today);


But the requirement for the project I'm doing says it needs to be in a function today(). Why I don't know because it would work without that but whatever. Right now I am trying this which doesn't work:

function today()
{
var currentdate = new Date();
var dd = currentdate.getDate();
var mm = currentdate.getMonth()+1;
var yyyy = currentdate.getFullYear();

if(dd<10) {
dd='0'+dd
}

if(mm<10) {
mm='0'+mm
}

return mm+'/'+dd+'/'+yyyy;
}

I've tried a bunch of other things as well but to no avail.

Any help would be appreciated, or even pointing me to a resource that will clear things up so I am less clueless.

I tried the second piece of code, and it seems to work like intended; it returns the string: "11/02/2015" (today's date in MURRICAN format)

For a small project, it probably won't hurt that you initialize global variables like that, but it's better to avoid them at all costs anyway. As projects get bigger, those variables will be accessible from anywhere else in your code, and thus any part of your code might introduce an error.

Also, you determine the date once, but are you sure that every subsequent time that today() is called, that the date is still the same. It's better to keep logical statements that belong together in the same function.


Yeah you are right, I am just retarded. Second piece is actually working correctly, I was just calling like "alert(today);" instead of "alert(today());" Woops.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
November 02 2015 23:27 GMT
#13472
On November 03 2015 05:01 WarSame wrote:
Show nested quote +
On November 03 2015 04:00 amazingxkcd wrote:
has anyone else seen this? this is super nifty

https://github.com/yuvaltz/Granular/wiki/TL;DR

I'm not sure I fully understand the point of it. This allows you to develop web layouts without having to touch JS/CSS/HTML? You can just write it in, what, C#, and it compiles to a web suite version?


I think the point is supposed to be that C# and XAML are a lot nicer interfaces for UI development than JS/CSS/HTML, which is probably true.
There is no one like you in the universe.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
Last Edited: 2015-11-02 23:57:45
November 02 2015 23:57 GMT
#13473
If that's the case then I'm fully behind it. My experience with the web suite is painful so far. I just wasn't sure if I was reading it right. It can be hard to understand some descriptions of products. There's a whole ton of lingo, other products' names, and unclear explanations.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Manit0u
Profile Blog Joined August 2004
Poland17770 Posts
November 03 2015 11:07 GMT
#13474
On November 03 2015 07:56 Kickstart wrote:
Show nested quote +
On November 03 2015 07:39 Nesserev wrote:
On November 03 2015 06:53 Kickstart wrote:
Not posted in this thread before but I'm doing some javascript and I'm new to it and I am failing hard. Feel like an idiot because I can't get it to work. I'm trying to do a few things with functions on a webpage. What I'm stuck on atm is that I am trying to create a function that will get the day's date. I am able to figure out how to get the date but when I try to make it a function it messes it up :/. I know I'm doing something stupid but I can't figure it out so yeah.

I have this which returns the date correctly:

var currentdate = new Date();
var dd = currentdate.getDate();
var mm = currentdate.getMonth()+1;
var yyyy = currentdate.getFullYear();

if(dd<10) {
dd='0'+dd
}

if(mm<10) {
mm='0'+mm
}

today = mm+'/'+dd+'/'+yyyy;

alert(today);


But the requirement for the project I'm doing says it needs to be in a function today(). Why I don't know because it would work without that but whatever. Right now I am trying this which doesn't work:

function today()
{
var currentdate = new Date();
var dd = currentdate.getDate();
var mm = currentdate.getMonth()+1;
var yyyy = currentdate.getFullYear();

if(dd<10) {
dd='0'+dd
}

if(mm<10) {
mm='0'+mm
}

return mm+'/'+dd+'/'+yyyy;
}

I've tried a bunch of other things as well but to no avail.

Any help would be appreciated, or even pointing me to a resource that will clear things up so I am less clueless.

I tried the second piece of code, and it seems to work like intended; it returns the string: "11/02/2015" (today's date in MURRICAN format)

For a small project, it probably won't hurt that you initialize global variables like that, but it's better to avoid them at all costs anyway. As projects get bigger, those variables will be accessible from anywhere else in your code, and thus any part of your code might introduce an error.

Also, you determine the date once, but are you sure that every subsequent time that today() is called, that the date is still the same. It's better to keep logical statements that belong together in the same function.


Yeah you are right, I am just retarded. Second piece is actually working correctly, I was just calling like "alert(today);" instead of "alert(today());" Woops.


Here's another way of doing it. That should show you the way


function printDate() {
var temp = new Date();
var dateStr = padStr(temp.getFullYear()) +
padStr(1 + temp.getMonth()) +
padStr(temp.getDate()) +
padStr(temp.getHours()) +
padStr(temp.getMinutes()) +
padStr(temp.getSeconds());
debug (dateStr );
}

function padStr(i) {
return (i < 10) ? "0" + i : "" + i;
}

Time is precious. Waste it wisely.
Prillan
Profile Joined August 2011
Sweden350 Posts
November 03 2015 14:24 GMT
#13475
On November 03 2015 07:16 Blisse wrote:
Show nested quote +
On November 03 2015 04:24 Manit0u wrote:
On November 02 2015 17:08 Blisse wrote:
On November 02 2015 16:30 Manit0u wrote:
On October 31 2015 18:10 supereddie wrote:
On October 31 2015 03:54 Manit0u wrote:
On October 29 2015 04:39 supereddie wrote:
Even if you round, the binary representation of fractions is still a problem. To avoid other problems, use a delta in comparisons.

double delta = 0.00001; // max deviation/fault tolerance
Math.Abs(0.3 - (0.1 + 0.2)) < delta


All cool and dandy, but what do you want to compare here?

You have 2 doubles and you want to see if the result of an operation performed on them is within delta. How do you determine what do you want to compare the result against?

It's nice when talking about 0.1, 0.2 and 0.3 for the sake of examples, but what if you don't know any of them beforehand?

The delta should be an application or business rule. The others can just be variables or something. Basically anywhere you do an equals comparison between floats/doubles you can replace it with this.

Useless example:

// Somewhere else
internal static readonly double FaultTolerance = 0.001;

private bool IsOneThird(double someNumber)
{
// any someNumer between 0.332 and 0.334 is counted as 1/3
return (Math.Abs(0.33 - someNumer) < Constants.FaultTolerance);
}


This still doesn't answer my question. Where did 0.33 come from in this example?

Let's say someNumber is 9268.27. How do you know which method to use to see if it's within fault tolerance?


What are you asking?

All mathematic operations are within whatever IEEE spec that the language/compiler supports, that's where you get your guarantees about the tolerance of operations.

When you have floats/doubles you want to compare, you can only compare them up to the tolerance of that IEEE spec because multiple operations lose precision, but you already know that.

If you have a budget of like $100.00 (or whatever a user enters) and you need to check if you reached that budget and you used floats for some poor reason, you can have three items costing 10.0+10.0+80.0 that equals 100.00. But because you represented them in floats it's actually 100.0000001, and that's higher than your first 100 which was actually 100.0000000001, so your check fails when obviously it should be correct. So to fix that you don't go 10.0+10.0+80.0 < 100.00 but 100.00 - 10.0+10.0+80.0 < tolerance.


I'm asking how do you know what to compare your value against?

Unless you set some pre-defined constants you really can't do it since you'd have to calculate it using floats which could also be erroneous. That's why you can't really use delta comparison in a system where you don't know how many or how large your input values will be and you don't have pre-set data to compare it. Unless I'm mistaken, but that's why I'm asking the question.


No that should be wrong.

If you have a spreadsheet and you need to compare the sums of two columns of doubles/floats then you don't have pre-defined constants but you still need to use epsilon checks to compare the two.

The point is that if you ever need to compare two numbers represented as double/floats, you cannot do so directly because they're imprecise and operations accumulate errors, so you need to deal with the poor precision by doing an epsilon comparison.

I don't really understand how you can't think of an example where you need to compare two numbers that are double/floats so I'm still really lost.

---

If you're talking about how the errors in precision can become unclear/unbounded if you have a large number of double/float operations, your error is bounded by the IEEE implementation of the type and internal to the language - use another number representation if you need more precision.

http://stackoverflow.com/questions/747470/what-is-the-meaning-of-numeric-limitsdoubledigits10

I'm confused, aren't you two actually saying the same thing? He's pointing out that you can't compare floating point numbers without first setting a tolerance. Which is exactly what you are saying, right?
TheBB's sidekick, aligulac.com | "Reality is frequently inaccurate." - Douglas Adams
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2015-11-03 18:26:17
November 03 2015 18:19 GMT
#13476
To me, it sounded like he was saying that during A - B < e, that you have to have a pre-defined/constant A or B otherwise the comparison doesn't, which doesn't make sense to me.

I'm asking how do you know what to compare your value against?


Specifically this...


---

OH are you (manitou) asking how do you determine the tolerance?

The fault tolerance is just a number you decide to choose depending on how much precision you want to be able to guarantee with each operation - you choose it yourself based on the numeric type and your system requirements.

---

Also I was watching X-Files on Netflix and they mentioned Manitou and I was like oh damn that's where your name comes from....
There is no one like you in the universe.
Manit0u
Profile Blog Joined August 2004
Poland17770 Posts
Last Edited: 2015-11-03 19:54:06
November 03 2015 19:52 GMT
#13477
On November 04 2015 03:19 Blisse wrote:
To me, it sounded like he was saying that during A - B < e, that you have to have a pre-defined/constant A or B otherwise the comparison doesn't, which doesn't make sense to me.

Show nested quote +
I'm asking how do you know what to compare your value against?


Specifically this...


---

OH are you (manitou) asking how do you determine the tolerance?

The fault tolerance is just a number you decide to choose depending on how much precision you want to be able to guarantee with each operation - you choose it yourself based on the numeric type and your system requirements.

---

Also I was watching X-Files on Netflix and they mentioned Manitou and I was like oh damn that's where your name comes from....


Haha. Well, I didn't ask about the tolerance (that's obviously a const). I was asking about A +/- B where if you have to calculate both A and B you can get the same imprecision in both of them, as opposed to A (or B) also being a pre-set value.


// CASE 1
const double tolerance = 0.001;
const double n = 0.03;

boolean all_is_fine(double x, double y) {
return n - (x + y) <= tolerance;
}

// CASE 2
const double tolerance = 0.001;

boolean all_is_fine(double a, double b, double c, double d) {
return (a + b) - (c + d) <= tolerance;
}


I was asking about case 1 vs case 2 specifically, since in all examples posted previously there was only case 1 presented. What if you have to do it case 2 way? Won't the imprecision skew both additions thus making tolerance check moot?

Might be dumb question but it intrigued me (at my company we try to avoid floats like a plague so I don't have much experience with them).
Time is precious. Waste it wisely.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
November 03 2015 19:59 GMT
#13478
I believe in that case you may want to double the tolerance. Potentially you could have 0.00001 extra from an addition or whatever. If you have 2 then you can get 0.00002 extra, so just double the tolerance to make up for that. It's kinda like uncertainty in physics. If you multiply them, then you square the tolerance(which makes it smaller), if you divide I think maybe you square root the tolerance?
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2015-11-03 20:18:42
November 03 2015 20:17 GMT
#13479
--- Nuked ---
Ropid
Profile Joined March 2009
Germany3557 Posts
Last Edited: 2015-11-03 22:12:55
November 03 2015 22:11 GMT
#13480
This guy here blogged a lot about floating point numbers: https://randomascii.wordpress.com/

Here's his article about comparisons: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

Well, I didn't ask about the tolerance (that's obviously a const).


That's actually a thing that's weird about floating point. The precision of the numbers is not a constant. It's changing with the size of the values as there's the exponent part of the floating point number that moves the point around. In C, the "float.h" header file has a definition for that "epsilon" that's telling you the precision of float and double from 1.0 to 2.0. If you move away from that range, the precision changes.

What's going on there is, the main bits of the data structure are used for fractions like this:

1 + (1/2) + (1/4) + (1/8) + (1/16) + (1/32) + ...

Those bits build values between 1.0 and <2.0. Then there's a second, smaller set of bits that moves the point around to get to smaller and larger ranges of numbers (a binary point, not decimal point).

Here's something fun about Patriot missiles being more imprecise the longer the computers were running:

http://www.gao.gov/products/IMTEC-92-26

There's something about 24-bit precision of their computers in the PDF. That would fit with 32-bit floats. It seems they used time in perhaps seconds since the machine was started for their calculations. The precision for comparing two time values then went to shit after several days when the numbers got large.
"My goal is to replace my soul with coffee and become immortal."
Prev 1 672 673 674 675 676 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 2h 8m
[ Submit Event ]
Live Streams
Refresh
StarCraft: Brood War
Mini 3277
PianO 1093
Hyuk 595
Killer 270
Larva 244
ToSsGirL 102
actioN 90
Leta 81
NotJumperer 38
HiyA 20
[ Show more ]
Sacsri 17
ajuk12(nOOB) 15
Sharp 15
Shine 5
League of Legends
JimRising 577
Counter-Strike
summit1g9029
Stewie2K929
Other Games
KnowMe170
RuFF_SC234
Trikslyr20
Organizations
Dota 2
PGL Dota 2 - Secondary Stream5538
Other Games
gamesdonequick786
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 11 non-featured ]
StarCraft 2
• Sammyuel 11
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Upcoming Events
WardiTV Spring Champion…
2h 8m
GSL
3h 8m
Maru vs ShoWTimE
Classic vs Reynor
herO vs Lambo
Solar vs Clem
IPSL
7h 8m
Bonyth vs Dewalt
BSL22 NKC (BSL vs China)
10h 8m
XuanXuan vs Jaystar
Mihu vs Messiah
eOnzErG vs Dewalt
Bonyth vs Jaystar
TerrOr vs Messiah
XuanXuan vs Mihu
eOnzErG vs Jaystar
Replay Cast
15h 8m
WardiTV Spring Champion…
1d 2h
GSL
1d 3h
IPSL
1d 7h
Hawk vs Julia
Patches Events
1d 8h
BSL22 NKC (BSL vs China)
1d 10h
Dewalt vs Messiah
Bonyth vs Mihu
TerrOr vs XuanXuan
eOnzErG vs Messiah
Jaystar vs Mihu
Dewalt vs XuanXuan
Bonyth vs TerrOr
[ Show More ]
Replay Cast
1d 15h
WardiTV Weekly
2 days
Monday Night Weeklies
2 days
Sparkling Tuna Cup
3 days
The PondCast
4 days
Douyu Cup 2020
4 days
Oliveira vs Trap
Jieshi vs XY
soO vs FanTaSy
TY vs Coffee
Douyu Cup 2020
5 days
Neeb vs Impact
MacSed vs Cyan
Scarlett vs Kelazhur
INnoVation vs Dear
Douyu Cup 2020
6 days
Liquipedia Results

Completed

KCM Race Survival 2026 Season 2
uThermal 2v2 2026 Main Event
Heroes Pulsing #2

Ongoing

IPSL Spring 2026
Acropolis #4
CSCL: Masked Kings S4
YSL S3
BSL 22 Non-Korean Championship
CSL Season 21: Qualifier 1
SCTL 2026 Spring
Maestros of the Game 2
WardiTV Spring 2026
Murky Cup 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026

Upcoming

CSL Season 21: Qualifier 2
CSL 2026 Summer (S21)
CSLAN 4
Blizzard Classic Cup 2026
Kung Fu Cup 2026 Grand Finals
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
HSC XXIX
Douyu Cup 2026
BCC 2026
Light HT
Heroes Pulsing #3
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.